From ce526f890b6972f68082b862f3cb4584cf475a2d Mon Sep 17 00:00:00 2001 From: azerr Date: Tue, 7 Dec 2021 11:52:39 +0100 Subject: [PATCH] Shutdown raises exception Fixes #1132 Signed-off-by: azerr --- .../eclipse/lemminx/XMLLanguageServer.java | 22 +- .../ClientCapabilitiesWrapper.java | 21 +- .../XMLSchemaCompletionExtensionsTest.java | 148 +- .../XMLSchemaDiagnosticsTest.java | 32 +- ...TypeDefinitionWithCacheExtensionsTest.java | 6 +- .../src/test/resources/xsd/maven-4.0.0.xsd | 2213 +++++++++-------- 6 files changed, 1291 insertions(+), 1151 deletions(-) diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLLanguageServer.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLLanguageServer.java index 9c3d3ba77..5cdf6c9ca 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLLanguageServer.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/XMLLanguageServer.java @@ -75,8 +75,7 @@ * XML language server. * */ -public class XMLLanguageServer - implements ProcessLanguageServer, XMLLanguageServerAPI, IXMLDocumentProvider, +public class XMLLanguageServer implements ProcessLanguageServer, XMLLanguageServerAPI, IXMLDocumentProvider, IXMLNotificationService, IXMLValidationService { private static final Logger LOGGER = Logger.getLogger(XMLLanguageServer.class.getName()); @@ -109,7 +108,7 @@ public CompletableFuture initialize(InitializeParams params) { Object xmlSettings = AllXMLSettings.getAllXMLSettings(initOptions); XMLGeneralClientSettings settings = XMLGeneralClientSettings.getGeneralXMLSettings(xmlSettings); - LogHelper.initializeRootLogger(languageClient, settings == null? null : settings.getLogs()); + LogHelper.initializeRootLogger(languageClient, settings == null ? null : settings.getLogs()); LOGGER.info("Initializing XML Language server" + System.lineSeparator() + Platform.details()); @@ -126,7 +125,7 @@ public CompletableFuture initialize(InitializeParams params) { xmlTextDocumentService.updateClientCapabilities(capabilityManager.getClientCapabilities().capabilities, capabilityManager.getClientCapabilities().getExtendedCapabilities()); - updateSettings(initOptions, false /* already configured logging*/ ); + updateSettings(initOptions, false /* already configured logging */ ); ServerCapabilities nonDynamicServerCapabilities = ServerCapabilitiesInitializer.getNonDynamicServerCapabilities( capabilityManager.getClientCapabilities(), xmlTextDocumentService.isIncrementalSupport()); @@ -162,7 +161,7 @@ public synchronized void updateSettings(Object initOptions) { * Update XML settings configured from the client. * * @param initOptions Settings the XML settings - * @param initLogs whether to initialize the log handlers + * @param initLogs whether to initialize the log handlers */ private synchronized void updateSettings(Object initOptions, boolean initLogs) { if (initOptions == null) { @@ -227,8 +226,8 @@ private synchronized void updateSettings(Object initOptions, boolean initLogs) { @Override public CompletableFuture shutdown() { xmlLanguageService.dispose(); - if (capabilityManager.getClientCapabilities().getExtendedCapabilities().shouldLanguageServerExitOnShutdown()) { - delayer.schedule(() -> exit(0) , 1, TimeUnit.SECONDS); + if (capabilityManager.getClientCapabilities().shouldLanguageServerExitOnShutdown()) { + delayer.schedule(() -> exit(0), 1, TimeUnit.SECONDS); } getTelemetryManager().shutdown(); return computeAsync(cc -> new Object()); @@ -285,7 +284,8 @@ public long getParentProcessId() { @Override public CompletableFuture closeTag(TextDocumentPositionParams params) { return xmlTextDocumentService.computeDOMAsync(params.getTextDocument(), (cancelChecker, xmlDocument) -> { - return getXMLLanguageService().doAutoClose(xmlDocument, params.getPosition(), getSettings().getCompletionSettings(), cancelChecker); + return getXMLLanguageService().doAutoClose(xmlDocument, params.getPosition(), + getSettings().getCompletionSettings(), cancelChecker); }); } @@ -323,9 +323,9 @@ public SharedSettings getSharedSettings() { @Override public Collection getAllDocuments() { - return xmlTextDocumentService.allDocuments().stream() - .map(m -> m.getModel().getNow(null)) - .filter(Objects::nonNull) + return xmlTextDocumentService.allDocuments().stream() // + .map(m -> m.getModel().getNow(null)) // + .filter(Objects::nonNull) // .collect(Collectors.toList()); } diff --git a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/capabilities/ClientCapabilitiesWrapper.java b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/capabilities/ClientCapabilitiesWrapper.java index ba622a7a2..06eb94b72 100644 --- a/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/capabilities/ClientCapabilitiesWrapper.java +++ b/org.eclipse.lemminx/src/main/java/org/eclipse/lemminx/settings/capabilities/ClientCapabilitiesWrapper.java @@ -114,7 +114,7 @@ public boolean isSelectionRangeDynamicRegistered() { public boolean isDidChangeWatchedFilesRegistered() { return v3Supported && isDynamicRegistrationSupported(capabilities.getWorkspace().getDidChangeWatchedFiles()); } - + public boolean isLinkedEditingRangeDynamicRegistered() { return v3Supported && isDynamicRegistrationSupported(getTextDocument().getLinkedEditingRange()); } @@ -133,9 +133,22 @@ public ExtendedClientCapabilities getExtendedCapabilities() { } public boolean isWorkspaceFoldersSupported() { - return Optional.ofNullable(this.capabilities) - .map(ClientCapabilities::getWorkspace) - .map(WorkspaceClientCapabilities::getWorkspaceFolders) + return Optional.ofNullable(this.capabilities) // + .map(ClientCapabilities::getWorkspace) // + .map(WorkspaceClientCapabilities::getWorkspaceFolders) // .filter(Boolean.TRUE::equals).isPresent(); } + + /** + * Returns true if the client should exit on shutdown() request and avoid + * waiting for an exit() request + * + * @return true if the language server should exit on shutdown() request + */ + public boolean shouldLanguageServerExitOnShutdown() { + if (extendedCapabilities == null) { + return false; + } + return extendedCapabilities.shouldLanguageServerExitOnShutdown(); + } } \ No newline at end of file diff --git a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java index f56aaf0ca..09d5f7beb 100644 --- a/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java +++ b/org.eclipse.lemminx/src/test/java/org/eclipse/lemminx/extensions/contentmodel/XMLSchemaCompletionExtensionsTest.java @@ -56,8 +56,10 @@ public void completionInRoot() throws BadLocationException { + // " <|" + // ""; - testCompletionFor(xml, c("modelVersion", te(3, 1, 3, 2, ""), ""), "", " xml = "" + // ""; - testCompletionFor(xml, c("modelVersion", te(3, 1, 3, 6, ""), ""), "", ""; - testCompletionFor(xml, c("modelVersion", te(3, 1, 3, 1, ""), "modelVersion"), // + testCompletionWithCatalogFor(xml, // + c("modelVersion", te(3, 1, 3, 1, ""), "modelVersion"), // c("parent", "", "parent")); + // completion on mod xml = ""; - testCompletionFor(xml, c("modelVersion", te(3, 1, 3, 4, ""), "modelVersion"), // + testCompletionWithCatalogFor(xml, // + c("modelVersion", te(3, 1, 3, 4, ""), "modelVersion"), // c("parent", "", "parent")); } @@ -95,7 +102,8 @@ public void completionInRootWithCloseBracket() throws BadLocationException { + // " <| >" + // here last '<' is replaced with ""; - testCompletionFor(xml, c("modelVersion", te(3, 1, 3, 5, ""), ""), "", "<|" + // ""; - testCompletionFor(xml, c("groupId", "", "", "", "", "|" + // ""; - testCompletionFor(xml, c("groupId", "", "groupId"), // + testCompletionWithCatalogFor(xml, c("groupId", "", "groupId"), // c("artifactId", "", "artifactId"), // c("version", "", "version")); } @@ -140,7 +148,7 @@ public void completionInRootWithAndWithoutPrefixes() throws BadLocationException " http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd\">\r\n" + // "\r\n" + // " <| "; - testCompletionFor(xml, c("bean", "", "", "", "\r\n" + // "\r\n" + // " | "; - testCompletionFor(xml, c("bean", "", "bean"), + testCompletionWithCatalogFor(xml, c("bean", "", "bean"), c("camel:camelContext", "", "camel:camelContext")); } @@ -178,7 +186,7 @@ public void completionInRootWithOnlyPrefix() throws BadLocationException { " http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd\">\r\n" + // "\r\n" + // " ")); + testCompletionWithCatalogFor(xml, c("camel:camelContext", "")); } @Test @@ -196,7 +204,7 @@ public void completionInChildElementWithPrefixes() throws BadLocationException { " http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd\">\r\n" + // "\r\n" + // " <| "; - testCompletionFor(xml, c("camel:route", ""), + testCompletionWithCatalogFor(xml, c("camel:route", ""), c("camel:template", "")); } @@ -206,7 +214,7 @@ public void completionInChildElementWithElementWhichDeclareNS() throws BadLocati "\r\n" + // " \r\n" + "\r\n" + // " <|"; - testCompletionFor(xml, c("route", ""), c("template", "