Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add workspace diagnostic support #363

Merged
merged 1 commit into from
Sep 1, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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