From b22c9838b9232d8ecdf0efb685b746146e3ff382 Mon Sep 17 00:00:00 2001 From: dece Date: Sat, 3 Dec 2022 18:06:05 +0100 Subject: [PATCH] server: implement type definition --- italianswirls/server.py | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/italianswirls/server.py b/italianswirls/server.py index bf6b43b..f1d82c5 100644 --- a/italianswirls/server.py +++ b/italianswirls/server.py @@ -3,13 +3,13 @@ from typing import Optional from jedi import Script from jedi.api.classes import Name -from pygls.lsp.methods import COMPLETION, DEFINITION, HOVER +from pygls.lsp.methods import COMPLETION, DEFINITION, HOVER, TYPE_DEFINITION from pygls.lsp.types import (CompletionItem, CompletionItemKind, CompletionList, CompletionOptions, CompletionParams, DefinitionParams, Hover, HoverParams, InsertTextFormat, Location, Position, Range, - TextDocumentPositionParams) + TextDocumentPositionParams, TypeDefinitionParams) from pygls.server import LanguageServer from pygls.workspace import Document @@ -141,6 +141,18 @@ async def do_definition( return get_lsp_locations(jedi_names) or None +@LS.feature(TYPE_DEFINITION) +async def do_type_definition( + server: LanguageServer, + params: TypeDefinitionParams, +) -> Optional[list[Location]]: + """Return the type definition location(s) of the target symbol.""" + script = get_jedi_script_from_params(params, server) + jedi_position = get_jedi_position(params.position) + jedi_names = script.infer(*jedi_position) + return get_lsp_locations(jedi_names) or None + + @LS.feature(HOVER) async def do_hover( server: LanguageServer,