-
Notifications
You must be signed in to change notification settings - Fork 65
Adding Did Change Configuration feature #802
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| package org.eclipse.lsp4e; | ||
|
|
||
| import java.util.Collections; | ||
| import java.util.List; | ||
| import java.util.Map; | ||
|
|
||
| import org.eclipse.jdt.annotation.NonNull; | ||
| import org.eclipse.jface.preference.IPreferenceStore; | ||
| import org.eclipse.ui.plugin.AbstractUIPlugin; | ||
|
|
||
| /** | ||
| * Configuration handler that enables to send and update | ||
| * the configuration of the language server. | ||
| * It also contains a default implementation that can be instantiated. | ||
| */ | ||
| public interface IConfigurationHandler { | ||
|
|
||
| /** | ||
| * Returns a {@link Map} containing all preference names and their values. | ||
| * Usually used during the initialization of the language server to send | ||
| * all the configuration at once. | ||
| * @return | ||
| */ | ||
| @SuppressWarnings("null") | ||
| default @NonNull Map<String, Object> getConfiguration() { | ||
| return Collections.emptyMap(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a {@link Map} containing all preference names and their values. | ||
| * Used to send multiple configuration change to the language server at once. | ||
| * @return | ||
| */ | ||
| @SuppressWarnings("null") | ||
| default @NonNull Map<String, Object> getConfiguration(final List<String> prefList) { | ||
| return Collections.emptyMap(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns a {@link Map} containing the requested preference name and its value, | ||
| * usually used by a preference change listener. | ||
| * The Map will be converted to JSON by LSP4J before the transmission. | ||
| * @param preferenceName name of preference | ||
| * @return {@link Map} containing the requested preference name and its value | ||
| */ | ||
| @SuppressWarnings("null") | ||
| default @NonNull Map<String, Object> getConfiguration(final String prefName) { | ||
| return Collections.emptyMap(); | ||
| } | ||
|
|
||
| /** | ||
| * Returns the preference store containing the configuration of the language server. | ||
| * This must be overridden by the plugin developer, usually with the actual | ||
| * {@code Activator.getDefault().getPreferenceStore()} | ||
| * @see AbstractUIPlugin#getPreferenceStore() | ||
| * @return the preference store | ||
| */ | ||
| public @NonNull IPreferenceStore getPreferenceStore(); | ||
|
|
||
| /** | ||
| * Default implementation that can be instantiated | ||
| */ | ||
| final static class DefaultConfigurationHandler implements IConfigurationHandler { | ||
| public DefaultConfigurationHandler() { | ||
| // Do nothing | ||
| } | ||
|
|
||
| @SuppressWarnings("null") | ||
| @Override | ||
| public @NonNull IPreferenceStore getPreferenceStore() { | ||
| return LanguageServerPlugin.getDefault().getPreferenceStore(); | ||
| } | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -65,6 +65,8 @@ | |
| import org.eclipse.jdt.annotation.NonNull; | ||
| import org.eclipse.jdt.annotation.Nullable; | ||
| import org.eclipse.jface.text.IDocument; | ||
| import org.eclipse.jface.util.IPropertyChangeListener; | ||
| import org.eclipse.jface.util.PropertyChangeEvent; | ||
| import org.eclipse.lsp4e.LanguageServersRegistry.LanguageServerDefinition; | ||
| import org.eclipse.lsp4e.internal.FileBufferListenerAdapter; | ||
| import org.eclipse.lsp4e.internal.SupportedFeatures; | ||
|
|
@@ -74,6 +76,7 @@ | |
| import org.eclipse.lsp4j.ClientCapabilities; | ||
| import org.eclipse.lsp4j.ClientInfo; | ||
| import org.eclipse.lsp4j.CodeActionOptions; | ||
| import org.eclipse.lsp4j.DidChangeConfigurationParams; | ||
| import org.eclipse.lsp4j.DidChangeWorkspaceFoldersParams; | ||
| import org.eclipse.lsp4j.DocumentFormattingOptions; | ||
| import org.eclipse.lsp4j.DocumentRangeFormattingOptions; | ||
|
|
@@ -142,6 +145,15 @@ public void dirtyStateChanged(IFileBuffer buffer, boolean isDirty) { | |
|
|
||
| }; | ||
|
|
||
| private final IPropertyChangeListener propertyChangeListener = new IPropertyChangeListener() { | ||
| @Override | ||
| public void propertyChange(PropertyChangeEvent event) { | ||
| final IConfigurationHandler configHandler = serverDefinition.getConfigurationHandler(); | ||
| languageServer.getWorkspaceService().didChangeConfiguration( | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
| new DidChangeConfigurationParams(configHandler.getConfiguration(event.getProperty()))); | ||
| } | ||
| }; | ||
|
|
||
| @NonNull | ||
| public final LanguageServerDefinition serverDefinition; | ||
| @Nullable | ||
|
|
@@ -307,6 +319,11 @@ public synchronized void start() throws IOException { | |
| this.initiallySupportsWorkspaceFolders = supportsWorkspaceFolders(serverCapabilities); | ||
| }).thenRun(() -> { | ||
| this.languageServer.initialized(new InitializedParams()); | ||
| }).thenRun(() -> { | ||
| final IConfigurationHandler configHandler = serverDefinition.getConfigurationHandler(); | ||
| this.languageServer.getWorkspaceService().didChangeConfiguration( | ||
| new DidChangeConfigurationParams(configHandler.getConfiguration())); | ||
| configHandler.getPreferenceStore().addPropertyChangeListener(propertyChangeListener); | ||
| }).thenRun(() -> { | ||
| final Map<URI, IDocument> toReconnect = filesToReconnect; | ||
| initializeFuture.thenRunAsync(() -> { | ||
|
|
@@ -495,6 +512,8 @@ public synchronized void stop() { | |
| this.languageServer = null; | ||
|
|
||
| FileBuffers.getTextFileBufferManager().removeFileBufferListener(fileBufferListener); | ||
| this.serverDefinition.getConfigurationHandler() | ||
| .getPreferenceStore().removePropertyChangeListener(propertyChangeListener); | ||
| } | ||
|
|
||
| public @Nullable CompletableFuture<@NonNull LanguageServerWrapper> connect(IDocument document, @NonNull IFile file) | ||
|
|
||
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.
Some servers asks for concrete preference (for example vue language-server) in this case getConfiguration can be for example boolean
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.
Sorry I don't get this. What do you mean by "can be"? The return value or the parameter or what do you mean?