Skip to content

Always request workspace diagnostics if supported by server - #2827

Merged
jwortmann merged 6 commits into
sublimelsp:mainfrom
jwortmann:workspace-diagnostics
Apr 22, 2026
Merged

jwortmann merged 6 commits into
sublimelsp:mainfrom
jwortmann:workspace-diagnostics

Conversation

@jwortmann

@jwortmann jwortmann commented Mar 24, 2026 •

Copy link
Copy Markdown
Member

Always request workspace diagnostics, independently of the "diagnostics_mode" setting.

If we want to do this change, the code at

def _on_before_destroy(self, view: sublime.View) -> None:
self.remove_all_inlay_hints()
if self.has_capability("diagnosticProvider") and self.session.config.diagnostics_mode == "open_files":
self.session.on_text_document_publish_diagnostics({'uri': self._last_known_uri, 'diagnostics': []})

probably doesn't make sense anymore in that form. But also I think we can't just clear diagnostics unconditionally on closing a file, because that would forfeit the purpose of workspace diagnostics (to have diagnostics for unopened files). So we might need to consider how to handle the problem 2. from #2727 (comment). Maybe another check whether the file is outside of the workspace folders would do.

@netlify

netlify Bot commented Mar 24, 2026 •

Copy link
Copy Markdown

βœ… Deploy Preview for sublime-lsp ready!

Name Link
πŸ”¨ Latest commit 698939a
πŸ” Latest deploy log https://app.netlify.com/projects/sublime-lsp/deploys/69e8cf3551bebe000803fad2
😎 Deploy Preview https://deploy-preview-2827--sublime-lsp.netlify.app
πŸ“± Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@jwortmann
jwortmann marked this pull request as ready for review April 19, 2026 15:20
@jwortmann

jwortmann commented Apr 19, 2026 •

Copy link
Copy Markdown
Member Author

Pull diagnostics are cleared now for files outside of the workspace folders (or for all files if there are no workspace folders), when the file gets closed. I think that should be the expected behavior.

I noticed that the current code with self.has_capability("diagnosticProvider") doesn't work anyway, because that always returns False since the pull diagnostics with multiple providers were fixed (because there is special handling for diagnostic provider registration).

And the diagnostics_mode config setting is now basically reverted to the predecessor setting hide_non_project_diagnostics. Not sure if we also want to revert back to the old name, or leave it like that. But it's probably rarely used anyway.

Comment thread docs/src/client_configuration.md Outdated
| initialization_options | options to send to the server at startup |
| 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 "priority_selector" to `text.html` for HTML server and `source.php` to PHP server.
| diagnostics_mode | Set to `"workspace"` (default is `"open_files"`) 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. If the server supports _pull diagnostics_ (`diagnosticProvider`), this setting also controls whether diagnostics are requested only for open files (`"open_files"`), or for all files in the project folders (`"workspace"`). |
| diagnostics_mode | Set to `"workspace"` (default is `"open_files"`) 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. |

@rchl rchl Apr 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I have some issue with this configuration's name and values.

"open_files" - All diagnostics reported from the server are shown.
"workspace" - If there are project folders (folders in the side bar),
    diagnostics for files not within those folders are ignored.

"open_files" seem to lost its meaning. It doesn't have to do anything with open files - server might return diagnostics for the whole workspace or just open files.

"workspace" description seems fine but the name of it is not very descriptive (for example could be called "limited_to_workspace" instead).

If we are OK with just completely changing naming around and break backwards compatibility then we could probably come up with better naming. Are we OK with that?

For what it's worth, no servers seem to use it in their default settings.
Of course people might be using it already and would be affected but probably not that many and if it breaks for them nothing really bad will happen. People might just notice and figure out how to fix it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we shouldn't just remove this config alltogether, and simply decide for one of the two behaviors, and without it being configurable. I wonder how other editors behave and if the have a config option for this (I assume they don't).

Or we could make it a user setting, because this is not really something specific to the server, but just personal preference. So I'd say it doesn't really make sense to have this as a server-specific config.

@rchl rchl Apr 20, 2026 •

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would be fine with user setting that defaults to ignoring diagnostics outside of workspace.

I suppose the setting should then be a hide_non_project_diagnostics boolean like before (or some variation of it).

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we want to keep it as part of the server config, we could probably just rename "open_files" to anything else, because that is currently the default value. And that option isn't even referenced anywhere in the source code. The only place left where diagnostics_mode is checked is in

LSP/plugin/core/windows.py

Lines 369 to 374 in 72796d3

def should_ignore_diagnostics(self, uri: DocumentUri, configuration: ClientConfig) -> str | None:
scheme, path = parse_uri(uri)
if scheme != "file":
return None
if configuration.diagnostics_mode == "workspace" and not self._workspace.contains(path):
return "not inside window folders"


Another question is what to do about code actions with files outside of the workspace folders, if someone has "diagnostics_mode": "workspace" configured. Because currently, we completely ignore the diagnostics (instead of just not drawing them in the view):

For pull diagnostics, no request is made:

def do_document_diagnostic_async(self, view: sublime.View, version: int, *, forced_update: bool = False) -> None:
mgr = self.session.manager()
if not mgr or mgr.should_ignore_diagnostics(self._last_known_uri, self.session.config):
return

For publishDiagnostics:

LSP/plugin/core/sessions.py

Lines 1911 to 1914 in 72796d3

reason = mgr.should_ignore_diagnostics(uri, self.config)
if isinstance(reason, str):
debug("ignoring unsuitable diagnostics for", uri, "reason:", reason)
return

So it's probably useless to automatically request code actions (for current caret position) for such views.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Another question is what to do about code actions with files outside of the workspace folders

your suggestion makes sense to me

@jwortmann jwortmann Apr 22, 2026 •

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah but I realized that we actually don't request code actions if there aren't any diagnostics (e.g. if ignored due to outside of workspace folders if configured like that). I have added that logic recently when refactoring the code actions. So it should be fine already.

Perhaps it could be optimized to return early from the function when the file is outside of workspace folders. But that's probably not so important.

@jwortmann
jwortmann merged commit 50fa4b4 into sublimelsp:main Apr 22, 2026
8 checks passed
@jwortmann
jwortmann deleted the workspace-diagnostics branch April 22, 2026 17:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants