From 8dccac908b046d5e5070c1720f9ef185062a44b4 Mon Sep 17 00:00:00 2001 From: Tobias Reiher Date: Fri, 13 Oct 2023 11:20:14 +0200 Subject: [PATCH] Update pygls Ref. eng/recordflux/RecordFlux#1431 --- rflx/ls/server.py | 4 ++-- setup.py | 2 +- tests/unit/ls/server_test.py | 41 +++++++++++++++++++----------------- 3 files changed, 25 insertions(+), 22 deletions(-) diff --git a/rflx/ls/server.py b/rflx/ls/server.py index a7f86c231..8966232f1 100644 --- a/rflx/ls/server.py +++ b/rflx/ls/server.py @@ -91,7 +91,7 @@ def to_lsp_severity(severity: error.Severity) -> Optional[DiagnosticSeverity]: def initialize_lexer(language_server: RecordFluxLanguageServer, uri: str) -> LSLexer: - document = language_server.workspace.get_document(uri) + document = language_server.workspace.get_text_document(uri) lexer = LSLexer(language_server.models[Path(document.path).parent].ls_model) lexer.tokenize(document.source, document.path) return lexer @@ -142,7 +142,7 @@ def update(self, document_uri: str) -> None: self._error = error.RecordFluxError() for path in workspace_files: - document = self.workspace.get_document(path.as_uri()) + document = self.workspace.get_text_document(path.as_uri()) self._document_state[document.uri] = hash(document.source) try: parser.parse_string(document.source, path) diff --git a/setup.py b/setup.py index 073c28ac1..002db1614 100644 --- a/setup.py +++ b/setup.py @@ -91,7 +91,7 @@ def run(self) -> None: "importlib_resources >=6, <7", # TODO(eng/recordflux/RecordFlux#1359): Remove "pydantic >=1, <2", "pydotplus >=2, <3", - "pygls >=1.0, <1.1", + "pygls >=1.1, <1.2", "ruamel.yaml >=0.17, <0.18", "z3-solver >=4, <5", ], diff --git a/tests/unit/ls/server_test.py b/tests/unit/ls/server_test.py index 32c134d96..aba80e451 100644 --- a/tests/unit/ls/server_test.py +++ b/tests/unit/ls/server_test.py @@ -21,6 +21,7 @@ SemanticTokensParams, TextDocumentIdentifier, TextDocumentItem, + TextDocumentSyncKind, VersionedTextDocumentIdentifier, WorkspaceFolder, ) @@ -62,11 +63,11 @@ @pytest.fixture() def language_server() -> server.RecordFluxLanguageServer: language_server = server.RecordFluxLanguageServer() - language_server.lsp.workspace = Workspace( + language_server.lsp._workspace = Workspace( # noqa: SLF001 DATA_DIR.absolute().as_uri(), - None, + TextDocumentSyncKind.None_, workspace_folders=[WorkspaceFolder(DATA_DIR.absolute().as_uri(), "data")], - ) # type: ignore[no-untyped-call] + ) return language_server @@ -147,11 +148,11 @@ def test_update_directory(tmp_path: Path) -> None: (tmp_path / "directory.rflx").mkdir() ls = server.RecordFluxLanguageServer() - ls.lsp.workspace = Workspace( + ls.lsp._workspace = Workspace( # noqa: SLF001 tmp_path.absolute().as_uri(), - None, + TextDocumentSyncKind.None_, workspace_folders=[WorkspaceFolder(tmp_path.absolute().as_uri(), "tmp_path")], - ) # type: ignore[no-untyped-call] + ) document_uri = (tmp_path / "message.rflx").absolute().as_uri() ls.update(document_uri) @@ -162,12 +163,14 @@ def test_update_no_folders(tmp_path: Path) -> None: document_uri = document.absolute().as_uri() ls = server.RecordFluxLanguageServer() - ls.lsp.workspace = Workspace( + ls.lsp._workspace = Workspace( # noqa: SLF001 tmp_path.absolute().as_uri(), - None, + TextDocumentSyncKind.None_, workspace_folders=[], - ) # type: ignore[no-untyped-call] - ls.lsp.workspace.put_document(TextDocumentItem(document_uri, "", 0, "")) + ) + ls.lsp._workspace.put_document( # type: ignore[no-untyped-call] # noqa: SLF001 + TextDocumentItem(document_uri, "", 0, ""), + ) ls.update(document_uri) @@ -180,11 +183,11 @@ def test_update_error_in_parser(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) document_uri = document.absolute().as_uri() ls = server.RecordFluxLanguageServer() - ls.lsp.workspace = Workspace( + ls.lsp._workspace = Workspace( # noqa: SLF001 tmp_path.absolute().as_uri(), - None, + TextDocumentSyncKind.None_, workspace_folders=[WorkspaceFolder(tmp_path.absolute().as_uri(), "tmp_path")], - ) # type: ignore[no-untyped-call] + ) ls.update(document_uri) assert published_diagnostics == [ @@ -217,11 +220,11 @@ def test_update_error_in_unchecked_model( document_uri = document.absolute().as_uri() ls = server.RecordFluxLanguageServer() - ls.lsp.workspace = Workspace( + ls.lsp._workspace = Workspace( # noqa: SLF001 tmp_path.absolute().as_uri(), - None, + TextDocumentSyncKind.None_, workspace_folders=[WorkspaceFolder(tmp_path.absolute().as_uri(), "tmp_path")], - ) # type: ignore[no-untyped-call] + ) ls.update(document_uri) assert published_diagnostics == [ @@ -249,11 +252,11 @@ def test_verify(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> None: document_uri = document.absolute().as_uri() ls = server.RecordFluxLanguageServer() - ls.lsp.workspace = Workspace( + ls.lsp._workspace = Workspace( # noqa: SLF001 tmp_path.absolute().as_uri(), - None, + TextDocumentSyncKind.None_, workspace_folders=[WorkspaceFolder(tmp_path.absolute().as_uri(), "tmp_path")], - ) # type: ignore[no-untyped-call] + ) ls.update(document_uri) ls.verify(document_uri)