@@ -3,6 +3,7 @@ import * as path from 'path';
33import * as net from 'net' ;
44import * as glob from 'glob' ;
55import * as os from 'os' ;
6+ import * as fs from 'fs' ;
67import { StreamInfo , Executable , ExecutableOptions } from 'vscode-languageclient' ;
78import { RequirementsData } from './requirements' ;
89import { getJavaEncoding , IS_WORKSPACE_VMARGS_ALLOWED , getKey , getJavaagentFlag } from './settings' ;
@@ -114,11 +115,41 @@ function prepareParams(requirements: RequirementsData, javaConfiguration, worksp
114115 } else if ( process . platform === 'linux' ) {
115116 configDir = 'config_linux' ;
116117 }
117- params . push ( '-configuration' ) ; params . push ( path . resolve ( __dirname , '../server' , configDir ) ) ;
118+ params . push ( '-configuration' ) ; params . push ( resolveConfiguration ( context , configDir ) ) ;
118119 params . push ( '-data' ) ; params . push ( workspacePath ) ;
119120 return params ;
120121}
121122
123+ function resolveConfiguration ( context , configDir ) {
124+ ensureExists ( context . globalStoragePath ) ;
125+ const extensionPath = path . resolve ( context . extensionPath , "package.json" ) ;
126+ const packageFile = JSON . parse ( fs . readFileSync ( extensionPath , 'utf8' ) ) ;
127+ let version ;
128+ if ( packageFile ) {
129+ version = packageFile . version ;
130+ }
131+ else {
132+ version = '0.0.0' ;
133+ }
134+ let configuration = path . resolve ( context . globalStoragePath , version ) ;
135+ ensureExists ( configuration ) ;
136+ configuration = path . resolve ( configuration , configDir ) ;
137+ ensureExists ( configuration ) ;
138+ const configIniName = "config.ini" ;
139+ const configIni = path . resolve ( configuration , configIniName ) ;
140+ if ( ! fs . existsSync ( configIni ) ) {
141+ const ini = path . resolve ( __dirname , '../server' , configDir , configIniName ) ;
142+ fs . copyFileSync ( ini , configIni ) ;
143+ }
144+ return configuration ;
145+ }
146+
147+ function ensureExists ( folder ) {
148+ if ( ! fs . existsSync ( folder ) ) {
149+ fs . mkdirSync ( folder ) ;
150+ }
151+ }
152+
122153function startedInDebugMode ( ) : boolean {
123154 const args = ( process as any ) . execArgv ;
124155 if ( args ) {
0 commit comments