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

add a client option for hiding non-project diagnostics #2218

Merged
merged 4 commits into from
Mar 24, 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
1 change: 1 addition & 0 deletions docs/src/client_configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ Below is an example of the `LSP.sublime-settings` file with configurations for t
| initializationOptions | options to send to the server at startup (rarely used) |
| selector | This is _the_ connection between your files and language servers. It's a selector that is matched against the current view's base scope. If the selector matches with the base scope of the the file, the associated language server is started. For more information, see https://www.sublimetext.com/docs/3/selectors.html |
| priority_selector | Used to prioritize a certain language server when choosing which one to query on views with multiple servers active. Certain LSP actions have to pick which server to query and this setting can be used to decide which one to pick based on the current scopes at the cursor location. For example when having both HTML and PHP servers running on a PHP file, this can be used to give priority to the HTML one in HTML blocks and to PHP one otherwise. That would be done by setting "feature_selector" to `text.html` for HTML server and `source.php` to PHP server. Note: when the "feature_selector" is missing, it will be the same as the "document_selector".
| hide_non_project_diagnostics | Enable to ignore diagnostics for files that are not within the project (window) folders. If project has no folders then this option has no effect and diagnostics are shown for all files. |
| tcp_port | see instructions below |
| experimental_capabilities | Turn on experimental capabilities of a language server. This is a dictionary and differs per language server |
| disabled_capabilities | Disables specific capabilities of a language server. This is a dictionary with key being a capability key and being `true`. Refer to the `ServerCapabilities` structure in [LSP capabilities](https://microsoft.github.io/language-server-protocol/specifications/specification-current/#initialize) to find capabilities that you might want to disable. Note that the value should be `true` rather than `false` for capabilites that you want to disable. For example: `"signatureHelpProvider": true` |
Expand Down
9 changes: 9 additions & 0 deletions messages/1.24.0.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
=> 1.23.0

⚠️ To ensure that everything works properly after LSP package is updated, it's strongly recommended to restart
Sublime Text once it finishes updating all packages. ⚠️

# Breaking changes

- Diagnostics for files that are not withing the project folders are no longer ignored.
You can set `hide_non_project_diagnostics` in server-specific configuration to enable old behavior.
4 changes: 2 additions & 2 deletions plugin/core/sessions.py
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ def get_project_path(self, file_path: str) -> Optional[str]:
raise NotImplementedError()

@abstractmethod
def should_present_diagnostics(self, uri: DocumentUri) -> Optional[str]:
def should_present_diagnostics(self, uri: DocumentUri, configuration: ClientConfig) -> Optional[str]:
"""
Should the diagnostics for this URI be shown in the view? Return a reason why not
"""
Expand Down Expand Up @@ -1751,7 +1751,7 @@ def m_textDocument_publishDiagnostics(self, params: PublishDiagnosticsParams) ->
if not mgr:
return
uri = params["uri"]
reason = mgr.should_present_diagnostics(uri)
reason = mgr.should_present_diagnostics(uri, self.config)
if isinstance(reason, str):
return debug("ignoring unsuitable diagnostics for", uri, "reason:", reason)
diagnostics = params["diagnostics"]
Expand Down
6 changes: 6 additions & 0 deletions plugin/core/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,7 @@ def __init__(self,
disabled_capabilities: DottedDict = DottedDict(),
file_watcher: FileWatcherConfig = {},
semantic_tokens: Optional[Dict[str, str]] = None,
hide_non_project_diagnostics: bool = False,
path_maps: Optional[List[PathMap]] = None) -> None:
self.name = name
self.selector = selector
Expand All @@ -676,6 +677,7 @@ def __init__(self,
self.path_maps = path_maps
self.status_key = "lsp_{}".format(self.name)
self.semantic_tokens = semantic_tokens
self.hide_non_project_diagnostics = hide_non_project_diagnostics

@classmethod
def from_sublime_settings(cls, name: str, s: sublime.Settings, file: str) -> "ClientConfig":
Expand Down Expand Up @@ -708,6 +710,7 @@ def from_sublime_settings(cls, name: str, s: sublime.Settings, file: str) -> "Cl
disabled_capabilities=disabled_capabilities,
file_watcher=file_watcher,
semantic_tokens=semantic_tokens,
hide_non_project_diagnostics=bool(s.get("hide_non_project_diagnostics", False)),
path_maps=PathMap.parse(s.get("path_maps"))
)

Expand Down Expand Up @@ -737,6 +740,7 @@ def from_dict(cls, name: str, d: Dict[str, Any]) -> "ClientConfig":
disabled_capabilities=disabled_capabilities,
file_watcher=d.get("file_watcher", dict()),
semantic_tokens=d.get("semantic_tokens", dict()),
hide_non_project_diagnostics=d.get("hide_non_project_diagnostics", False),
path_maps=PathMap.parse(d.get("path_maps"))
)

Expand Down Expand Up @@ -766,6 +770,8 @@ def from_config(cls, src_config: "ClientConfig", override: Dict[str, Any]) -> "C
disabled_capabilities=disabled_capabilities,
file_watcher=override.get("file_watcher", src_config.file_watcher),
semantic_tokens=override.get("semantic_tokens", src_config.semantic_tokens),
hide_non_project_diagnostics=override.get(
"hide_non_project_diagnostics", src_config.hide_non_project_diagnostics),
path_maps=path_map_override if path_map_override else src_config.path_maps
)

Expand Down
4 changes: 2 additions & 2 deletions plugin/core/windows.py
Original file line number Diff line number Diff line change
Expand Up @@ -344,11 +344,11 @@ def get_project_path(self, file_path: str) -> Optional[str]:
candidate = folder
return candidate

def should_present_diagnostics(self, uri: DocumentUri) -> Optional[str]:
def should_present_diagnostics(self, uri: DocumentUri, configuration: ClientConfig) -> Optional[str]:
scheme, path = parse_uri(uri)
if scheme != "file":
return None
if not self._workspace.contains(path):
if configuration.hide_non_project_diagnostics and not self._workspace.contains(path):
return "not inside window folders"
view = self._window.active_view()
if not view:
Expand Down
11 changes: 11 additions & 0 deletions sublime-package.json
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,11 @@
}
]
},
"ClientHideNonProjectDiagnostics": {
"markdownDescription": "Whether diagnostics are ignored for files that are not within the project folders.",
"type": "boolean",
"default": false,
},
"ClientPrioritySelector": {
"markdownDescription": "While the `\"selector\"` is used to determine which views belong to which language server configuration, the `\"priority_selector\"` is used to determine which language server wins at the caret position in case there are multiple language servers attached to a view. For instance, there can only be one signature help popup visible at any given time. This selector is use to decide which one to use for such capabilities. This setting is optional and you won't need to set it if you're planning on using a single language server for a particular type of view."
},
Expand Down Expand Up @@ -361,6 +366,9 @@
"feature_selector": {
"$ref": "#/definitions/useSelectorInstead"
},
"hide_non_project_diagnostics": {
"$ref": "#/definitions/ClientHideNonProjectDiagnostics"
},
"syntaxes": {
"type": "array",
"$ref": "#/definitions/useSelectorInstead"
Expand Down Expand Up @@ -743,6 +751,9 @@
"schemes": {
"$ref": "sublime://settings/LSP#/definitions/ClientSchemes"
},
"hide_non_project_diagnostics": {
"$ref": "sublime://settings/LSP#/definitions/ClientHideNonProjectDiagnostics"
},
"priority_selector": {
"$ref": "sublime://settings/LSP#/definitions/ClientPrioritySelector"
},
Expand Down