-
Notifications
You must be signed in to change notification settings - Fork 188
Refactor plugin API methods for applicable views #2713
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
base: main
Are you sure you want to change the base?
Conversation
|
Language servers can dynamically register features only to certain files using a DocumentSelector, which is a list of DocumentFilter, which in turn is a combination of language ID, scheme and glob pattern. We use that DocumentSelector to assing the server capabilities to the SessionBuffers, but the criterium which views the language server runs on is currently still limited to the The new @classmethod
def is_applicable(cls, view: sublime.View, config: ClientConfig) -> bool:
if (filename := view.file_name()) and os.path.basename(filename) == 'Project.toml':
return True
return super().is_applicable(view, config) |
Co-authored-by: Rafał Chłodnicki <rchl2k@gmail.com>
|
I haven't given it too much thought but would it make sense to also (or only) provide a way to statically define those conditions in settings (to match the current approach)? It might not be as flexible as API-based solution but it might be enough if one can specify equivalent of Something like: but without The advantage of that? A clear visibility of the conditions triggering the server. EDIT: Copilot wants to read ignore patterns from |
|
I think providing an API method that can only modify the static config would be a step backwards because then there wouldn't be any way to react to changes in configuration files when the server is already running. The We could think of adding something like the |
| if wm._new_session: | ||
| wm._sessions.add(wm._new_session) | ||
| listener.on_session_initialized_async(wm._new_session) | ||
| wm._new_session = None |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This part is pretty ugly, but the public WindowManager.start_async method is not actually sufficient to start a new session. That method sets an internal variable at
Line 280 in d5aefde
| self._new_session = session |
I won't touch the recursive
Line 154 in d5aefde
| def _dequeue_listener_async(self) -> None: |
Starting a new session when triggered from the lsp_check_applicable TextCommand seems to work correctly now though.
Combine
selectorandshould_ignoreplugin API methods into a newis_applicable.The previous methods are intended to still work with this PR, i.e. it should be backwards compatible (todo: still needs testing to verify).
This also adds a new TextCommand which can be used via
to retrigger the check for the given view and session. This is implemented as a command (instead of additional API method) to allow it to be called even if the session is not yet running (this needs it to be called e.g. from an independent listener implementation of course).
Closes #2503