Skip to content

Commit e5b6e52

Browse files
authored
Use pygls==2.0.0 in fixit (#540)
1 parent 739992d commit e5b6e52

2 files changed

Lines changed: 13 additions & 8 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ dev = [
5454
"pyrefly == 0.39.4",
5555
]
5656
lsp = [
57-
"pygls[ws] ~= 1.3.1",
57+
"pygls[ws] ~= 2.0.0",
5858
]
5959
pretty = [
6060
"rich >= 12.6.0",

src/fixit/lsp.py

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,14 @@
1616
DidOpenTextDocumentParams,
1717
DocumentFormattingParams,
1818
Position,
19+
PublishDiagnosticsParams,
1920
Range,
2021
TEXT_DOCUMENT_DID_CHANGE,
2122
TEXT_DOCUMENT_DID_OPEN,
2223
TEXT_DOCUMENT_FORMATTING,
2324
TextEdit,
2425
)
25-
from pygls.server import LanguageServer
26+
from pygls.lsp.server import LanguageServer
2627
from pygls.workspace.text_document import TextDocument
2728

2829
from .__version__ import __version__
@@ -69,12 +70,12 @@ def diagnostic_generator(
6970
"""
7071
LSP wrapper (provides document state from `pygls`) for `fixit_bytes`.
7172
"""
72-
path = Uri.to_fs_path(uri)
73-
if not path:
73+
path_uri = Uri.to_fs_path(uri)
74+
if not path_uri:
7475
return None
75-
path = Path(path)
76+
path = Path(path_uri)
7677

77-
doc: TextDocument = self.lsp.workspace.get_document(uri) # type: ignore[no-untyped-call]
78+
doc: TextDocument = self.lsp.workspace.get_text_document(uri) # type: ignore[no-untyped-call]
7879
return fixit_bytes(
7980
path,
8081
doc.source.encode(),
@@ -107,7 +108,9 @@ def _validate(self, uri: str, version: int) -> None:
107108
source="fixit",
108109
)
109110
diagnostics.append(diagnostic)
110-
self.lsp.publish_diagnostics(uri, diagnostics, version=version)
111+
self.lsp.text_document_publish_diagnostics(
112+
PublishDiagnosticsParams(uri, diagnostics, version)
113+
)
111114

112115
def validate(self, uri: str, version: int) -> None:
113116
"""
@@ -137,7 +140,9 @@ def format(self, params: DocumentFormattingParams) -> Optional[List[TextEdit]]:
137140
if not formatted_content:
138141
return None
139142

140-
doc: TextDocument = self.lsp.workspace.get_document(params.text_document.uri) # type: ignore[no-untyped-call]
143+
doc: TextDocument = self.lsp.workspace.get_text_document(
144+
params.text_document.uri
145+
)
141146
entire_range = Range(
142147
start=Position(line=0, character=0),
143148
end=Position(line=len(doc.lines) - 1, character=len(doc.lines[-1])),

0 commit comments

Comments
 (0)