Skip to content
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

Adding Did Change Configuration feature #802

Closed
wants to merge 1 commit into from

Conversation

ppank5
Copy link

@ppank5 ppank5 commented Sep 13, 2023

The intention of this PR is adding the Did Change Configuration feature of the LSP. The initial/last configuration is sent after the initialized notification message is received, similarly to VS Code. Then each preference store change triggers a didChangeConfiguration message to the server. This behavior provides that the language server acquires a meaningful configuration before starting analyzing any file/workspace/project coming from the LSP4E client.
The plugin developers can add their own implementation via a new extension point called configurationHandler and by implementing the IConfigurationHandler interface. This interface comes with a default implementation that basically sends empty messages that can be easily neglected by the language server.
I think the idea is understandable from the code, I tried to add meaningful comments as well, however, feedbacks are welcome.

Signed-off-by: Adam Knapp <adam.knapp@ericsson.com>
* @return {@link Map} containing the requested preference name and its value
*/
@SuppressWarnings("null")
default @NonNull Map<String, Object> getConfiguration(final String prefName) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Some servers asks for concrete preference (for example vue language-server) in this case getConfiguration can be for example boolean

Copy link
Author

Choose a reason for hiding this comment

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

Sorry I don't get this. What do you mean by "can be"? The return value or the parameter or what do you mean?

@Override
public void propertyChange(PropertyChangeEvent event) {
final IConfigurationHandler configHandler = serverDefinition.getConfigurationHandler();
languageServer.getWorkspaceService().didChangeConfiguration(
Copy link
Contributor

Choose a reason for hiding this comment

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

How about configuration sharing? For example HTML LS can ask for CSS or JAVASCRIPT settings or just workspace settings (http)

Copy link
Author

Choose a reason for hiding this comment

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

I think any LS can ask for any section, however the LS is not aware of what configuration sections are available in/at the client. So by default the configuration is shared, just need to ask the client properly.

@angelozerr
Copy link
Contributor

@ppank5
Copy link
Author

ppank5 commented Sep 19, 2023

Please note that WWD manages HTML, CSS, JS settings https://github.com/eclipse-wildwebdeveloper/wildwebdeveloper/blob/bd4d90213bee415549706c875dbe3ce348e26bda/org.eclipse.wildwebdeveloper/src/org/eclipse/wildwebdeveloper/html/HTMLLanguageClient.java#L42

I wonder if this PR will simplify the code of WWD.

Based on the code you linked, the WWD LS has to ask for the configuration in every case. Contrarily, the didChangeConfiguration message is a notification about the change of the settings. The former mechanism is not influenced by the latter one. So the LS can have both if the developers like. In our case, the user can have such preferences that influence the code analysis at the server side. So we needed the configuration of the client asap, preferably before starting the analysis. Therefore, we "copied" the VSCode behavior by sending the whole client configuration right after the initialization messages.
Regarding the WWD LS, I think the developers can experiment a bit with this idea. As I see a conversion is needed between Settings and Map<String, Object>, basically everything else is just boilerplate code.

@mickaelistria
Copy link
Contributor

I'm a bit unsure about this one as there are many many things that could trigger a configuration change, and I'm unsure about whether 1 API could successfully encompass all cases. For example. a configuration can be derived from one or more preference store, with or without translation of preference ids, or can be derived from a configuration file, or can be triggered by some custom menu action, or even by a codeAction that would trigger a client side action...
In such case, it's relatively easy to place the right listener already where it fits best (and LSP4E cannot do much to know "where it fits best"), and then to call LanguageServers.forDocument().withPreferredServerId(lsID).execute(ls -> ls.didChangeConfiguration(...)).
Unless I'm mistaken, I think the missing brick is more a way to store the current configuration for a language server instance. But I don't think a new API is necessary for it, it could maybe be just a field in the LanguageServerWrapper ?

@zulus
Copy link
Contributor

zulus commented Sep 19, 2023

I'm thinking about something different for eclipse-wildwebdeveloper/wildwebdeveloper#1335

  1. Additional extension point to collect prefixes (sections) and IConfigurationProvider that can deliver entire tree/map or single value, how it will be stored, we don't care
  2. Separate alias mapping (can be in xml directly in same extension point)
  3. Basic implementation for IConfigurationProvider that store in IEclipsePreference (PreferenceStore) (boolean, numbers, string) values directly, and do json serialize/deserialize for others
  4. Default implementation for "workspace/configuration" that use data from IConfigurationProvider's for LS that prefer PULL's. I read somewhere that is a trend now ;)
  5. Helpers for LS that prefer settings in PUSH mode : initializationOptions or after initialize + watchers

@zulus
Copy link
Contributor

zulus commented Oct 3, 2023

See my proposition: #835 and example implementation for wildwebdeveloper ;)

@eclipsewebmaster eclipsewebmaster deleted the branch eclipse:master May 21, 2024 14:09
@mickaelistria
Copy link
Contributor

The initial target branch master was deleted and replaced by main, so this PR got closed automatically. If this is still relevant, please re-create this PR targetting the main branch.

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.

None yet

5 participants