Skip to content

Commit

Permalink
Move dynamic registration to initialized
Browse files Browse the repository at this point in the history
Moves the dynamic registration of the server capabilities
to initialized notification

fixes #601

Signed-off-by: Gorkem Ercan <[email protected]>
  • Loading branch information
gorkem committed Mar 26, 2018
1 parent 9331324 commit a3fb99c
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -164,9 +164,66 @@ public CompletableFuture<InitializeResult> initialize(InitializeParams params) {
*/
@Override
public void initialized(InitializedParams params) {
logInfo(">> initialized");
JobHelpers.waitForInitializeJobs();
if (preferenceManager.getClientPreferences().isWorkspaceSymbolDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.WORKSPACE_SYMBOL_ID, Preferences.WORKSPACE_SYMBOL);
}
if (preferenceManager.getClientPreferences().isDocumentSymbolDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.DOCUMENT_SYMBOL_ID, Preferences.DOCUMENT_SYMBOL);
}
if (preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.CODE_ACTION_ID, Preferences.CODE_ACTION);
}
if (preferenceManager.getClientPreferences().isDefinitionDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.DEFINITION_ID, Preferences.DEFINITION);
}
if (preferenceManager.getClientPreferences().isHoverDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.HOVER_ID, Preferences.HOVER);
}
if (preferenceManager.getClientPreferences().isReferencesDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.REFERENCES_ID, Preferences.REFERENCES);
}
if (preferenceManager.getClientPreferences().isDocumentHighlightDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.DOCUMENT_HIGHLIGHT_ID, Preferences.DOCUMENT_HIGHLIGHT);
}
if (preferenceManager.getClientPreferences().isWorkspaceFoldersSupported()) {
registerCapability(Preferences.WORKSPACE_CHANGE_FOLDERS_ID, Preferences.WORKSPACE_CHANGE_FOLDERS);
}
// we do not have the user setting initialized yet at this point but we should
// still call to enable defaults in case client does not support configuration changes
syncCapabilitiesToSettings();
try {
boolean autoBuildChanged = pm.setAutoBuilding(preferenceManager.getPreferences().isAutobuildEnabled());
buildWorkspace(autoBuildChanged);
} catch (CoreException e) {
JavaLanguageServerPlugin.logException(e.getMessage(), e);
}
}

/**
* Toggles the server capabilities according to user preferences.
*/
private void syncCapabilitiesToSettings() {
if (preferenceManager.getClientPreferences().isFormattingDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isJavaFormatEnabled(), Preferences.FORMATTING_ID, Preferences.TEXT_DOCUMENT_FORMATTING, null);
}
if (preferenceManager.getClientPreferences().isRangeFormattingDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isJavaFormatEnabled(), Preferences.FORMATTING_RANGE_ID, Preferences.TEXT_DOCUMENT_RANGE_FORMATTING, null);
}
if (preferenceManager.getClientPreferences().isCodeLensDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isCodeLensEnabled(), Preferences.CODE_LENS_ID, Preferences.TEXT_DOCUMENT_CODE_LENS, new CodeLensOptions(true));
}
if (preferenceManager.getClientPreferences().isSignatureHelpDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isSignatureHelpEnabled(), Preferences.SIGNATURE_HELP_ID, Preferences.TEXT_DOCUMENT_SIGNATURE_HELP, SignatureHelpHandler.createOptions());
}
if (preferenceManager.getClientPreferences().isRenameDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isRenameEnabled(), Preferences.RENAME_ID, Preferences.TEXT_DOCUMENT_RENAME, null);
}
if (preferenceManager.getClientPreferences().isExecuteCommandDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isExecuteCommandEnabled(), Preferences.EXECUTE_COMMAND_ID, Preferences.WORKSPACE_EXECUTE_COMMAND,
new ExecuteCommandOptions(new ArrayList<>(WorkspaceExecuteCommandHandler.getCommands())));
}
}

