4
4
* ------------------------------------------------------------------------------------------ */
5
5
'use strict' ;
6
6
7
+ import * as path from 'path' ;
8
+ import * as os from 'os' ;
9
+
7
10
import { ExtensionContext , workspace , window , OutputChannel , languages } from 'vscode' ;
8
11
import { LanguageClient , LanguageClientOptions , ServerOptions ,
9
12
TransportKind , RequestType , NotificationType , NotificationHandler ,
@@ -313,21 +316,36 @@ export default class SqlToolsServiceClient {
313
316
private createServerOptions ( servicePath ) : ServerOptions {
314
317
let serverArgs = [ ] ;
315
318
let serverCommand : string = servicePath ;
316
- if ( servicePath . endsWith ( '.dll' ) ) {
317
- serverArgs = [ servicePath ] ;
318
- serverCommand = 'dotnet' ;
319
- }
320
319
321
- // Get the extenion's configuration
322
320
let config = workspace . getConfiguration ( Constants . extensionConfigSectionName ) ;
321
+
323
322
if ( config ) {
323
+ // Override the server path with the local debug path if enabled
324
+
325
+ let useLocalSource = config [ 'useDebugSource' ] ;
326
+ if ( useLocalSource ) {
327
+ let localSourcePath = config [ 'debugSourcePath' ] ;
328
+ let filePath = path . join ( localSourcePath , 'pgsqltoolsservice/pgtoolsservice_main.py' ) ;
329
+ process . env . PYTHONPATH = localSourcePath ;
330
+ serverCommand = process . platform === 'win32' ? 'python' : 'python3' ;
331
+
332
+ let enableStartupDebugging = config [ 'enableStartupDebugging' ] ;
333
+ let debuggingArg = enableStartupDebugging ? '--enable-remote-debugging-wait' : '--enable-remote-debugging' ;
334
+ let debugPort = config [ 'debugServerPort' ] ;
335
+ debuggingArg += '=' + debugPort ;
336
+ serverArgs = [ filePath , debuggingArg ] ;
337
+ }
338
+
339
+ let logFileLocation = path . join ( this . getDefaultLogLocation ( ) , 'pgsql' ) ;
340
+
341
+ serverArgs . push ( '--log-dir=' + logFileLocation ) ;
342
+ serverArgs . push ( logFileLocation ) ;
343
+
324
344
// Enable diagnostic logging in the service if it is configured
325
- let logDebugInfo = config [ Constants . configLogDebugInfo ] ;
345
+ let logDebugInfo = config [ 'logDebugInfo' ] ;
326
346
if ( logDebugInfo ) {
327
347
serverArgs . push ( '--enable-logging' ) ;
328
348
}
329
-
330
- // Send Locale for sqltoolsservice localization
331
349
let applyLocalization = config [ Constants . configApplyLocalization ] ;
332
350
if ( applyLocalization ) {
333
351
let locale = vscode . env . language ;
@@ -336,10 +354,8 @@ export default class SqlToolsServiceClient {
336
354
}
337
355
}
338
356
339
-
340
- // run the service host using dotnet.exe from the path
341
- let serverOptions : ServerOptions = { command : serverCommand , args : serverArgs , transport : TransportKind . stdio } ;
342
- return serverOptions ;
357
+ // run the service host
358
+ return { command : serverCommand , args : serverArgs , transport : TransportKind . stdio } ;
343
359
}
344
360
345
361
/**
@@ -384,4 +400,20 @@ export default class SqlToolsServiceClient {
384
400
} ) ;
385
401
} ) ;
386
402
}
403
+
404
+ // The function is a duplicate of \src\paths.js. IT would be better to import path.js but it doesn't
405
+ // work for now because the extension is running in different process.
406
+ private getAppDataPath ( ) : string {
407
+ let platform = process . platform ;
408
+ switch ( platform ) {
409
+ case 'win32' : return process . env [ 'APPDATA' ] || path . join ( process . env [ 'USERPROFILE' ] , 'AppData' , 'Roaming' ) ;
410
+ case 'darwin' : return path . join ( os . homedir ( ) , 'Library' , 'Application Support' ) ;
411
+ case 'linux' : return process . env [ 'XDG_CONFIG_HOME' ] || path . join ( os . homedir ( ) , '.config' ) ;
412
+ default : throw new Error ( 'Platform not supported' ) ;
413
+ }
414
+ }
415
+
416
+ private getDefaultLogLocation ( ) : string {
417
+ return path . join ( this . getAppDataPath ( ) , 'code' ) ;
418
+ }
387
419
}
0 commit comments