diff --git a/ycmd/completers/typescript/typescript_completer.py b/ycmd/completers/typescript/typescript_completer.py index 99439421da..ab3d37dca5 100644 --- a/ycmd/completers/typescript/typescript_completer.py +++ b/ycmd/completers/typescript/typescript_completer.py @@ -911,7 +911,21 @@ def _GetDoc( self, request_data ): 'offset': request_data[ 'column_codepoint' ] } ) + extra_info = [] + for tag in info.get( 'tags', [] ): + tag_name = tag[ 'name' ] + tag_text = tag.get( 'text' ) + if tag_name == 'param' and tag_text: + extra_info.append( tag_text ) + elif tag_name == 'returns' and tag_text: + extra_info.append( 'returns ' + tag_text ) + + extra_info = '\n'.join( extra_info ) + message = f'{ info[ "displayString" ] }\n\n{ info[ "documentation" ] }' + if extra_info: + message += f'\n\n{ extra_info }' + return responses.BuildDetailedInfoResponse( message ) @@ -1130,6 +1144,20 @@ def _BuildCompletionExtraMenuAndDetailedInfo( request_data, entry ): docs = entry.get( 'documentation', [] ) detailed_info += [ doc[ 'text' ].strip() for doc in docs if doc ] + + extra_info = [] + for tag in entry.get( 'tags', [] ): + tag_name = tag[ 'name' ] + tag_text = tag.get( 'text' ) + if tag_name == 'param' and tag_text: + extra_info.append( tag_text ) + elif tag_name == 'returns': + extra_info.append( 'returns ' + tag_text ) + + extra_info = '\n'.join( extra_info ) + if extra_info: + detailed_info.append( extra_info ) + detailed_info = '\n\n'.join( detailed_info ) return extra_menu_info, detailed_info diff --git a/ycmd/tests/typescript/get_completions_test.py b/ycmd/tests/typescript/get_completions_test.py index 8a8f961ad7..c69033cd60 100644 --- a/ycmd/tests/typescript/get_completions_test.py +++ b/ycmd/tests/typescript/get_completions_test.py @@ -357,3 +357,34 @@ def test_GetCompletions_TypeScriptReact_DefaultTriggers( self, app ): } ) } } ) + + + @SharedYcmd + def test_GetCompletions_WithTags( self, app ): + filepath = PathToTestFile( 'signatures.ts' ) + RunTest( app, { + 'description': 'No need to force after a semantic trigger', + 'request': { + 'line_num': 101, + 'column_num': 24, + 'filepath': filepath, + 'filetype': 'typescript' + }, + 'expect': { + 'response': requests.codes.ok, + 'data': has_entries( { + 'completions': has_item( has_entries( { + 'insertion_text': 'single_argument_with_doc', + 'extra_data': {}, + 'extra_menu_info': + 'function single_argument_with_doc(a: string): string', + 'detailed_info': + 'function single_argument_with_doc(a: string): string\n\n' + 'A function with a single argument\n\n' + 'a - The argument\n' + 'returns - The hashed input', + 'kind': 'function' + } ) ) + } ) + } + } ) diff --git a/ycmd/tests/typescript/subcommands_test.py b/ycmd/tests/typescript/subcommands_test.py index e64acb2546..888fe823f3 100644 --- a/ycmd/tests/typescript/subcommands_test.py +++ b/ycmd/tests/typescript/subcommands_test.py @@ -610,6 +610,29 @@ def test_Subcommands_GetDoc_Class_Unicode( self, app ): } ) + @SharedYcmd + def test_Subcommands_GetDoc_FreeFunction_WithTags( self, app ): + RunTest( app, { + 'description': 'GetDoc shows documentation of param and returns tags', + 'request': { + 'command': 'GetDoc', + 'line_num': 101, + 'column_num': 12, + 'filepath': PathToTestFile( 'signatures.ts' ), + }, + 'expect': { + 'response': requests.codes.ok, + 'data': has_entries( { + 'detailed_info': + 'function single_argument_with_doc(a: string): string\n\n' + 'A function with a single argument\n\n' + 'a - The argument\n' + 'returns - The hashed input' + } ) + } + } ) + + @SharedYcmd def test_Subcommands_GoToReferences( self, app ): RunTest( app, {