diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLLanguageServer.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLLanguageServer.java index 1f1f951148..14195d9709 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLLanguageServer.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/XMLLanguageServer.java @@ -14,6 +14,10 @@ import static org.eclipse.lsp4j.jsonrpc.CompletableFutures.computeAsync; import static org.eclipse.lsp4xml.utils.VersionHelper.getVersion; +import java.io.File; +import java.nio.file.Files; +import java.nio.file.LinkOption; +import java.nio.file.Path; import java.util.concurrent.CompletableFuture; import java.util.concurrent.Executors; import java.util.concurrent.ScheduledExecutorService; @@ -44,11 +48,13 @@ import org.eclipse.lsp4xml.settings.AllXMLSettings; import org.eclipse.lsp4xml.settings.InitializationOptionsSettings; import org.eclipse.lsp4xml.settings.LogsSettings; +import org.eclipse.lsp4xml.settings.ServerSettings; import org.eclipse.lsp4xml.settings.XMLGeneralClientSettings; import org.eclipse.lsp4xml.settings.XMLExperimentalCapabilities; import org.eclipse.lsp4xml.settings.XMLFormattingOptions; import org.eclipse.lsp4xml.settings.capabilities.ServerCapabilitiesInitializer; import org.eclipse.lsp4xml.settings.capabilities.XMLCapabilityManager; +import org.eclipse.lsp4xml.utils.FilesUtils; /** * XML language server. @@ -135,6 +141,18 @@ public void updateSettings(Object initializationOptionsSettings) { if (newCompletions != null) { xmlTextDocumentService.updateCompletionSettings(newCompletions); } + + ServerSettings serverSettings = xmlClientSettings.getServer(); + if(serverSettings != null) { + String workDir = serverSettings.getWorkDir(); + + Path p = new File(workDir).toPath(); + if(Files.isDirectory(p, LinkOption.NOFOLLOW_LINKS)) { + if(workDir != null && System.getProperty(FilesUtils.LSP4XML_WORKDIR_KEY).equals(workDir) == false) { + System.setProperty(FilesUtils.LSP4XML_WORKDIR_KEY, workDir); + } + } + } // Experimental capabilities XMLExperimentalCapabilities experimental = xmlClientSettings.getExperimental(); diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/ServerSettings.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/ServerSettings.java new file mode 100644 index 0000000000..5c67f54f2b --- /dev/null +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/ServerSettings.java @@ -0,0 +1,37 @@ +/******************************************************************************* +* 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; + +import org.eclipse.lsp4xml.utils.JSONUtility; + +/** + * ServerSettings + */ +public class ServerSettings { + + private String workDir; + + + /** + * @return the workDir + */ + public String getWorkDir() { + return workDir; + } + + /** + * @param workDir the workDir to set + */ + public void setWorkDir(String workDir) { + this.workDir = workDir; + } + +} \ No newline at end of file diff --git a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/XMLGeneralClientSettings.java b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/XMLGeneralClientSettings.java index f147ced0a7..83c40c7116 100644 --- a/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/XMLGeneralClientSettings.java +++ b/org.eclipse.lsp4xml/src/main/java/org/eclipse/lsp4xml/settings/XMLGeneralClientSettings.java @@ -42,6 +42,8 @@ public class XMLGeneralClientSettings { private CompletionSettings completion; + private ServerSettings server; + public void setLogs(LogsSettings logs) { this.logs = logs; } @@ -78,6 +80,20 @@ public CompletionSettings getCompletion() { return completion; } + /** + * @return the server + */ + public ServerSettings getServer() { + return server; + } + + /** + * @param server the server to set + */ + public void setServer(ServerSettings server) { + this.server = server; + } + public static XMLGeneralClientSettings getGeneralXMLSettings(Object initializationOptionsSettings) { return JSONUtility.toModel(initializationOptionsSettings, XMLGeneralClientSettings.class); }