From 22381da0cba670d2eeae408eec76d3675dd38a3d Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sat, 11 Mar 2023 23:23:04 +0100 Subject: [PATCH 1/4] add an option for not ignoring non-project diagnostics --- plugin/core/sessions.py | 4 ++-- plugin/core/types.py | 6 ++++++ plugin/core/windows.py | 4 ++-- 3 files changed, 10 insertions(+), 4 deletions(-) diff --git a/plugin/core/sessions.py b/plugin/core/sessions.py index f49647421..d87ed97e3 100644 --- a/plugin/core/sessions.py +++ b/plugin/core/sessions.py @@ -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 """ @@ -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"] diff --git a/plugin/core/types.py b/plugin/core/types.py index c4c1dc99f..5cdd76c00 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -651,6 +651,7 @@ def __init__(self, disabled_capabilities: DottedDict = DottedDict(), file_watcher: FileWatcherConfig = {}, semantic_tokens: Optional[Dict[str, str]] = None, + show_non_project_diagnostics: bool = False, path_maps: Optional[List[PathMap]] = None) -> None: self.name = name self.selector = selector @@ -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.show_non_project_diagnostics = show_non_project_diagnostics @classmethod def from_sublime_settings(cls, name: str, s: sublime.Settings, file: str) -> "ClientConfig": @@ -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, + show_non_project_diagnostics=bool(s.get("show_non_project_diagnostics", False)), path_maps=PathMap.parse(s.get("path_maps")) ) @@ -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()), + show_non_project_diagnostics=d.get("show_non_project_diagnostics", False), path_maps=PathMap.parse(d.get("path_maps")) ) @@ -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), + show_non_project_diagnostics=override.get( + "show_non_project_diagnostics", src_config.show_non_project_diagnostics), path_maps=path_map_override if path_map_override else src_config.path_maps ) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index daad219df..c084c99db 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -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 not configuration.show_non_project_diagnostics and not self._workspace.contains(path): return "not inside window folders" view = self._window.active_view() if not view: From d1f7a8bdcbf13da272c1be1f02ebaf5d0f5f8eb6 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Sun, 12 Mar 2023 20:10:43 +0100 Subject: [PATCH 2/4] schema and docs --- docs/src/client_configuration.md | 1 + sublime-package.json | 11 +++++++++++ 2 files changed, 12 insertions(+) diff --git a/docs/src/client_configuration.md b/docs/src/client_configuration.md index 0da733fb8..a21e0103d 100644 --- a/docs/src/client_configuration.md +++ b/docs/src/client_configuration.md @@ -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". +| show_non_project_diagnostics | By default all diagnostics are ignored for files that are not within the current project (window) folders. Set this to `true` to see diagnostics even if the file is not within the project folders. If project (window) has no folders then diagnostics are never ignored, regardless what this option is set to. | | 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` | diff --git a/sublime-package.json b/sublime-package.json index 7852004d5..014ad78d0 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -298,6 +298,11 @@ } ] }, + "ClientShowNonProjectDiagnostics": { + "markdownDescription": "Whether diagnostics are reported for files that are not contained 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." }, @@ -361,6 +366,9 @@ "feature_selector": { "$ref": "#/definitions/useSelectorInstead" }, + "show_non_project_diagnostics": { + "$ref": "#/definitions/ClientShowNonProjectDiagnostics" + }, "syntaxes": { "type": "array", "$ref": "#/definitions/useSelectorInstead" @@ -743,6 +751,9 @@ "schemes": { "$ref": "sublime://settings/LSP#/definitions/ClientSchemes" }, + "show_non_project_diagnostics": { + "$ref": "sublime://settings/LSP#/definitions/ClientShowNonProjectDiagnostics" + }, "priority_selector": { "$ref": "sublime://settings/LSP#/definitions/ClientPrioritySelector" }, From 8e860ddf29f510690b855b0dfbb4f3ed4a231671 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Wed, 22 Mar 2023 23:10:29 +0100 Subject: [PATCH 3/4] rename to hide_non_project_diagnostics --- docs/src/client_configuration.md | 2 +- plugin/core/types.py | 12 ++++++------ plugin/core/windows.py | 2 +- sublime-package.json | 12 ++++++------ 4 files changed, 14 insertions(+), 14 deletions(-) diff --git a/docs/src/client_configuration.md b/docs/src/client_configuration.md index a21e0103d..1945bfd13 100644 --- a/docs/src/client_configuration.md +++ b/docs/src/client_configuration.md @@ -42,7 +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". -| show_non_project_diagnostics | By default all diagnostics are ignored for files that are not within the current project (window) folders. Set this to `true` to see diagnostics even if the file is not within the project folders. If project (window) has no folders then diagnostics are never ignored, regardless what this option is set to. | +| 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` | diff --git a/plugin/core/types.py b/plugin/core/types.py index 5cdd76c00..430cdd033 100644 --- a/plugin/core/types.py +++ b/plugin/core/types.py @@ -651,7 +651,7 @@ def __init__(self, disabled_capabilities: DottedDict = DottedDict(), file_watcher: FileWatcherConfig = {}, semantic_tokens: Optional[Dict[str, str]] = None, - show_non_project_diagnostics: bool = False, + hide_non_project_diagnostics: bool = False, path_maps: Optional[List[PathMap]] = None) -> None: self.name = name self.selector = selector @@ -677,7 +677,7 @@ def __init__(self, self.path_maps = path_maps self.status_key = "lsp_{}".format(self.name) self.semantic_tokens = semantic_tokens - self.show_non_project_diagnostics = show_non_project_diagnostics + self.hide_non_project_diagnostics = hide_non_project_diagnostics @classmethod def from_sublime_settings(cls, name: str, s: sublime.Settings, file: str) -> "ClientConfig": @@ -710,7 +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, - show_non_project_diagnostics=bool(s.get("show_non_project_diagnostics", False)), + hide_non_project_diagnostics=bool(s.get("hide_non_project_diagnostics", False)), path_maps=PathMap.parse(s.get("path_maps")) ) @@ -740,7 +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()), - show_non_project_diagnostics=d.get("show_non_project_diagnostics", False), + hide_non_project_diagnostics=d.get("hide_non_project_diagnostics", False), path_maps=PathMap.parse(d.get("path_maps")) ) @@ -770,8 +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), - show_non_project_diagnostics=override.get( - "show_non_project_diagnostics", src_config.show_non_project_diagnostics), + 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 ) diff --git a/plugin/core/windows.py b/plugin/core/windows.py index c084c99db..1f28dc9f3 100644 --- a/plugin/core/windows.py +++ b/plugin/core/windows.py @@ -348,7 +348,7 @@ def should_present_diagnostics(self, uri: DocumentUri, configuration: ClientConf scheme, path = parse_uri(uri) if scheme != "file": return None - if not configuration.show_non_project_diagnostics and 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: diff --git a/sublime-package.json b/sublime-package.json index 014ad78d0..49f503145 100644 --- a/sublime-package.json +++ b/sublime-package.json @@ -298,8 +298,8 @@ } ] }, - "ClientShowNonProjectDiagnostics": { - "markdownDescription": "Whether diagnostics are reported for files that are not contained within the project folders.", + "ClientHideNonProjectDiagnostics": { + "markdownDescription": "Whether diagnostics are ignored for files that are not within the project folders.", "type": "boolean", "default": false, }, @@ -366,8 +366,8 @@ "feature_selector": { "$ref": "#/definitions/useSelectorInstead" }, - "show_non_project_diagnostics": { - "$ref": "#/definitions/ClientShowNonProjectDiagnostics" + "hide_non_project_diagnostics": { + "$ref": "#/definitions/ClientHideNonProjectDiagnostics" }, "syntaxes": { "type": "array", @@ -751,8 +751,8 @@ "schemes": { "$ref": "sublime://settings/LSP#/definitions/ClientSchemes" }, - "show_non_project_diagnostics": { - "$ref": "sublime://settings/LSP#/definitions/ClientShowNonProjectDiagnostics" + "hide_non_project_diagnostics": { + "$ref": "sublime://settings/LSP#/definitions/ClientHideNonProjectDiagnostics" }, "priority_selector": { "$ref": "sublime://settings/LSP#/definitions/ClientPrioritySelector" From e4eab178a5cee58b6bbc262740fc46d520511e22 Mon Sep 17 00:00:00 2001 From: Rafal Chlodnicki Date: Wed, 22 Mar 2023 23:14:18 +0100 Subject: [PATCH 4/4] add changelog --- messages/1.24.0.txt | 9 +++++++++ 1 file changed, 9 insertions(+) create mode 100644 messages/1.24.0.txt diff --git a/messages/1.24.0.txt b/messages/1.24.0.txt new file mode 100644 index 000000000..d1084be00 --- /dev/null +++ b/messages/1.24.0.txt @@ -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.