Skip to content

Commit

Permalink
Shutdown raises exception
Browse files Browse the repository at this point in the history
Fixes #1132

Signed-off-by: azerr <azerr@redhat.com>
  • Loading branch information
azerr authored and angelozerr committed Dec 7, 2021
1 parent fceb4c3 commit ce526f8
Show file tree
Hide file tree
Showing 6 changed files with 1,291 additions and 1,151 deletions.
Expand Up @@ -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());
Expand Down Expand Up @@ -109,7 +108,7 @@ public CompletableFuture<InitializeResult> 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());

Expand All @@ -126,7 +125,7 @@ public CompletableFuture<InitializeResult> 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());
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -227,8 +226,8 @@ private synchronized void updateSettings(Object initOptions, boolean initLogs) {
@Override
public CompletableFuture<Object> 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());
Expand Down Expand Up @@ -285,7 +284,8 @@ public long getParentProcessId() {
@Override
public CompletableFuture<AutoCloseTagResponse> 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);
});
}

Expand Down Expand Up @@ -323,9 +323,9 @@ public SharedSettings getSharedSettings() {

@Override
public Collection<DOMDocument> 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());
}

Expand Down
Expand Up @@ -114,7 +114,7 @@ public boolean isSelectionRangeDynamicRegistered() {
public boolean isDidChangeWatchedFilesRegistered() {
return v3Supported && isDynamicRegistrationSupported(capabilities.getWorkspace().getDidChangeWatchedFiles());
}

public boolean isLinkedEditingRangeDynamicRegistered() {
return v3Supported && isDynamicRegistrationSupported(getTextDocument().getLinkedEditingRange());
}
Expand All @@ -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();
}
}

0 comments on commit ce526f8

Please sign in to comment.