def GetDoc(self, request_data): try: # Just pull `value` out of the textDocument/hover response return responses.BuildDetailedInfoResponse( self.GetHoverResponse(request_data)['value']) except language_server_completer.NoHoverInfoException: raise RuntimeError('No documentation available.')
def _BuildGetDocResponse(doc_data): """Builds a "DetailedInfoResponse" for a GetDoc request. doc_data is a DocumentationData object returned from the ClangCompleter""" # Parse the XML, as this is the only way to get the declaration text out of # libclang. It seems quite wasteful, but while the contents of the XML # provide fully parsed doxygen documentation tree, we actually don't want to # ever lose any information from the comment, so we just want display # the stripped comment. Arguably we could skip all of this XML generation and # parsing, but having the raw declaration text is likely one of the most # useful pieces of documentation available to the developer. Perhaps in # future, we can use this XML for more interesting things. try: root = xml.etree.ElementTree.fromstring(doc_data.comment_xml) except: raise ValueError(NO_DOCUMENTATION_MESSAGE) # Note: declaration is False-y if it has no child elements, hence the below # (wordy) if not declaration is None declaration = root.find("Declaration") return responses.BuildDetailedInfoResponse( '{0}\n{1}\nType: {2}\nName: {3}\n---\n{4}'.format( declaration.text if declaration is not None else "", doc_data.brief_comment, doc_data.canonical_type, doc_data.display_name, _FormatRawComment(doc_data.raw_comment)))
def _GetHover( self, request_data ): raw_hover = self.GetHoverResponse( request_data ) if isinstance( raw_hover, dict ): # Both MarkedString and MarkupContent contain 'value' key. # MarkupContent is the only one not deprecated. return responses.BuildDetailedInfoResponse( raw_hover[ 'value' ] ) if isinstance( raw_hover, str ): # MarkedString might be just a string. return responses.BuildDetailedInfoResponse( raw_hover ) # If we got this far, this is a list of MarkedString objects. lines = [] for marked_string in raw_hover: if isinstance( marked_string, str ): lines.append( marked_string ) else: lines.append( marked_string[ 'value' ] ) return responses.BuildDetailedInfoResponse( '\n'.join( lines ) )
def _GetDoc( self, request_data ): with self._jedi_lock: definitions = self._GetJediScript( request_data ).goto_definitions() documentation = [ definition.docstring() for definition in definitions ] documentation = '\n---\n'.join( documentation ) if documentation: return responses.BuildDetailedInfoResponse( documentation ) raise RuntimeError( 'No documentation available.' )
def GetDoc( self, request_data ): assert self._settings[ 'ls' ][ 'hoverKind' ] == 'Structured' try: result = json.loads( self.GetHoverResponse( request_data )[ 'value' ] ) docs = result[ 'signature' ] + '\n' + result[ 'fullDocumentation' ] return responses.BuildDetailedInfoResponse( docs.strip() ) except language_server_completer.NoHoverInfoException: raise RuntimeError( 'No documentation available.' )
def _GetDoc(self, request_data): try: definition = self._GetResponse('/find_definition', request_data) docs = [definition['context'], definition['docs']] return responses.BuildDetailedInfoResponse('\n---\n'.join(docs)) except Exception as e: _logger.exception(e) raise RuntimeError('Can\'t lookup docs.')
def _GetDoc( self, request_data ): self._Reload( request_data ) info = self._SendRequest( 'quickinfo', { 'file': request_data[ 'filepath' ], 'line': request_data[ 'line_num' ], 'offset': request_data[ 'column_codepoint' ] } ) message = f'{ info[ "displayString" ] }\n\n{info[ "documentation" ]}' return responses.BuildDetailedInfoResponse( message )
def _GetDoc( self, request_data ): request = self._DefaultParameters( request_data ) request[ "IncludeDocumentation" ] = True result = self._GetResponse( '/typelookup', request ) message = result[ "Type" ] if ( result[ "Documentation" ] ): message += "\n" + result[ "Documentation" ] return responses.BuildDetailedInfoResponse( message )
def _GetDoc( self, request_data ): self._Reload( request_data ) info = self._SendRequest( 'quickinfo', { 'file': request_data[ 'filepath' ], 'line': request_data[ 'line_num' ], 'offset': request_data[ 'column_codepoint' ] } ) message = '{0}\n\n{1}'.format( info[ 'displayString' ], info[ 'documentation' ] ) return responses.BuildDetailedInfoResponse( message )
def GetDoc( self, request_data ): try: hover_response = self.GetHoverResponse( request_data ) except language_server_completer.NoHoverInfoException: raise RuntimeError( 'No documentation available.' ) # Strips all empty lines and lines starting with "```" to make the hover # response look like plain text. For the format, see the comment in GetType. lines = hover_response[ 'value' ].split( '\n' ) documentation = '\n'.join( line for line in lines if line and not line.startswith( '```' ) ).strip() return responses.BuildDetailedInfoResponse( documentation )
def _GetDoc( self, request_data ): with self._jedi_lock: line = request_data[ 'line_num' ] # Jedi expects columns to start at 0, not 1, and for them to be Unicode # codepoint offsets. column = request_data[ 'start_codepoint' ] - 1 definitions = self._GetJediScript( request_data ).goto( line, column ) documentation = [ definition.docstring() for definition in definitions ] documentation = '\n---\n'.join( documentation ) if documentation: return responses.BuildDetailedInfoResponse( documentation ) raise RuntimeError( 'No documentation available.' )
def _GetDoc(self, request_data, args): query = self._GetQueryWord(request_data) if query in self._raw_names: type = self._raw_names[query] ret = subprocess.run( ['cmake', '--help-{}'.format(type), query], capture_output=True) if ret.returncode == 0: msg = ret.stdout.decode() return responses.BuildDetailedInfoResponse(str(request_data)) msg = "Can't find doc for {}".format(query) return responses.BuildDisplayMessageResponse(msg)
def _GetDoc(self, request_data): self._UpdateCurrentBuffer(request_data) col = request_data['column_num'] - 1 keyword = '' for it in re.finditer(r'\b[\w\.]+\b', request_data['line_value']): if it.start() <= col and it.end() > col: keyword = it.group(0) break doc = self.daemon.query(keyword) if doc: return responses.BuildDetailedInfoResponse(doc) else: raise ValueError('No documentation available')
def _GetDoc(self, request_data): request = self._DefaultParameters(request_data) request["IncludeDocumentation"] = True result = self._GetResponse('/typelookup', request) message = result.get('Type') or '' if (result["Documentation"]): message += "\n" + result["Documentation"] if not message: raise RuntimeError('No documentation available.') return responses.BuildDetailedInfoResponse(message.strip())
def _GetDoc(self, request_data): # Note: we use the 'type' request because this is the best # way to get the name, type and doc string. The 'documentation' request # doesn't return the 'name' (strangely), wheras the 'type' request returns # the same docs with extra info. query = {'type': 'type', 'docFormat': 'full', 'types': True} response = self._GetResponse(query, request_data) doc_string = 'Name: {name}\nType: {type}\n\n{doc}'.format( name=response.get('name', 'Unknown'), type=response.get('type', 'Unknown'), doc=response.get('doc', 'No documentation available')) return responses.BuildDetailedInfoResponse(doc_string)
def GetDoc(self, request_data): hover_response = self.GetHoverResponse(request_data) # RLS returns a list that may contain the following elements: # - a documentation string; # - a documentation url; # - [{language:rust, value:<type info>}]. documentation = '\n'.join( [item.strip() for item in hover_response if isinstance(item, str)]) if not documentation: raise RuntimeError( 'No documentation available for current context.') return responses.BuildDetailedInfoResponse(documentation)
def GetDoc(self, request_data): hover_response = self.GetHoverResponse(request_data) # The LSP defines the hover response as either: # - a string # - a list of strings # - an object with keys language, value # - a list of objects with keys language, value # - an object with keys kind, value # That's right. All of the above. documentation = hover_response.rstrip() if not documentation: raise RuntimeError(NO_DOCUMENTATION_MESSAGE) return responses.BuildDetailedInfoResponse(documentation)
def GetDoc(self, request_data): hover_response = self.GetHoverResponse(request_data) # The LSP defines the hover response as either: # - a string # - a list of strings # - an object with keys language, value # - a list of objects with keys language, value # - an object with keys kind, value # That's right. All of the above. # However it would appear that jdt.ls only ever returns useful data when it # is a list of objects-with-keys-language-value, so we only handle that case # and throw any other time. # Strictly we seem to receive: # - "" # when there really is no documentation or type info available # - {language:java, value:<type info>} # when there only the type information is available # - [{language:java, value:<type info>}, # 'doc line 1', # 'doc line 2', # ...] # when there is type and documentation information available. documentation = '' if isinstance(hover_response, list): for item in hover_response: if isinstance(item, str): documentation += item + '\n' documentation = documentation.rstrip() if not documentation: raise RuntimeError(NO_DOCUMENTATION_MESSAGE) return responses.BuildDetailedInfoResponse(documentation)
def _BuildDetailedInfoResponse(self, definition_list): docs = [definition['docstring'] for definition in definition_list] return responses.BuildDetailedInfoResponse('\n---\n'.join(docs))