Skip to content

Commit

Permalink
feat: add workspace diagnostic support
Browse files Browse the repository at this point in the history
  • Loading branch information
karthiknadig authored and tombh committed Sep 1, 2023
1 parent f95f693 commit 94fdef3
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 1 deletion.
20 changes: 19 additions & 1 deletion examples/servers/json_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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=[":"]),
Expand Down
2 changes: 2 additions & 0 deletions pygls/capabilities.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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

Expand Down
6 changes: 6 additions & 0 deletions tests/lsp/test_diagnostics.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 94fdef3

Please sign in to comment.