@@ -55,6 +55,7 @@ import { ServerStateChange } from './ServerStateChange';
55
55
import TelemetryReporter from '@vscode/extension-telemetry' ;
56
56
import CSharpIntelliCodeExports from '../CSharpIntelliCodeExports' ;
57
57
import { csharpDevkitExtensionId , getCSharpDevKit } from '../utils/getCSharpDevKit' ;
58
+ import { randomUUID } from 'crypto' ;
58
59
59
60
let _languageServer : RoslynLanguageServer ;
60
61
let _channel : vscode . OutputChannel ;
@@ -365,28 +366,28 @@ export class RoslynLanguageServer {
365
366
let options = this . optionProvider . GetLatestOptions ( ) ;
366
367
let serverPath = this . getServerPath ( options ) ;
367
368
368
- let dotnetRuntimePath = options . commonOptions . dotnetPath ;
369
+ let dotnetRuntimePath = options . commonOptions . dotnetPath ;
369
370
if ( ! dotnetRuntimePath )
370
371
{
371
- let dotnetPath = await acquireDotNetProcessDependencies ( serverPath ) ;
372
- dotnetRuntimePath = path . dirname ( dotnetPath ) ;
372
+ let dotnetPath = await acquireDotNetProcessDependencies ( serverPath ) ;
373
+ dotnetRuntimePath = path . dirname ( dotnetPath ) ;
373
374
}
374
-
375
+
375
376
const dotnetExecutableName = this . platformInfo . isWindows ( ) ? 'dotnet.exe' : 'dotnet' ;
376
377
const dotnetExecutablePath = path . join ( dotnetRuntimePath , dotnetExecutableName ) ;
377
378
if ( ! fs . existsSync ( dotnetExecutablePath ) ) {
378
379
throw new Error ( `Cannot find dotnet path '${ dotnetExecutablePath } '` ) ;
379
380
}
380
381
381
382
_channel . appendLine ( "Dotnet path: " + dotnetExecutablePath ) ;
382
-
383
+
383
384
// Take care to always run .NET processes on the runtime that we intend.
384
385
// The dotnet.exe we point to should not go looking for other runtimes.
385
386
const env : NodeJS . ProcessEnv = { ...process . env } ;
386
387
env . DOTNET_ROOT = dotnetRuntimePath ;
387
388
env . DOTNET_MULTILEVEL_LOOKUP = '0' ;
388
389
// Save user's DOTNET_ROOT env-var value so server can recover the user setting when needed
389
- env . DOTNET_ROOT_USER = process . env . DOTNET_ROOT ?? 'EMPTY' ;
390
+ env . DOTNET_ROOT_USER = process . env . DOTNET_ROOT ?? 'EMPTY' ;
390
391
391
392
let args : string [ ] = [ ] ;
392
393
@@ -532,7 +533,7 @@ export class RoslynLanguageServer {
532
533
args . push ( extensionPath ) ;
533
534
}
534
535
535
- args . push ( "--sessionId" , vscode . env . sessionId ) ;
536
+ args . push ( "--sessionId" , getSessionId ( ) ) ;
536
537
return args ;
537
538
}
538
539
@@ -676,3 +677,15 @@ export async function deactivate() {
676
677
return _languageServer . stop ( ) ;
677
678
}
678
679
680
+ // VS code will have a default session id when running under tests. Since we may still
681
+ // report telemetry, we need to give a unique session id instead of the default value.
682
+ function getSessionId ( ) : string {
683
+ let sessionId = vscode . env . sessionId ;
684
+
685
+ // 'somevalue.sessionid' is the test session id provided by vs code
686
+ if ( sessionId . toLowerCase ( ) === 'somevalue.sessionid' ) {
687
+ return randomUUID ( ) ;
688
+ }
689
+
690
+ return sessionId ;
691
+ }
0 commit comments