Skip to content

Commit c4c470c

Browse files
authored
Merge pull request pappasam#285 from dimbleby/pygls-1.1
pygls 1.1
2 parents 77e4c19 + 600975a commit c4c470c

File tree

7 files changed

+105
-235
lines changed

7 files changed

+105
-235
lines changed

jedi_language_server/initialization_options.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
from cattrs.gen import make_dict_structure_fn, override
1414
from lsprotocol.types import MarkupKind
1515

16+
# pylint: disable=invalid-field-call
1617
# pylint: disable=missing-class-docstring
1718
# pylint: disable=too-few-public-methods
1819

jedi_language_server/jedi_utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
SymbolInformation,
3333
SymbolKind,
3434
)
35-
from pygls.workspace import Document
35+
from pygls.workspace import TextDocument # type: ignore[attr-defined]
3636

3737
from .initialization_options import HoverDisableOptions, InitializationOptions
3838
from .type_map import get_lsp_completion_type, get_lsp_symbol_type
@@ -113,7 +113,7 @@ def set_jedi_settings( # pylint: disable=invalid-name
113113
jedi.set_debug_function(func_cb=_jedi_debug_function)
114114

115115

116-
def script(project: Optional[Project], document: Document) -> Script:
116+
def script(project: Optional[Project], document: TextDocument) -> Script:
117117
"""Simplifies getting jedi Script."""
118118
return Script(code=document.source, path=document.path, project=project)
119119

jedi_language_server/pygls_utils.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@
77
from typing import Optional
88

99
from lsprotocol.types import Position, Range
10-
from pygls.workspace import Document
10+
from pygls.workspace import TextDocument # type: ignore[attr-defined]
1111

1212

1313
def char_before_cursor(
14-
document: Document, position: Position, default: str = ""
14+
document: TextDocument, position: Position, default: str = ""
1515
) -> str:
1616
"""Get the character directly before the cursor."""
1717
try:
@@ -21,7 +21,7 @@ def char_before_cursor(
2121

2222

2323
def char_after_cursor(
24-
document: Document, position: Position, default: str = ""
24+
document: TextDocument, position: Position, default: str = ""
2525
) -> str:
2626
"""Get the character directly before the cursor."""
2727
try:
@@ -31,7 +31,7 @@ def char_after_cursor(
3131

3232

3333
def current_word_range(
34-
document: Document, position: Position
34+
document: TextDocument, position: Position
3535
) -> Optional[Range]:
3636
"""Get the range of the word under the cursor."""
3737
word = document.word_at_position(position)

jedi_language_server/server.py

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,14 +78,16 @@
7878
class JediLanguageServerProtocol(LanguageServerProtocol):
7979
"""Override some built-in functions."""
8080

81+
_server: "JediLanguageServer"
82+
8183
@lsp_method(INITIALIZE)
8284
def lsp_initialize(self, params: InitializeParams) -> InitializeResult:
8385
"""Override built-in initialization.
8486
8587
Here, we can conditionally register functions to features based
8688
on client capabilities and initializationOptions.
8789
"""
88-
server: "JediLanguageServer" = self._server
90+
server = self._server
8991
try:
9092
server.initialization_options = (
9193
initialization_options_converter.structure(
@@ -203,7 +205,7 @@ def completion(
203205
snippet_disable = server.initialization_options.completion.disable_snippets
204206
resolve_eagerly = server.initialization_options.completion.resolve_eagerly
205207
ignore_patterns = server.initialization_options.completion.ignore_patterns
206-
document = server.workspace.get_document(params.text_document.uri)
208+
document = server.workspace.get_text_document(params.text_document.uri)
207209
jedi_script = jedi_utils.script(server.project, document)
208210
jedi_lines = jedi_utils.line_column(params.position)
209211
completions_jedi_raw = jedi_script.complete(*jedi_lines)
@@ -232,7 +234,7 @@ def completion(
232234
snippet_support and not snippet_disable and not is_import_context
233235
)
234236
char_before_cursor = pygls_utils.char_before_cursor(
235-
document=server.workspace.get_document(params.text_document.uri),
237+
document=server.workspace.get_text_document(params.text_document.uri),
236238
position=params.position,
237239
)
238240
jedi_utils.clear_completions_cache()
@@ -270,7 +272,7 @@ def signature_help(
270272
handle markdown well in the signature. Will update if this changes in the
271273
future.
272274
"""
273-
document = server.workspace.get_document(params.text_document.uri)
275+
document = server.workspace.get_text_document(params.text_document.uri)
274276
jedi_script = jedi_utils.script(server.project, document)
275277
jedi_lines = jedi_utils.line_column(params.position)
276278
signatures_jedi = jedi_script.get_signatures(*jedi_lines)
@@ -310,7 +312,7 @@ def definition(
310312
server: JediLanguageServer, params: TextDocumentPositionParams
311313
) -> Optional[List[Location]]:
312314
"""Support Goto Definition."""
313-
document = server.workspace.get_document(params.text_document.uri)
315+
document = server.workspace.get_text_document(params.text_document.uri)
314316
jedi_script = jedi_utils.script(server.project, document)
315317
jedi_lines = jedi_utils.line_column(params.position)
316318
names = jedi_script.goto(
@@ -331,7 +333,7 @@ def type_definition(
331333
server: JediLanguageServer, params: TextDocumentPositionParams
332334
) -> Optional[List[Location]]:
333335
"""Support Goto Type Definition."""
334-
document = server.workspace.get_document(params.text_document.uri)
336+
document = server.workspace.get_text_document(params.text_document.uri)
335337
jedi_script = jedi_utils.script(server.project, document)
336338
jedi_lines = jedi_utils.line_column(params.position)
337339
names = jedi_script.infer(*jedi_lines)
@@ -358,7 +360,7 @@ def highlight(
358360
Finally, we only return names if there are more than 1. Otherwise, we don't
359361
want to highlight anything.
360362
"""
361-
document = server.workspace.get_document(params.text_document.uri)
363+
document = server.workspace.get_text_document(params.text_document.uri)
362364
jedi_script = jedi_utils.script(server.project, document)
363365
jedi_lines = jedi_utils.line_column(params.position)
364366
names = jedi_script.get_references(*jedi_lines, scope="file")
@@ -376,7 +378,7 @@ def hover(
376378
server: JediLanguageServer, params: TextDocumentPositionParams
377379
) -> Optional[Hover]:
378380
"""Support Hover."""
379-
document = server.workspace.get_document(params.text_document.uri)
381+
document = server.workspace.get_text_document(params.text_document.uri)
380382
jedi_script = jedi_utils.script(server.project, document)
381383
jedi_lines = jedi_utils.line_column(params.position)
382384
markup_kind = _choose_markup(server)
@@ -397,7 +399,7 @@ def references(
397399
server: JediLanguageServer, params: TextDocumentPositionParams
398400
) -> Optional[List[Location]]:
399401
"""Obtain all references to text."""
400-
document = server.workspace.get_document(params.text_document.uri)
402+
document = server.workspace.get_text_document(params.text_document.uri)
401403
jedi_script = jedi_utils.script(server.project, document)
402404
jedi_lines = jedi_utils.line_column(params.position)
403405
names = jedi_script.get_references(*jedi_lines)
@@ -431,7 +433,7 @@ def document_symbol(
431433
non-hierarchical symbols, we simply remove `param` symbols. Others are
432434
included for completeness.
433435
"""
434-
document = server.workspace.get_document(params.text_document.uri)
436+
document = server.workspace.get_text_document(params.text_document.uri)
435437
jedi_script = jedi_utils.script(server.project, document)
436438
names = jedi_script.get_names(all_scopes=True, definitions=True)
437439
if get_capability(
@@ -513,7 +515,7 @@ def rename(
513515
server: JediLanguageServer, params: RenameParams
514516
) -> Optional[WorkspaceEdit]:
515517
"""Rename a symbol across a workspace."""
516-
document = server.workspace.get_document(params.text_document.uri)
518+
document = server.workspace.get_text_document(params.text_document.uri)
517519
jedi_script = jedi_utils.script(server.project, document)
518520
jedi_lines = jedi_utils.line_column(params.position)
519521
try:
@@ -545,7 +547,7 @@ def code_action(
545547
2. Extract variable
546548
3. Extract function
547549
"""
548-
document = server.workspace.get_document(params.text_document.uri)
550+
document = server.workspace.get_text_document(params.text_document.uri)
549551
jedi_script = jedi_utils.script(server.project, document)
550552
code_actions = []
551553
jedi_lines = jedi_utils.line_column(params.range.start)
@@ -649,7 +651,7 @@ def _publish_diagnostics(server: JediLanguageServer, uri: str) -> None:
649651
if uri not in server.workspace.documents:
650652
return
651653

652-
doc = server.workspace.get_document(uri)
654+
doc = server.workspace.get_text_document(uri)
653655
diagnostic = jedi_utils.lsp_python_diagnostic(uri, doc.source)
654656
diagnostics = [diagnostic] if diagnostic else []
655657

jedi_language_server/text_edit_utils.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,10 @@
2323
TextDocumentEdit,
2424
TextEdit,
2525
)
26-
from pygls.workspace import Document, Workspace
26+
from pygls.workspace import ( # type: ignore[attr-defined]
27+
TextDocument,
28+
Workspace,
29+
)
2730

2831

2932
def is_valid_python(code: str) -> bool:
@@ -74,7 +77,7 @@ def lsp_text_document_edits(self) -> Iterator[TextDocumentEdit]:
7477
changed_files = self.refactoring.get_changed_files()
7578
for path, changed_file in changed_files.items():
7679
uri = path.as_uri()
77-
document = self.workspace.get_document(uri)
80+
document = self.workspace.get_text_document(uri)
7881
version = 0 if document.version is None else document.version
7982
text_edits = lsp_text_edits(document, changed_file)
8083
if text_edits:
@@ -91,7 +94,7 @@ def lsp_text_document_edits(self) -> Iterator[TextDocumentEdit]:
9194

9295

9396
def lsp_text_edits(
94-
document: Document, changed_file: ChangedFile
97+
document: TextDocument, changed_file: ChangedFile
9598
) -> List[Union[TextEdit, AnnotatedTextEdit]]:
9699
"""Take a jedi `ChangedFile` and convert to list of text edits.
97100

0 commit comments

Comments
 (0)