-
-
Notifications
You must be signed in to change notification settings - Fork 106
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
Documentation update about dynamic features #376
Comments
I finally managed to make it work with this code: @server.feature(INITIALIZED)
def init(ls, params):
ls.register_capability(RegistrationParams(
registrations = [
Registration(
id = str(uuid.uuid4()),
method = WORKSPACE_DID_CHANGE_WATCHED_FILES,
register_options = DidChangeWatchedFilesRegistrationOptions(watchers = [
FileSystemWatcher(glob_pattern = "**", kind = WatchKind.Create | WatchKind.Change | WatchKind.Delete)
])
)
]
)) It could maybe be nice to indicate how we should register about dynamic features in the documentation. As you can see, I expected dynamic registration to be done this way too, as nothing (or I miss it) indicates it. I think it's quite an interesting addition, as Microsoft is now saying that registering to WORKSPACE_DID_CHANGE_WATCHED_FILES is now a good practice (before no registration was needed). see https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeWatchedFiles (especially: "It is recommended that servers register for these file system events using the registration mechanism. In former implementations clients pushed file events without the server actively asking for it.") |
Glad to hear it! I'll admit I'm not that familiar with this part of the spec, is this a more generic version of the
I agree! I'm kind of surprised we didn't have that already 😅 |
This is not really a subset but it is events that are coming from different sources. To give you an example, I wanted to use this event to detect that git has changed the content of the workspace. However this is the first dynamic feature I register and I don't know if the "INITIALIZED" feature is the best place to do it, but it seems to work |
Ah that makes sense - thanks!
Well, you've officially registered more dynamic features than I have! It's not an area of LSP/pygls I've had much reason to look into yet.
|
Thanks for bringing this up. Like @alcarney I'm not very familiar with this area either. We could add a note on the docs page? The interesting thing about the https://pygls.readthedocs.io/en/latest/pages/advanced_usage.html#built-in-features |
I don't really know what you want to be built-in with this feature, because it does not really do something. This is only an event that indicates that a file changed and give the uri, but not the content not anything else. however I think it could maybe be interesting to check more generaly what can be done about dynamic features and the way they are registered. At first when I discovered pygls, I understood that as soon as you put a decorator |
To continue on this subject, I just found this section: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_configuration Now you do not receive any 'DidChangeConfiguration' notification anymore, except if you dynamically register for it. @server.feature(INITIALIZED)
@send_error_on_traceback
def init(ls, params):
server.register_capability(RegistrationParams(
registrations = [
Registration(
id = str(uuid.uuid4()),
method = WORKSPACE_DID_CHANGE_WATCHED_FILES,
register_options = DidChangeWatchedFilesRegistrationOptions(watchers = [
FileSystemWatcher(glob_pattern = "**", kind = WatchKind.Create | WatchKind.Change | WatchKind.Delete)
])
),
Registration(
id = str(uuid.uuid4()),
method = WORKSPACE_DID_CHANGE_CONFIGURATION,
register_options = DidChangeConfigurationRegistrationOptions(
section = "???"
)
),
]
)) However as the documentation says, to register you have to register to 'undefined'. The 'DidChangeConfigurationRegistrationOptions' is then useless, and after experimentation, is even not working if used. Registration(
id = str(uuid.uuid4()),
method = WORKSPACE_DID_CHANGE_CONFIGURATION
), On the feature, the parameter is not filled anymore, you have to pull the the configuration now. @server.feature(WORKSPACE_DID_CHANGE_CONFIGURATION)
def did_change_configuration(server, params: DidChangeConfigurationParams):
#params is None, you have to do server.get_configuration
pass The weird thing here is that params is None, but if you don't put it in the signature the feature does not work at all. |
I'm finding this thread very thought provoking! Rereading the spec, there's a chance even pygls' static registration is currently too restrictive 🤔. - Does anyone know of a server that statically registers lsp methods with a
It would certainly be possible for I suspect though that servers calling I don't have much to add on the
It might seem odd, but for requests like shutdown require an explicit |
Hello !
I'm trying to use the WORKSPACE_DID_CHANGE_WATCHED_FILES notification. But I can't pass a DidChangeWatchedFilesRegistrationOptions on the decorator.
I already succeeded to pass a RegistrationOption for the RENAME_FILES event, like this:
But if I try to pass a registrationOptions for WORKSPACE_DID_CHANGE_WATCHED_FILES, it crashes:
With this code I get a "MethodTypeNotRegisteredError". From what I see from the code, it seems to try to find a DidChangeWatchedFilesOptions class, which doesn't exist.
Am I doing something wrong or is there an issue with this option?
The text was updated successfully, but these errors were encountered: