1
+ from typing import Optional
2
+
1
3
from pydantic import ValidationError
2
4
from pylspclient import lsp_structs
3
- from pylspclient .lsp_pydantic_strcuts import TextDocumentItem , TextDocumentIdentifier , DocumentSymbol , SymbolInformation
5
+ from pylspclient .lsp_endpoint import LspEndpoint
6
+ from pylspclient .lsp_pydantic_strcuts import TextDocumentItem , TextDocumentIdentifier , DocumentSymbol , SymbolInformation , LocationLink , Location
7
+ from pylspclient .lsp_pydantic_strcuts import Position
4
8
5
9
class LspClient (object ):
6
- def __init__ (self , lsp_endpoint ):
10
+ def __init__ (self , lsp_endpoint : LspEndpoint ):
7
11
"""
8
12
Constructs a new LspClient instance.
9
13
10
- :param lsp_endpoint: TODO
14
+ :param lsp_endpoint:
11
15
"""
12
16
self .lsp_endpoint = lsp_endpoint
13
17
@@ -85,7 +89,7 @@ def didOpen(self, textDocument: TextDocumentItem):
85
89
86
90
:param TextDocumentItem textDocument: The document that was opened.
87
91
"""
88
- return self .lsp_endpoint .send_notification ("textDocument/didOpen" , textDocument = textDocument . dict () )
92
+ return self .lsp_endpoint .send_notification ("textDocument/didOpen" , textDocument = textDocument )
89
93
90
94
91
95
def didChange (self , textDocument , contentChanges ):
@@ -98,7 +102,7 @@ def didChange(self, textDocument, contentChanges):
98
102
to the document. So if there are two content changes c1 and c2 for a document in state S then c1 move the document
99
103
to S' and c2 to S''.
100
104
"""
101
- return self .lsp_endpoint .send_notification ("textDocument/didChange" , textDocument = textDocument , contentChanges = contentChanges )
105
+ self .lsp_endpoint .send_notification ("textDocument/didChange" , textDocument = textDocument , contentChanges = contentChanges )
102
106
103
107
104
108
def documentSymbol (self , textDocument : TextDocumentIdentifier ) -> list [DocumentSymbol ] | list [SymbolInformation ]:
@@ -115,15 +119,19 @@ def documentSymbol(self, textDocument: TextDocumentIdentifier) -> list[DocumentS
115
119
return [SymbolInformation .parse_obj (sym ) for sym in result_dict ]
116
120
117
121
118
- def typeDefinition (self , textDocument , position ):
122
+ def typeDefinition (
123
+ self ,
124
+ textDocument : TextDocumentIdentifier ,
125
+ position : Position
126
+ ) -> list [Location ]:
119
127
"""
120
128
The goto type definition request is sent from the client to the server to resolve the type definition location of a symbol at a given text document position.
121
129
122
130
:param TextDocumentItem textDocument: The text document.
123
131
:param Position position: The position inside the text document.
124
132
"""
125
133
result_dict = self .lsp_endpoint .call_method ("textDocument/typeDefinition" , textDocument = textDocument , position = position )
126
- return [lsp_structs . Location ( ** result ) for result in result_dict ]
134
+ return [Location . parse_obj ( result ) for result in result_dict ]
127
135
128
136
129
137
def signatureHelp (self , textDocument , position ):
@@ -153,7 +161,11 @@ def completion(self, textDocument, position, context):
153
161
return [lsp_structs .CompletionItem (** result ) for result in result_dict ]
154
162
155
163
156
- def declaration (self , textDocument , position ):
164
+ def declaration (
165
+ self ,
166
+ textDocument : TextDocumentIdentifier ,
167
+ position : Position
168
+ ) -> Location | list [Location ] | list [LocationLink ]:
157
169
"""
158
170
The go to declaration request is sent from the client to the server to resolve the declaration location of a
159
171
symbol at a given text document position.
@@ -166,12 +178,18 @@ def declaration(self, textDocument, position):
166
178
"""
167
179
result_dict = self .lsp_endpoint .call_method ("textDocument/declaration" , textDocument = textDocument , position = position )
168
180
if "uri" in result_dict :
169
- return lsp_structs . Location ( ** result_dict )
181
+ return Location . parse_obj ( result_dict )
170
182
171
- return [lsp_structs . Location ( ** result ) if "uri" in result else lsp_structs . LocationLink ( ** result ) for result in result_dict ]
183
+ return [Location . parse_obj ( result ) if "uri" in result else LocationLink . parse_obj ( result ) for result in result_dict ]
172
184
173
185
174
- def definition (self , textDocument , position ):
186
+ def definition (
187
+ self ,
188
+ textDocument : TextDocumentIdentifier ,
189
+ position : Position ,
190
+ workDoneToken : Optional [str ] = None ,
191
+ partialResultToken : Optional [str ] = None
192
+ ) -> Location | list [Location ] | list [LocationLink ]:
175
193
"""
176
194
The go to definition request is sent from the client to the server to resolve the declaration location of a
177
195
symbol at a given text document position.
@@ -184,6 +202,6 @@ def definition(self, textDocument, position):
184
202
"""
185
203
result_dict = self .lsp_endpoint .call_method ("textDocument/definition" , textDocument = textDocument , position = position )
186
204
if "uri" in result_dict :
187
- return lsp_structs . Location ( ** result_dict )
205
+ return Location . parse_obj ( result_dict )
188
206
189
- return [lsp_structs . Location ( ** result ) if "uri" in result else lsp_structs . LocationLink ( ** result ) for result in result_dict ]
207
+ return [Location . parse_obj ( result ) if "uri" in result else LocationLink . parse_obj ( result ) for result in result_dict ]
0 commit comments