From 8090c7a8c300e4f9db999402ac0db1e44a1f4c01 Mon Sep 17 00:00:00 2001 From: Karthik Nadig Date: Thu, 31 Aug 2023 15:38:37 -0700 Subject: [PATCH] feat: add workspace diagnostic support --- examples/servers/json_server.py | 20 +++++++++++++++++++- pygls/capabilities.py | 2 ++ tests/lsp/test_diagnostics.py | 6 ++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/examples/servers/json_server.py b/examples/servers/json_server.py index 34fe101b..9700becc 100644 --- a/examples/servers/json_server.py +++ b/examples/servers/json_server.py @@ -91,7 +91,7 @@ def _validate_json(source): lsp.DiagnosticOptions( identifier="jsonServer", inter_file_dependencies=True, - workspace_diagnostics=False, + workspace_diagnostics=True, ), ) def text_document_diagnostic( @@ -105,6 +105,24 @@ def text_document_diagnostic( ) +@json_server.feature(lsp.WORKSPACE_DIAGNOSTIC) +def workspace_diagnostic( + params: lsp.WorkspaceDiagnosticParams, +) -> lsp.WorkspaceDiagnosticReport: + """Returns diagnostic report.""" + first = list(json_server.workspace._docs.keys())[0] + document = json_server.workspace.get_document(first) + return lsp.WorkspaceDiagnosticReport( + items=[ + lsp.WorkspaceFullDocumentDiagnosticReport( + uri=document.uri, + items=_validate_json(document.source), + kind=lsp.DocumentDiagnosticReportKind.Full, + ) + ] + ) + + @json_server.feature( lsp.TEXT_DOCUMENT_COMPLETION, lsp.CompletionOptions(trigger_characters=[","], all_commit_characters=[":"]), diff --git a/pygls/capabilities.py b/pygls/capabilities.py index e5157582..d2506ebd 100644 --- a/pygls/capabilities.py +++ b/pygls/capabilities.py @@ -52,6 +52,7 @@ TEXT_DOCUMENT_WILL_SAVE, TEXT_DOCUMENT_WILL_SAVE_WAIT_UNTIL, TEXT_DOCUMENT_TYPE_DEFINITION, + WORKSPACE_DIAGNOSTIC, WORKSPACE_DID_CREATE_FILES, WORKSPACE_DID_DELETE_FILES, WORKSPACE_DID_RENAME_FILES, @@ -392,6 +393,7 @@ def _with_workspace_capabilities(self): def _with_diagnostic_provider(self): value = self._provider_options(TEXT_DOCUMENT_DIAGNOSTIC) if value is not None: + value.workspace_diagnostics = self._provider_options(WORKSPACE_DIAGNOSTIC) self.server_cap.diagnostic_provider = value return self diff --git a/tests/lsp/test_diagnostics.py b/tests/lsp/test_diagnostics.py index e27b826c..c420942a 100644 --- a/tests/lsp/test_diagnostics.py +++ b/tests/lsp/test_diagnostics.py @@ -60,3 +60,9 @@ async def test_diagnostics( ) diagnostics = result.items assert diagnostics[0].message == expected_message + + workspace_result = await client.workspace_diagnostic_async( + types.WorkspaceDiagnosticParams(previous_result_ids=[]) + ) + diagnostics = workspace_result.items[0].items + assert diagnostics[0].message == expected_message