Skip to content

Commit 0916b88

Browse files
authored
Update pygls (#83)
1 parent cd7ba40 commit 0916b88

File tree

5 files changed

+325
-274
lines changed

5 files changed

+325
-274
lines changed

cmake_language_server/server.py

Lines changed: 6 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
from typing import Any, Callable, List, Optional, Tuple
77

88
from lsprotocol.types import (
9-
ALL_TYPES_MAP,
109
INITIALIZE,
1110
INITIALIZED,
1211
TEXT_DOCUMENT_COMPLETION,
@@ -26,8 +25,8 @@
2625
MarkupKind,
2726
Position,
2827
Range,
28+
SaveOptions,
2929
TextDocumentPositionParams,
30-
TextDocumentSaveRegistrationOptions,
3130
TextEdit,
3231
)
3332
from pygls.server import LanguageServer
@@ -37,10 +36,6 @@
3736
logger = logging.getLogger(__name__)
3837

3938

40-
# fix pygls bug
41-
ALL_TYPES_MAP["TextDocumentSaveOptions"] = TextDocumentSaveRegistrationOptions
42-
43-
4439
class CMakeLanguageServer(LanguageServer):
4540
_api: Optional[API]
4641

@@ -159,7 +154,7 @@ def completions(params: CompletionParams) -> CompletionList:
159154
def formatting(
160155
params: DocumentFormattingParams,
161156
) -> Optional[List[TextEdit]]:
162-
doc = self.workspace.get_document(params.text_document.uri)
157+
doc = self.workspace.get_text_document(params.text_document.uri)
163158
content = doc.source
164159
formatted = subprocess.check_output(
165160
["cmake-format", "-"],
@@ -206,7 +201,7 @@ def hover(params: TextDocumentPositionParams) -> Optional[Hover]:
206201
@self.thread()
207202
@self.feature(
208203
TEXT_DOCUMENT_DID_SAVE,
209-
TextDocumentSaveRegistrationOptions(include_text=False),
204+
SaveOptions(include_text=False),
210205
)
211206
@self.feature(INITIALIZED)
212207
def run_cmake(*args: Any) -> None:
@@ -216,14 +211,14 @@ def run_cmake(*args: Any) -> None:
216211
self._api.read_reply()
217212

218213
def _cursor_function(self, uri: str, position: Position) -> Optional[str]:
219-
doc = self.workspace.get_document(uri)
214+
doc = self.workspace.get_text_document(uri)
220215
lines = doc.source.split("\n")[: position.line + 1]
221216
lines[-1] = lines[-1][: position.character - 1].strip()
222217
words = re.split(r"[\s\n()]+", "\n".join(lines))
223218
return words[-1] if words else None
224219

225220
def _cursor_line(self, uri: str, position: Position) -> str:
226-
doc = self.workspace.get_document(uri)
221+
doc = self.workspace.get_text_document(uri)
227222
content = doc.source
228223
line = content.split("\n")[position.line]
229224
return str(line)
@@ -260,4 +255,4 @@ def main() -> None:
260255

261256
logging.basicConfig(level=logging.INFO)
262257
logging.getLogger("pygls").setLevel(logging.WARNING)
263-
CMakeLanguageServer("cmake-language-server", __version__).start_io() # type: ignore
258+
CMakeLanguageServer("cmake-language-server", __version__).start_io()

0 commit comments

Comments
 (0)