sublimelsp / LSP

Client implementation of the Language Server Protocol for Sublime Text
https://lsp.sublimetext.io/
MIT License
1.65k stars 181 forks source link

Disable language server for syntax test files by default #2504

Open jfcherng opened 3 months ago

jfcherng commented 3 months ago

TL;DR

By default, disable servers for

Description

I think enabling servers on syntax test files only cause (linting) issues. Only very few ones (e.g., LSP-copilot) will work well. By suggested rules, the name of a syntax test file starts with syntax_test_ (but in Default/run_syntax_tests.py, it finds filenames start with syntax_test).

The same reason for disabling for SublimeREPL views. See https://github.com/sublimelsp/LSP-pyright/issues/343 A SublimeREPL view has the view setting "repl": True,.

Suggestion

Something equivalent to

    @classmethod
    def should_ignore(cls, view: sublime.View) -> bool:
        return bool(
            # SublimeREPL views
            view.settings().get("repl")
            # syntax test files
            or os.path.basename(view.file_name() or "").startswith("syntax_test")
        )
jwortmann commented 1 week ago

I'm not sure whether view.settings().get("repl") would be a good approach; LSP currently registers new (non-file) views in on_activated_async. Dependent on how/when exactly SublimeREPL writes this setting, this approach might be prone to a race condition, i.e. whether this setting is set or read first.

In general, if we want to have this, I would probably prefer a more general setting name like for example lsp_ignore which would not be specific to SublimeREPL.

Edit: Probably a better approach would be for SublimeREPL to provide its own syntax definition with base scope e.g. source.python.repl, and then exclude this scope in Pyright etc. ("selector": "source.python - source.python.repl"). This way users could also easily configure their own syntax specific settings for REPL views.