Skip to content

Commit

Permalink
Tested and Enabled incremental document syncing.
Browse files Browse the repository at this point in the history
Fixes eclipse-lemminx#133

Removed the incremental setting, it is default and you can't change it

Signed-off-by: Nikolas <nikolaskomonen@gmail.com>
  • Loading branch information
NikolasKomonen committed Jun 11, 2019
1 parent 867aae2 commit 1e8f987
Show file tree
Hide file tree
Showing 10 changed files with 274 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import org.eclipse.lsp4xml.settings.LogsSettings;
import org.eclipse.lsp4xml.settings.ServerSettings;
import org.eclipse.lsp4xml.settings.SharedSettings;
import org.eclipse.lsp4xml.settings.XMLExperimentalCapabilities;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.settings.XMLGeneralClientSettings;
import org.eclipse.lsp4xml.settings.XMLSymbolSettings;
Expand Down Expand Up @@ -116,7 +115,7 @@ public void initialized(InitializedParams params) {
*
* @param initializationOptionsSettings the XML settings
*/
public void updateSettings(Object initializationOptionsSettings) {
public synchronized void updateSettings(Object initializationOptionsSettings) {
if (initializationOptionsSettings == null) {
return;
}
Expand Down Expand Up @@ -150,15 +149,6 @@ public void updateSettings(Object initializationOptionsSettings) {
String workDir = serverSettings.getNormalizedWorkDir();
FilesUtils.setCachePathSetting(workDir);
}

// Experimental capabilities
XMLExperimentalCapabilities experimental = xmlClientSettings.getExperimental();
if (experimental != null) {
boolean incrementalSupport = experimental.getIncrementalSupport() != null
&& experimental.getIncrementalSupport().getEnabled() != null
&& experimental.getIncrementalSupport().getEnabled().booleanValue();
xmlTextDocumentService.setIncrementalSupport(incrementalSupport);
}
}
ContentModelSettings cmSettings = ContentModelSettings.getContentModelXMLSettings(initializationOptionsSettings);
if(cmSettings != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ private XMLLanguageService getXMLLanguageService() {
}

public void updateCompletionSettings(CompletionSettings newCompletion) {
sharedSettings.completionSettings.setAutoCloseTags(newCompletion.isAutoCloseTags());
sharedSettings.setCompletionSettings(newCompletion);
}

public void updateSymbolSettings(XMLSymbolSettings newSettings) {
Expand All @@ -454,10 +454,6 @@ public XMLFormattingOptions getSharedFormattingSettings() {
return sharedSettings.formattingSettings;
}

public void setIncrementalSupport(boolean incrementalSupport) {
this.documents.setIncremental(incrementalSupport);
}

public XMLValidationSettings getValidationSettings() {

return sharedSettings.validationSettings;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,8 @@ public void update(List<TextDocumentContentChangeEvent> changes) {
try {
synchronized (buffer) {
for (TextDocumentContentChangeEvent changeEvent : changes) {
ListLineTracker lt = new ListLineTracker();
lt.set(buffer.toString());

Range range = changeEvent.getRange();
int length = 0;
Expand All @@ -147,17 +149,17 @@ public void update(List<TextDocumentContentChangeEvent> changes) {
length = changeEvent.getRangeLength().intValue();
} else {
// range is optional and if not given, the whole file content is replaced
length = getText().length();
range = new Range(positionAt(0), positionAt(length));
length = buffer.toString().length();
range = new Range(lt.getPositionAt(0), lt.getPositionAt(length));
}
String text = changeEvent.getText();
int startOffset = offsetAt(range.getStart());
int startOffset = lt.getOffsetAt(range.getStart());
buffer.replace(startOffset, startOffset + length, text);
}
setText(buffer.toString());
}
} catch (BadLocationException e) {
// Should never occurs.
// Should never occur.
}
} else {
// like vscode does, get the last changes
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,21 +26,13 @@
*/
public class TextDocuments implements ITextDocumentFactory {

private boolean incremental;
private final boolean incremental;

private final Map<String, TextDocument> documents;

public TextDocuments() {
documents = new HashMap<>();
}

/**
* Set the incremental support.
*
* @param incremental
*/
public void setIncremental(boolean incremental) {
this.incremental = incremental;
incremental = true; // Quick fix to set incremental
documents.values().forEach(document -> document.setIncremental(incremental));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,15 +14,15 @@
* XML experimental capabilities.
*
*/
public class XMLExperimentalCapabilities {
public class XMLExperimentalSettings {

private XMLIncrementalSupportCapabilities incrementalSupport;
private XMLIncrementalSupportSettings incrementalSupport;

public void setIncrementalSupport(XMLIncrementalSupportCapabilities incrementalSupport) {
public void setIncrementalSupport(XMLIncrementalSupportSettings incrementalSupport) {
this.incrementalSupport = incrementalSupport;
}

public XMLIncrementalSupportCapabilities getIncrementalSupport() {
public XMLIncrementalSupportSettings getIncrementalSupport() {
return incrementalSupport;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ public class XMLGeneralClientSettings {
private LogsSettings logs;

private XMLFormattingOptions format;

private XMLExperimentalCapabilities experimental;

private CompletionSettings completion;

Expand Down Expand Up @@ -69,10 +67,6 @@ public void setFormat(XMLFormattingOptions format) {
public XMLFormattingOptions getFormat() {
return format;
}

public XMLExperimentalCapabilities getExperimental() {
return experimental;
}

/**
* Set completion settings
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@
* XML experimental incremental support capabilities.
*
*/
public class XMLIncrementalSupportCapabilities {
public class XMLIncrementalSupportSettings {

private Boolean enabled;

public Boolean getEnabled() {
if(enabled == null) {
enabled = true; // default on
}
return enabled;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@

import static org.eclipse.lsp4xml.settings.capabilities.ServerCapabilitiesConstants.DEFAULT_COMPLETION_OPTIONS;
import static org.eclipse.lsp4xml.settings.capabilities.ServerCapabilitiesConstants.DEFAULT_LINK_OPTIONS;
import static org.eclipse.lsp4xml.settings.capabilities.ServerCapabilitiesConstants.DEFAULT_SYNC_OPTION;

import org.eclipse.lsp4j.ServerCapabilities;
import org.eclipse.lsp4j.TextDocumentSyncKind;
Expand All @@ -37,9 +36,9 @@ 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.isDocumentSymbolDynamicRegistrationSupported());
serverCapabilities.setDocumentHighlightProvider(!clientCapabilities.isDocumentHighlightDynamicRegistered());
serverCapabilities.setCodeActionProvider(!clientCapabilities.isCodeActionDynamicRegistered());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,10 @@ public void initializeCapabilities() {
}

/**
* Registers all capabilities that this server can support client side
* preferences to turn on/off
* Registers(indicates the servers ability to support the service) all capabilities that have the ability to be turned
* on/off on the client side through preferences.
*
* In the case the preference is set to off/false this server will tell the cliet it does not support this capability.
*
* If a capability is not dynamic, it's handled by
* {@link ServerCapabilitiesInitializer}
Expand Down
Loading

0 comments on commit 1e8f987

Please sign in to comment.