Esempio n. 1
0
        def f(params: HoverParams) -> Optional[Hover]:
            range = Range(
                start=Position(line=0, character=0),
                end=Position(line=1, character=1),
            )

            return {
                'file://return.marked_string':
                Hover(
                    range=range,
                    contents=MarkedString(
                        language='language',
                        value='value',
                    ),
                ),
                'file://return.marked_string_list':
                Hover(
                    range=range,
                    contents=[
                        MarkedString(
                            language='language',
                            value='value',
                        ), 'str type'
                    ],
                ),
                'file://return.markup_content':
                Hover(
                    range=range,
                    contents=MarkupContent(kind=MarkupKind.Markdown,
                                           value='value'),
                ),
            }.get(params.text_document.uri, None)
Esempio n. 2
0
def hover(
    server: JediLanguageServer, params: TextDocumentPositionParams
) -> Optional[Hover]:
    """Support Hover."""
    document = server.workspace.get_document(params.text_document.uri)
    jedi_script = jedi_utils.script(server.project, document)
    jedi_lines = jedi_utils.line_column(params.position)
    markup_kind = _choose_markup(server)
    # jedi's help function is buggy when the column is 0. For this reason, as a
    # rote fix, we simply set the column to 1 if params.position returns column
    # 0.
    hover_text = jedi_utils.hover_text(
        jedi_script.help(
            line=jedi_lines[0],
            column=1 if jedi_lines[1] == 0 else jedi_lines[1],
        ),
        markup_kind,
        server.initialization_options,
    )
    if not hover_text:
        return None
    contents = MarkupContent(kind=markup_kind, value=hover_text)
    document = server.workspace.get_document(params.text_document.uri)
    _range = pygls_utils.current_word_range(document, params.position)
    return Hover(contents=contents, range=_range)
Esempio n. 3
0
 def get_documentation(self, xml_document: XmlDocument,
                       position: Position) -> Optional[Hover]:
     """Gets the documentation about the element at the given position."""
     context = self.xml_context_service.get_xml_context(
         xml_document, position)
     if context.node:
         if context.is_tag or context.is_attribute_key:
             documentation = self.xsd_service.get_documentation_for(context)
             context_range = self.xml_context_service.get_range_for_context(
                 xml_document, context)
             return Hover(contents=documentation, range=context_range)
         # Try to get token
         word = xml_document.document.word_at_position(position)
         token = self.definitions_provider.get_token_definition(
             xml_document, word)
         if token:
             return Hover(
                 contents=MarkupContent(kind=MarkupKind.Markdown,
                                        value=token.value),
                 range=Range(start=position, end=position),
             )
     return None
Esempio n. 4
0
def hover(server: JediLanguageServer,
          params: TextDocumentPositionParams) -> Optional[Hover]:
    """Support Hover."""
    document = server.workspace.get_document(params.text_document.uri)
    jedi_script = jedi_utils.script(server.project, document)
    jedi_lines = jedi_utils.line_column(jedi_script, params.position)
    markup_kind = _choose_markup(server)
    hover_text = jedi_utils.hover_text(jedi_script.help(**jedi_lines),
                                       markup_kind)
    if not hover_text:
        return None
    contents = MarkupContent(kind=markup_kind, value=hover_text)
    document = server.workspace.get_document(params.text_document.uri)
    _range = pygls_utils.current_word_range(document, params.position)
    return Hover(contents=contents, range=_range)
Esempio n. 5
0
def hover(server: JediLanguageServer,
          params: TextDocumentPositionParams) -> Optional[Hover]:
    """Support Hover."""
    document = server.workspace.get_document(params.text_document.uri)
    jedi_script = jedi_utils.script(server.project, document)
    jedi_lines = jedi_utils.line_column(jedi_script, params.position)
    markup_kind = _choose_markup(server)
    for name in jedi_script.help(**jedi_lines):
        docstring = name.docstring()
        if not docstring:
            continue
        docstring_clean = jedi_utils.convert_docstring(docstring, markup_kind)
        contents = MarkupContent(kind=markup_kind, value=docstring_clean)
        document = server.workspace.get_document(params.text_document.uri)
        _range = pygls_utils.current_word_range(document, params.position)
        return Hover(contents=contents, range=_range)
    return None
Esempio n. 6
0
    def on_hover(ls: RstLanguageServer, params: HoverParams):
        uri = params.text_document.uri
        doc = ls.workspace.get_document(uri)
        pos = params.position
        line = ls.line_at_position(doc, pos)
        location = ls.get_location_type(doc, pos)

        hover_values = []
        for feature in ls._features.values():
            for pattern in feature.hover_triggers:
                for match in pattern.finditer(line):
                    if not match:
                        continue

                    # only trigger hover if the position of the request is within
                    # the match
                    start, stop = match.span()
                    if start <= pos.character <= stop:
                        context = HoverContext(
                            doc=doc,
                            location=location,
                            match=match,
                            position=pos,
                            capabilities=ls.client_capabilities,
                        )
                        ls.logger.debug("Hover context: %s", context)

                        hover_value = feature.hover(context)
                        hover_values.append(hover_value)

        hover_content_values = "\n".join(hover_values)

        return Hover(contents=MarkupContent(
            kind=MarkupKind.Markdown,
            value=hover_content_values,
        ))