-
Notifications
You must be signed in to change notification settings - Fork 188
Moved diagnostic panel contributions from SessionBuffer to Session (#1868) #1881
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
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
cc2948c
Moved diagnostic panel contributions from SessionBuffer to Session (s…
htmue b6d2c65
Handle clear diagnostics messages safely (sublimelsp/LSP#1868).
htmue c6cb4f9
Added function signature (sublimelsp/LSP#1868).
htmue 9c7a575
Merge branch 'main' into fix/session-diagnostics-manager
htmue 87ee7fe
Removed unused code and some newlines (sublimelsp/LSP#1868).
htmue 728ccf5
Added _async suffix (sublimelsp/LSP#1868).
htmue 943f10e
Filter empty contributions properly (sublimelsp/LSP#1868).
htmue 305bc21
Use path as key (sublimelsp/LSP#1868).
htmue File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,60 @@ | ||
| from .protocol import Diagnostic, DiagnosticSeverity | ||
| from .settings import userprefs | ||
| from .typing import Callable, Iterator, List, Optional, Tuple | ||
| from .url import parse_uri | ||
| from .views import diagnostic_severity, format_diagnostic_for_panel | ||
| from collections import OrderedDict | ||
|
|
||
|
|
||
| class DiagnosticsManager(OrderedDict): | ||
| # From the specs: | ||
| # | ||
| # When a file changes it is the server’s responsibility to re-compute | ||
| # diagnostics and push them to the client. If the computed set is empty | ||
| # it has to push the empty array to clear former diagnostics. Newly | ||
| # pushed diagnostics always replace previously pushed diagnostics. There | ||
| # is no merging that happens on the client side. | ||
| # | ||
| # https://microsoft.github.io/language-server-protocol/specification#textDocument_publishDiagnostics | ||
|
|
||
| def add_diagnostics_async(self, uri: str, diagnostics: List[Diagnostic]) -> None: | ||
| _, path = parse_uri(uri) | ||
| if not diagnostics: | ||
| # received "clear diagnostics" message for this path | ||
| self.pop(path, None) | ||
| return | ||
| max_severity = userprefs().diagnostics_panel_include_severity_level | ||
| self[path] = ( | ||
| list( | ||
| filter( | ||
| None, | ||
| ( | ||
| format_diagnostic_for_panel(diagnostic) | ||
| for diagnostic in diagnostics | ||
| if diagnostic_severity(diagnostic) <= max_severity | ||
| ), | ||
| ) | ||
| ), | ||
| len(list(filter(has_severity(DiagnosticSeverity.Error), diagnostics))), | ||
| len(list(filter(has_severity(DiagnosticSeverity.Warning), diagnostics))), | ||
| ) | ||
| self.move_to_end(path) # maintain incoming order | ||
|
|
||
| def diagnostics_panel_contributions_async( | ||
| self, | ||
| ) -> Iterator[Tuple[str, List[Tuple[str, Optional[int], Optional[str], Optional[str]]]]]: | ||
| for path, (contribution, _, _) in self.items(): | ||
| if contribution: | ||
| yield path, contribution | ||
|
|
||
| def sum_total_errors_and_warnings_async(self) -> Tuple[int, int]: | ||
| return ( | ||
| sum(errors for _, errors, _ in self.values()), | ||
| sum(warnings for _, _, warnings in self.values()), | ||
| ) | ||
|
|
||
|
|
||
| def has_severity(severity: int) -> Callable[[Diagnostic], bool]: | ||
| def has_severity(diagnostic: Diagnostic) -> bool: | ||
| return diagnostic_severity(diagnostic) == severity | ||
| return has_severity |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.