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 8cee65c
Show file tree
Hide file tree
Showing 9 changed files with 163 additions and 92 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 @@ -15,6 +15,7 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.concurrent.CancellationException;
import java.util.concurrent.CompletableFuture;
Expand Down Expand Up @@ -73,6 +74,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 @@ -215,6 +217,11 @@ public CompletableFuture<List<? extends DocumentHighlight>> documentHighlight(Te
@Override
public CompletableFuture<List<Either<SymbolInformation, DocumentSymbol>>> documentSymbol(
DocumentSymbolParams params) {

if(!sharedSettings.symbolSettings.isEnabled()) {
return CompletableFuture.completedFuture(Collections.emptyList());
}

return computeAsync((monitor) -> {
TextDocument document = getDocument(params.getTextDocument().getUri());
DOMDocument xmlDocument = getXMLDocument(document);
Expand Down Expand Up @@ -431,6 +438,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 @@ -37,19 +37,14 @@ private ServerCapabilitiesInitializer() {
public static ServerCapabilities getNonDynamicServerCapabilities(ClientCapabilitiesWrapper clientCapabilities,
boolean isIncremental) {
ServerCapabilities serverCapabilities = new ServerCapabilities();

// @formatter:off
serverCapabilities.setTextDocumentSync(DEFAULT_SYNC_OPTION);

serverCapabilities
.setTextDocumentSync(isIncremental ? TextDocumentSyncKind.Incremental : TextDocumentSyncKind.Full);

serverCapabilities.setDocumentSymbolProvider(!clientCapabilities.isDocumentSymbolDynamicRegistered());
serverCapabilities.setTextDocumentSync(isIncremental ? TextDocumentSyncKind.Incremental : TextDocumentSyncKind.Full);
serverCapabilities.setDocumentSymbolProvider(!clientCapabilities.isDocumentSymbolDynamicRegistrationSupported());
serverCapabilities.setDocumentHighlightProvider(!clientCapabilities.isDocumentHighlightDynamicRegistered());
serverCapabilities.setCodeActionProvider(!clientCapabilities.isCodeActionDynamicRegistered());
serverCapabilities
.setDocumentFormattingProvider(!clientCapabilities.isFormattingDynamicRegistrationSupported());
serverCapabilities.setDocumentRangeFormattingProvider(
!clientCapabilities.isRangeFormattingDynamicRegistrationSupported());
serverCapabilities.setDocumentFormattingProvider(!clientCapabilities.isFormattingDynamicRegistrationSupported());
serverCapabilities.setDocumentRangeFormattingProvider(!clientCapabilities.isRangeFormattingDynamicRegistrationSupported());
serverCapabilities.setHoverProvider(!clientCapabilities.isHoverDynamicRegistered());
serverCapabilities.setRenameProvider(!clientCapabilities.isRenameDynamicRegistrationSupported());
serverCapabilities.setFoldingRangeProvider(!clientCapabilities.isRangeFoldingDynamicRegistrationSupported());
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 8cee65c

Please sign in to comment.