File tree Expand file tree Collapse file tree 4 files changed +55
-1
lines changed Expand file tree Collapse file tree 4 files changed +55
-1
lines changed Original file line number Diff line number Diff line change @@ -456,6 +456,7 @@ jedi-language-server aims to support Jedi's capabilities and expose them through
456
456
- [ completionItem/resolve] ( https://microsoft.github.io/language-server-protocol/specification#completionItem_resolve )
457
457
- [ textDocument/codeAction] ( https://microsoft.github.io/language-server-protocol/specification#textDocument_codeAction ) (refactor.inline, refactor.extract)
458
458
- [ textDocument/completion] ( https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_completion )
459
+ - [ textDocument/declaration] ( https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_declaration )
459
460
- [ textDocument/definition] ( https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_definition )
460
461
- [ textDocument/documentHighlight] ( https://microsoft.github.io/language-server-protocol/specification#textDocument_documentHighlight )
461
462
- [ textDocument/documentSymbol] ( https://microsoft.github.io/language-server-protocol/specifications/specification-current/#textDocument_documentSymbol )
Original file line number Diff line number Diff line change 17
17
INITIALIZE ,
18
18
TEXT_DOCUMENT_CODE_ACTION ,
19
19
TEXT_DOCUMENT_COMPLETION ,
20
+ TEXT_DOCUMENT_DECLARATION ,
20
21
TEXT_DOCUMENT_DEFINITION ,
21
22
TEXT_DOCUMENT_DID_CHANGE ,
22
23
TEXT_DOCUMENT_DID_CLOSE ,
@@ -306,6 +307,23 @@ def signature_help(
306
307
)
307
308
308
309
310
+ @SERVER .feature (TEXT_DOCUMENT_DECLARATION )
311
+ def declaration (
312
+ server : JediLanguageServer , params : TextDocumentPositionParams
313
+ ) -> Optional [List [Location ]]:
314
+ """Support Goto Declaration."""
315
+ document = server .workspace .get_text_document (params .text_document .uri )
316
+ jedi_script = jedi_utils .script (server .project , document )
317
+ jedi_lines = jedi_utils .line_column (params .position )
318
+ names = jedi_script .goto (* jedi_lines )
319
+ definitions = [
320
+ definition
321
+ for definition in (jedi_utils .lsp_location (name ) for name in names )
322
+ if definition is not None
323
+ ]
324
+ return definitions if definitions else None
325
+
326
+
309
327
@SERVER .feature (TEXT_DOCUMENT_DEFINITION )
310
328
def definition (
311
329
server : JediLanguageServer , params : TextDocumentPositionParams
Original file line number Diff line number Diff line change @@ -152,8 +152,15 @@ def text_document_signature_help(self, signature_help_params):
152
152
)
153
153
return fut .result ()
154
154
155
+ def text_document_declaration (self , declaration_params ):
156
+ """Sends text document declaration request to LSP server."""
157
+ fut = self ._send_request (
158
+ "textDocument/declaration" , params = declaration_params
159
+ )
160
+ return fut .result ()
161
+
155
162
def text_document_definition (self , definition_params ):
156
- """Sends text document defintion request to LSP server."""
163
+ """Sends text document definition request to LSP server."""
157
164
fut = self ._send_request (
158
165
"textDocument/definition" , params = definition_params
159
166
)
Original file line number Diff line number Diff line change @@ -36,3 +36,31 @@ def test_definition():
36
36
]
37
37
38
38
assert_that (actual , is_ (expected ))
39
+
40
+
41
+ def test_declaration ():
42
+ """Tests declaration on an imported module.
43
+
44
+ Test Data: tests/test_data/definition/definition_test1.py
45
+ """
46
+ with session .LspSession () as ls_session :
47
+ ls_session .initialize ()
48
+ uri = as_uri (DEFINITION_TEST_ROOT / "definition_test1.py" )
49
+ actual = ls_session .text_document_declaration (
50
+ {
51
+ "textDocument" : {"uri" : uri },
52
+ "position" : {"line" : 5 , "character" : 0 },
53
+ }
54
+ )
55
+
56
+ expected = [
57
+ {
58
+ "uri" : uri ,
59
+ "range" : {
60
+ "start" : {"line" : 2 , "character" : 26 },
61
+ "end" : {"line" : 2 , "character" : 37 },
62
+ },
63
+ }
64
+ ]
65
+
66
+ assert_that (actual , is_ (expected ))
You can’t perform that action at this time.
0 commit comments