/* (non-Javadoc)
Expand Down Expand Up @@ -244,52 +301,7 @@ public void didChangeConfiguration(DidChangeConfigurationParams params) {
Preferences prefs = Preferences.createFrom((Map<String, Object>) settings);
preferenceManager.update(prefs);
}
JobHelpers.waitForInitializeJobs();
if (preferenceManager.getClientPreferences().isWorkspaceSymbolDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.WORKSPACE_SYMBOL_ID, Preferences.WORKSPACE_SYMBOL);
}
if (preferenceManager.getClientPreferences().isDocumentSymbolDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.DOCUMENT_SYMBOL_ID, Preferences.DOCUMENT_SYMBOL);
}
if (preferenceManager.getClientPreferences().isCodeActionDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.CODE_ACTION_ID, Preferences.CODE_ACTION);
}
if (preferenceManager.getClientPreferences().isDefinitionDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.DEFINITION_ID, Preferences.DEFINITION);
}
if (preferenceManager.getClientPreferences().isHoverDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.HOVER_ID, Preferences.HOVER);
}
if (preferenceManager.getClientPreferences().isReferencesDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.REFERENCES_ID, Preferences.REFERENCES);
}
if (preferenceManager.getClientPreferences().isDocumentHighlightDynamicRegistered()) {
JavaLanguageServerPlugin.getInstance().registerCapability(Preferences.DOCUMENT_HIGHLIGHT_ID, Preferences.DOCUMENT_HIGHLIGHT);
}
if (preferenceManager.getClientPreferences().isFormattingDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isJavaFormatEnabled(), Preferences.FORMATTING_ID, Preferences.TEXT_DOCUMENT_FORMATTING, null);
}
if (preferenceManager.getClientPreferences().isRangeFormattingDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isJavaFormatEnabled(), Preferences.FORMATTING_RANGE_ID, Preferences.TEXT_DOCUMENT_RANGE_FORMATTING, null);
}
if (preferenceManager.getClientPreferences().isCodeLensDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isCodeLensEnabled(), Preferences.CODE_LENS_ID, Preferences.TEXT_DOCUMENT_CODE_LENS, new CodeLensOptions(true));
}
if (preferenceManager.getClientPreferences().isSignatureHelpDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isSignatureHelpEnabled(), Preferences.SIGNATURE_HELP_ID, Preferences.TEXT_DOCUMENT_SIGNATURE_HELP, SignatureHelpHandler.createOptions());
}
if (preferenceManager.getClientPreferences().isRenameDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isRenameEnabled(), Preferences.RENAME_ID, Preferences.TEXT_DOCUMENT_RENAME, null);
if (preferenceManager.getPreferences().isRenameEnabled()) {
registerCapability(Preferences.RENAME_ID, Preferences.TEXT_DOCUMENT_RENAME);
} else {
unregisterCapability(Preferences.RENAME_ID, Preferences.TEXT_DOCUMENT_RENAME);
}
}
if (preferenceManager.getClientPreferences().isExecuteCommandDynamicRegistrationSupported()) {
toggleCapability(preferenceManager.getPreferences().isExecuteCommandEnabled(), Preferences.EXECUTE_COMMAND_ID, Preferences.WORKSPACE_EXECUTE_COMMAND,
new ExecuteCommandOptions(new ArrayList<>(WorkspaceExecuteCommandHandler.getCommands())));
}
syncCapabilitiesToSettings();
boolean jvmChanged = false;
try {
jvmChanged = configureVM();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,13 +50,13 @@
import org.eclipse.jdt.ls.core.internal.preferences.Preferences;
import org.eclipse.lsp4j.ClientCapabilities;
import org.eclipse.lsp4j.DidChangeConfigurationCapabilities;
import org.eclipse.lsp4j.DidChangeConfigurationParams;
import org.eclipse.lsp4j.DidChangeWatchedFilesParams;
import org.eclipse.lsp4j.ExecuteCommandCapabilities;
import org.eclipse.lsp4j.FileChangeType;
import org.eclipse.lsp4j.FileEvent;
import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4j.InitializeResult;
import org.eclipse.lsp4j.InitializedParams;
import org.eclipse.lsp4j.SynchronizationCapabilities;
import org.eclipse.lsp4j.TextDocumentClientCapabilities;
import org.eclipse.lsp4j.TextDocumentSyncKind;
Expand Down Expand Up @@ -149,8 +149,7 @@ public void testRegisterDelayedCapability() throws Exception {
when(mockCapabilies.isDocumentHighlightDynamicRegistered()).thenReturn(Boolean.TRUE);
InitializeResult result = initialize(true);
assertNull(result.getCapabilities().getDocumentSymbolProvider());
DidChangeConfigurationParams params = new DidChangeConfigurationParams();
server.didChangeConfiguration(params);
server.initialized(new InitializedParams());
verify(client, times(7)).registerCapability(any());
}

Expand Down

0 comments on commit a3fb99c

Please sign in to comment.