Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Display tsserver tags from docstrings in GetDoc and extra_menu_info #1716

Merged
merged 1 commit into from
Dec 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ycmd/completers/typescript/typescript_completer.py
Original file line number Diff line number Diff line change
Expand Up @@ -911,7 +911,12 @@ def _GetDoc( self, request_data ):
'offset': request_data[ 'column_codepoint' ]
} )

extra_info = _AggregateTagsFromDocstring( 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 @@ -1117,6 +1122,16 @@ def _LogLevel():
return 'verbose' if LOGGER.isEnabledFor( logging.DEBUG ) else 'normal'


def _AggregateTagsFromDocstring( info ):
extra_info = []
for tag in info.get( 'tags', [] ):
tag_name = tag[ 'name' ]
tag_text = tag.get( 'text' )
formated_tag = tag_name + ( f': { tag_text }' if tag_text else '' )
extra_info.append( formated_tag )
return '\n'.join( extra_info )


def _BuildCompletionExtraMenuAndDetailedInfo( request_data, entry ):
signature = _DisplayPartsToString( entry[ 'displayParts' ] )
if entry[ 'name' ] == signature:
Expand All @@ -1130,6 +1145,11 @@ def _BuildCompletionExtraMenuAndDetailedInfo( request_data, entry ):

docs = entry.get( 'documentation', [] )
detailed_info += [ doc[ 'text' ].strip() for doc in docs if doc ]

extra_info = _AggregateTagsFromDocstring( entry )
if extra_info:
detailed_info.append( extra_info )

detailed_info = '\n\n'.join( detailed_info )

return extra_menu_info, detailed_info
Expand Down
6 changes: 5 additions & 1 deletion ycmd/tests/javascriptreact/get_completions_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,11 @@ def test_GetCompletions_JavaScriptReact_DefaultTriggers( self, app ):
'detailed_info': '(property) Document.alinkColor: string\n'
'\n'
'Sets or gets the color of all active links '
'in the document.',
'in the document.\n'
'\n'
'deprecated: [MDN Reference]'
'(https://developer.mozilla.org/docs/Web/'
'API/Document/alinkColor)',
'kind': 'property',
} ) )
} )
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'
'param: 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'
'param: a - The argument\n'
'returns: - The hashed input'
} )
}
} )


@SharedYcmd
def test_Subcommands_GoToReferences( self, app ):
RunTest( app, {
Expand Down