Skip to content

Commit

Permalink
Unregister language server extension on LS shutdown
Browse files Browse the repository at this point in the history
fix eclipse-lemminx#605

Signed-off-by: Andrew Obuchowicz <aobuchow@redhat.com>
  • Loading branch information
AObuchow committed Feb 6, 2020
1 parent e8dd978 commit 39908ec
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
import org.eclipse.lsp4xml.services.IXMLDocumentProvider;
import org.eclipse.lsp4xml.services.XMLLanguageService;
import org.eclipse.lsp4xml.settings.AllXMLSettings;
import org.eclipse.lsp4xml.settings.XMLCompletionSettings;
import org.eclipse.lsp4xml.settings.InitializationOptionsSettings;
import org.eclipse.lsp4xml.settings.LogsSettings;
import org.eclipse.lsp4xml.settings.ServerSettings;
import org.eclipse.lsp4xml.settings.SharedSettings;
import org.eclipse.lsp4xml.settings.XMLCodeLensSettings;
import org.eclipse.lsp4xml.settings.XMLCompletionSettings;
import org.eclipse.lsp4xml.settings.XMLFormattingOptions;
import org.eclipse.lsp4xml.settings.XMLGeneralClientSettings;
import org.eclipse.lsp4xml.settings.XMLSymbolSettings;
Expand Down Expand Up @@ -176,6 +176,7 @@ public synchronized void updateSettings(Object initializationOptionsSettings) {

@Override
public CompletableFuture<Object> shutdown() {
xmlLanguageService.dispose();
return computeAsync(cc -> new Object());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ public void initializeIfNeeded() {
}

private synchronized void initialize() {

if (initialized) {
return;
}
Expand Down Expand Up @@ -198,6 +198,16 @@ void unregisterExtension(IXMLExtension extension) {
extension.stop(this);
}

/**
* Unregisters all registered extensions.
*/
public void dispose() {
// Copy the list of extensions to avoid ConcurrentModificationError
List<IXMLExtension> extensionReferences = new ArrayList<>();
extensions.forEach(extensionReferences::add);
extensionReferences.forEach(this::unregisterExtension);
}

public void registerCompletionParticipant(ICompletionParticipant completionParticipant) {
completionParticipants.add(completionParticipant);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package org.eclipse.lsp4xml.services.extensions;

import static org.junit.Assert.assertTrue;

import org.eclipse.lsp4j.InitializeParams;
import org.eclipse.lsp4xml.services.extensions.save.ISaveContext;
import org.junit.Test;

public class ExtensionRegistryDisposeTest {

@Test
public void testExtensionRegistryDipose() {
XMLExtensionsRegistry registry = new XMLExtensionsRegistry();
registry.initializeIfNeeded();
MockXMLExtension extension = new MockXMLExtension();
registry.registerExtension(extension);
assertTrue(!extension.isStopped());
registry.dispose();
assertTrue(extension.isStopped());
assertTrue(registry.getExtensions().isEmpty());
}
}

class MockXMLExtension implements IXMLExtension {
boolean stopped;

@Override
public void start(InitializeParams params, XMLExtensionsRegistry registry) {
stopped = false;
}

@Override
public void stop(XMLExtensionsRegistry registry) {
stopped = true;
}

@Override
public void doSave(ISaveContext context) {
}

public boolean isStopped() {
return stopped;
}

}

0 comments on commit 39908ec

Please sign in to comment.