@@ -4,7 +4,7 @@ import * as path from 'path';
44import * as os from 'os' ;
55import * as fs from 'fs' ;
66import { workspace , extensions , ExtensionContext , window , StatusBarAlignment , commands , ViewColumn , Uri , CancellationToken , TextDocumentContentProvider , TextEditor , WorkspaceConfiguration , languages , IndentAction , ProgressLocation , InputBoxOptions , Selection , Position , EventEmitter , OutputChannel } from 'vscode' ;
7- import { ExecuteCommandParams , ExecuteCommandRequest , LanguageClient , LanguageClientOptions , RevealOutputChannelOn , Position as LSPosition , Location as LSLocation , StreamInfo , VersionedTextDocumentIdentifier , ErrorHandler , Message , ErrorAction , CloseAction , InitializationFailedHandler } from 'vscode-languageclient' ;
7+ import { ExecuteCommandParams , ExecuteCommandRequest , LanguageClient , LanguageClientOptions , RevealOutputChannelOn , Position as LSPosition , Location as LSLocation , StreamInfo , VersionedTextDocumentIdentifier , ErrorHandler , Message , ErrorAction , CloseAction , InitializationFailedHandler , DidChangeConfigurationNotification } from 'vscode-languageclient' ;
88import { onExtensionChange , collectJavaExtensions } from './plugin' ;
99import { prepareExecutable , awaitServerConnection } from './javaServerStarter' ;
1010import { getDocumentSymbolsCommand , getDocumentSymbolsProvider } from './documentSymbols' ;
@@ -22,7 +22,7 @@ import * as refactorAction from './refactorAction';
2222import * as pasteAction from './pasteAction' ;
2323import * as net from 'net' ;
2424import { getJavaConfiguration } from './utils' ;
25- import { onConfigurationChange , excludeProjectSettingsFiles } from './settings' ;
25+ import { onConfigurationChange , excludeProjectSettingsFiles , getKey , IS_WORKSPACE_JDK_ALLOWED } from './settings' ;
2626import { logger , initializeLogFile } from './log' ;
2727import glob = require( 'glob' ) ;
2828import { SnippetCompletionProvider } from './snippetCompletionProvider' ;
@@ -126,7 +126,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
126126
127127 enableJavadocSymbols ( ) ;
128128
129- return requirements . resolveRequirements ( ) . catch ( error => {
129+ return requirements . resolveRequirements ( context ) . catch ( error => {
130130 // show error
131131 window . showErrorMessage ( error . message , error . label ) . then ( ( selection ) => {
132132 if ( error . label && error . label === selection && error . command ) {
@@ -138,7 +138,6 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
138138 } ) . then ( requirements => {
139139 return new Promise ( ( resolve , reject ) => {
140140 const workspacePath = path . resolve ( storagePath + '/jdt_ws' ) ;
141-
142141 // Options to control the language client
143142 const clientOptions : LanguageClientOptions = {
144143 // Register the server for java
@@ -153,7 +152,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
153152 initializationOptions : {
154153 bundles : collectJavaExtensions ( extensions . all ) ,
155154 workspaceFolders : workspace . workspaceFolders ? workspace . workspaceFolders . map ( f => f . uri . toString ( ) ) : null ,
156- settings : { java : getJavaConfiguration ( ) } ,
155+ settings : { java : getJavaConfig ( requirements . java_home ) } ,
157156 extendedClientCapabilities : {
158157 progressReportProvider : getJavaConfiguration ( ) . get ( 'progressReports.enabled' ) ,
159158 classFileContentsSupport : true ,
@@ -170,6 +169,14 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
170169 } ,
171170 triggerFiles : getTriggerFiles ( )
172171 } ,
172+ middleware : {
173+ workspace : {
174+ didChangeConfiguration : ( ) => {
175+ languageClient . sendNotification ( DidChangeConfigurationNotification . type , { settings : getJavaConfig ( requirements . java_home ) } ) ;
176+ onConfigurationChange ( languageClient , context ) ;
177+ }
178+ }
179+ } ,
173180 revealOutputChannelOn : RevealOutputChannelOn . Never ,
174181 errorHandler : new ClientErrorHandler ( extensionName ) ,
175182 initializationFailedHandler : error => {
@@ -203,7 +210,7 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
203210 if ( ! port ) {
204211 const lsPort = process . env [ 'JDTLS_CLIENT_PORT' ] ;
205212 if ( ! lsPort ) {
206- serverOptions = prepareExecutable ( requirements , workspacePath , getJavaConfiguration ( ) ) ;
213+ serverOptions = prepareExecutable ( requirements , workspacePath , getJavaConfig ( requirements . java_home ) , context ) ;
207214 } else {
208215 serverOptions = ( ) => {
209216 const socket = net . connect ( lsPort ) ;
@@ -450,6 +457,13 @@ export function activate(context: ExtensionContext): Promise<ExtensionAPI> {
450457 } ) ;
451458}
452459
460+ function getJavaConfig ( javaHome : string ) {
461+ const origConfig = getJavaConfiguration ( ) ;
462+ const javaConfig = JSON . parse ( JSON . stringify ( origConfig ) ) ;
463+ javaConfig . home = javaHome ;
464+ return javaConfig ;
465+ }
466+
453467export function deactivate ( ) : Thenable < void > {
454468 if ( ! languageClient ) {
455469 return undefined ;
0 commit comments