Skip to content

Commit

Permalink
Preference to turn off document symbols
Browse files Browse the repository at this point in the history
Fixes eclipse-lemminx#413

Signed-off-by: Nikolas Komonen <[email protected]>
  • Loading branch information
NikolasKomonen committed Jun 4, 2019
1 parent f58872a commit 946ef8e
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 83 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
import org.eclipse.lsp4xml.settings.XMLExperimentalCapabilities;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.settings.XMLGeneralClientSettings;
import org.eclipse.lsp4xml.settings.XMLSymbolSettings;
import org.eclipse.lsp4xml.settings.capabilities.ServerCapabilitiesInitializer;
import org.eclipse.lsp4xml.settings.capabilities.XMLCapabilityManager;
import org.eclipse.lsp4xml.utils.FilesUtils;
Expand Down Expand Up @@ -139,6 +140,11 @@ public void updateSettings(Object initializationOptionsSettings) {
xmlTextDocumentService.updateCompletionSettings(newCompletions);
}

XMLSymbolSettings newSymbols = xmlClientSettings.getSymbols();
if(newSymbols != null) {
xmlTextDocumentService.updateSymbolSettings(newSymbols);
}

ServerSettings serverSettings = xmlClientSettings.getServer();
if(serverSettings != null) {
String workDir = serverSettings.getNormalizedWorkDir();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@
import org.eclipse.lsp4xml.services.extensions.save.AbstractSaveContext;
import org.eclipse.lsp4xml.settings.SharedSettings;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.settings.XMLSymbolSettings;

/**
* XML text document service.
Expand Down Expand Up @@ -431,6 +432,14 @@ public void updateCompletionSettings(CompletionSettings newCompletion) {
sharedSettings.completionSettings.setAutoCloseTags(newCompletion.isAutoCloseTags());
}

public void updateSymbolSettings(XMLSymbolSettings newSettings) {
sharedSettings.symbolSettings.setEnabled(newSettings.isEnabled());
}

public XMLSymbolSettings getSharedSymbolSettings() {
return sharedSettings.symbolSettings;
}

public boolean isIncrementalSupport() {
return documents.isIncremental();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,14 @@ public class SharedSettings {
public final FoldingRangeCapabilities foldingSettings;
public XMLFormattingOptions formattingSettings;
public final XMLValidationSettings validationSettings;
public final XMLSymbolSettings symbolSettings;

public SharedSettings() {
this.completionSettings = new CompletionSettings();
this.foldingSettings = new FoldingRangeCapabilities();
this.formattingSettings = new XMLFormattingOptions(true);
this.validationSettings = new XMLValidationSettings();
this.symbolSettings = new XMLSymbolSettings();
}

public void setFormattingSettings(XMLFormattingOptions formattingOptions) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,10 +44,20 @@ public class XMLGeneralClientSettings {

private ServerSettings server;

private XMLSymbolSettings symbols;

public void setLogs(LogsSettings logs) {
this.logs = logs;
}

public XMLSymbolSettings getSymbols() {
return symbols;
}

public void setSymbols(XMLSymbolSettings symbols) {
this.symbols = symbols;
}

public LogsSettings getLogs() {
return logs;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*******************************************************************************
* Copyright (c) 2019 Red Hat Inc. and others.
* All rights reserved. This program and the accompanying materials
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v20.html
*
* Contributors:
* Red Hat Inc. - initial API and implementation
*******************************************************************************/

package org.eclipse.lsp4xml.settings;

/**
* XMLSymbolPreferences for Document Symbols
*/
public class XMLSymbolSettings {

private boolean enabled = true;

public boolean isEnabled() {
return enabled;
}

public void setEnabled(boolean enabled) {
this.enabled = enabled;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public boolean isRenameDynamicRegistrationSupported() {
return v3Supported && isDynamicRegistrationSupported(getTextDocument().getRename());
}

public boolean isDocumentSymbolDynamicRegistered() {
public boolean isDocumentSymbolDynamicRegistrationSupported() {
return v3Supported && isDynamicRegistrationSupported(getTextDocument().getDocumentSymbol());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public static ServerCapabilities getNonDynamicServerCapabilities(ClientCapabilit
serverCapabilities
.setTextDocumentSync(isIncremental ? TextDocumentSyncKind.Incremental : TextDocumentSyncKind.Full);

serverCapabilities.setDocumentSymbolProvider(!clientCapabilities.isDocumentSymbolDynamicRegistered());
serverCapabilities.setDocumentSymbolProvider(!clientCapabilities.isDocumentSymbolDynamicRegistrationSupported());
serverCapabilities.setDocumentHighlightProvider(!clientCapabilities.isDocumentHighlightDynamicRegistered());
serverCapabilities.setCodeActionProvider(!clientCapabilities.isCodeActionDynamicRegistered());
serverCapabilities
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@
import org.eclipse.lsp4j.services.LanguageClient;
import org.eclipse.lsp4xml.XMLTextDocumentService;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.settings.XMLSymbolSettings;

/**
* Manager for capability related tasks
Expand Down Expand Up @@ -125,9 +126,6 @@ public void initializeCapabilities() {
if (this.getClientCapabilities().isDocumentHighlightDynamicRegistered()) {
registerCapability(DOCUMENT_HIGHLIGHT_ID, TEXT_DOCUMENT_HIGHLIGHT);
}
if (this.getClientCapabilities().isDocumentSymbolDynamicRegistered()) {
registerCapability(DOCUMENT_SYMBOL_ID, TEXT_DOCUMENT_DOCUMENT_SYMBOL);
}
if (this.getClientCapabilities().isRangeFoldingDynamicRegistrationSupported()) {
registerCapability(FOLDING_RANGE_ID, TEXT_DOCUMENT_FOLDING_RANGE);
}
Expand Down Expand Up @@ -165,6 +163,13 @@ public void syncDynamicCapabilitiesWithPreferences() {
toggleCapability(formattingPreferences.isEnabled(), FORMATTING_RANGE_ID,
ServerCapabilitiesConstants.TEXT_DOCUMENT_RANGE_FORMATTING, null);
}

XMLSymbolSettings symbolSettings = this.textDocumentService.getSharedSymbolSettings();

if (this.getClientCapabilities().isDocumentSymbolDynamicRegistrationSupported()) {
toggleCapability(symbolSettings.isEnabled(), DOCUMENT_SYMBOL_ID,
TEXT_DOCUMENT_DOCUMENT_SYMBOL, null);
}
}

public Set<String> getRegisteredCapabilities() {
Expand Down
Loading

0 comments on commit 946ef8e

Please sign in to comment.