Skip to content

Commit

Permalink
Display tsserver tags from docstrings in GetDoc and extra_menu_info
Browse files Browse the repository at this point in the history
  • Loading branch information
bstaletic committed Oct 14, 2023
1 parent adce5d8 commit 38dac2b
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
28 changes: 28 additions & 0 deletions ycmd/completers/typescript/typescript_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 )


Expand Down Expand Up @@ -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
Expand Down
31 changes: 31 additions & 0 deletions ycmd/tests/typescript/get_completions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'
} ) )
} )
}
} )
23 changes: 23 additions & 0 deletions ycmd/tests/typescript/subcommands_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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, {
Expand Down

0 comments on commit 38dac2b

Please sign in to comment.