diff --git a/package-lock.json b/package-lock.json index 00a4dc89b..8f71ec33f 100644 --- a/package-lock.json +++ b/package-lock.json @@ -24,6 +24,7 @@ "react-dom": "^17.0.2", "semver": "^7.5.2", "vscode-languageclient": "8.2.0-next.3", + "vscode-variables": "^1.0.1", "winreg-utf8": "^0.1.1", "winston": "^3.2.1", "winston-daily-rotate-file": "^4.7.1" @@ -7732,6 +7733,11 @@ "resolved": "https://registry.npmjs.org/vscode-languageserver-types/-/vscode-languageserver-types-3.17.6-next.1.tgz", "integrity": "sha512-7xVc/xLtNhKuCKX0mINT6mFUrUuRz0EinhwPGT8Gtsv2hlo+xJb5NKbiGailcWa1/T5e4dr5Pb2MfGchHreHAA==" }, + "node_modules/vscode-variables": { + "version": "1.0.1", + "resolved": "https://registry.npmjs.org/vscode-variables/-/vscode-variables-1.0.1.tgz", + "integrity": "sha512-iZ1d08I30ktqv4mMszGz2Y2o53r+PBpF5tEnwf8NNzKoxeuo0thoaFRG98uJkNVhOtiDmH4HJ3KlqfjM6XIxbA==" + }, "node_modules/watchpack": { "version": "2.4.2", "resolved": "https://registry.npmjs.org/watchpack/-/watchpack-2.4.2.tgz", diff --git a/package.json b/package.json index 06ad47e5b..08713eadc 100644 --- a/package.json +++ b/package.json @@ -1989,7 +1989,8 @@ "vscode-languageclient": "8.2.0-next.3", "winreg-utf8": "^0.1.1", "winston": "^3.2.1", - "winston-daily-rotate-file": "^4.7.1" + "winston-daily-rotate-file": "^4.7.1", + "vscode-variables": "^1.0.1" }, "overrides": { "vscode-languageserver-protocol": "3.17.6-next.1" diff --git a/src/javaServerStarter.ts b/src/javaServerStarter.ts index 7d0f3f267..19ebf744e 100644 --- a/src/javaServerStarter.ts +++ b/src/javaServerStarter.ts @@ -11,7 +11,7 @@ import { logger } from './log'; import { addLombokParam, isLombokSupportEnabled } from './lombokSupport'; import { RequirementsData } from './requirements'; import { IS_WORKSPACE_VMARGS_ALLOWED, getJavaEncoding, getJavaagentFlag, getKey, isInWorkspaceFolder } from './settings'; -import { deleteDirectory, ensureExists, getJavaConfiguration, getTimestamp, getVersion } from './utils'; +import { deleteDirectory, ensureExists, getJavaConfiguration, getTimestamp, getVersion, getVSCodeVariablesMap } from './utils'; import { log } from 'console'; // eslint-disable-next-line no-var @@ -39,7 +39,7 @@ const DEPENDENCY_COLLECTOR_IMPL_BF= 'bf'; export function prepareExecutable(requirements: RequirementsData, workspacePath, context: ExtensionContext, isSyntaxServer: boolean): Executable { const executable: Executable = Object.create(null); const options: ExecutableOptions = Object.create(null); - options.env = Object.assign({ syntaxserver : isSyntaxServer }, process.env); + options.env = Object.assign({ syntaxserver: isSyntaxServer }, process.env, getVSCodeVariablesMap()); if (os.platform() === 'win32') { const vmargs = getJavaConfiguration().get('jdt.ls.vmargs', ''); const watchParentProcess = '-DwatchParentProcess=false'; diff --git a/src/utils.ts b/src/utils.ts index 450227e6b..cb1cb3a99 100644 --- a/src/utils.ts +++ b/src/utils.ts @@ -6,6 +6,7 @@ import { workspace, WorkspaceConfiguration, commands, Uri, version } from 'vscod import { Commands } from './commands'; import { IJavaRuntime } from 'jdk-utils'; import { getSupportedJreNames, listJdks, sortJdksBySource, sortJdksByVersion } from './jdkUtils'; +const vscodeVariables = require('vscode-variables'); export function getJavaConfiguration(): WorkspaceConfiguration { return workspace.getConfiguration('java'); @@ -347,3 +348,12 @@ export function getVersion(extensionPath: string): string { return '0.0.0'; } + +export function getVSCodeVariablesMap(): any { + const keys = [ + "userHome", "workspaceFolder", "workspaceFolderBasename" + ]; + const res = {}; + keys.forEach(key => res[key] = vscodeVariables(`\${${key}}`)); + return res; +}