@@ -27,10 +27,14 @@ import { PlatformInformation } from '../../shared/platform';
2727import { readConfigurations } from '../options/configurationMiddleware' ;
2828import { DynamicFileInfoHandler } from '../../razor/src/dynamicFile/dynamicFileInfoHandler' ;
2929import * as RoslynProtocol from './roslynProtocol' ;
30- import { CSharpDevKitExports } from '../csharpDevKitExports' ;
31- import { SolutionSnapshotId } from './services/ISolutionSnapshotProvider' ;
32- import CSharpIntelliCodeExports from '../csharpIntelliCodeExports' ;
33- import { csharpDevkitExtensionId , csharpDevkitIntelliCodeExtensionId , getCSharpDevKit } from '../utils/getCSharpDevKit' ;
30+ import { CSharpDevKitExports } from '../../csharpDevKitExports' ;
31+ import { SolutionSnapshotId } from '../solutionSnapshot/ISolutionSnapshotProvider' ;
32+ import CSharpIntelliCodeExports from '../../csharpIntelliCodeExports' ;
33+ import {
34+ csharpDevkitExtensionId ,
35+ csharpDevkitIntelliCodeExtensionId ,
36+ getCSharpDevKit ,
37+ } from '../../utils/getCSharpDevKit' ;
3438import { randomUUID } from 'crypto' ;
3539import { IHostExecutableResolver } from '../../shared/constants/IHostExecutableResolver' ;
3640import { RoslynLanguageClient } from './roslynLanguageClient' ;
@@ -43,27 +47,21 @@ import { registerShowToastNotification } from '../handlers/showToastNotification
4347import { registerOnAutoInsert } from '../autoInsert/onAutoInsert' ;
4448import { commonOptions , languageServerOptions , omnisharpOptions , razorOptions } from '../../shared/options' ;
4549import { NamedPipeInformation } from './roslynProtocol' ;
46- import { IDisposable } from '../disposable' ;
47- import { registerNestedCodeActionCommands } from './nestedCodeAction' ;
48- import { registerRestoreCommands } from './restore' ;
49- import { BuildDiagnosticsService } from './buildDiagnosticsService' ;
50- import { getComponentPaths } from './builtInComponents' ;
51- import { OnAutoInsertFeature } from './onAutoInsertFeature' ;
52- import { registerLanguageStatusItems } from './languageStatusBar' ;
53- import { ProjectContextService } from './services/projectContextService' ;
54- import { ServerState } from './serverStateChange' ;
55- import { ProvideDynamicFileResponse } from '../razor/src/dynamicFile/provideDynamicFileResponse' ;
56- import { ProvideDynamicFileParams } from '../razor/src/dynamicFile/provideDynamicFileParams' ;
57- import { registerCopilotExtension } from './copilot' ;
50+ import { IDisposable } from '../../disposable' ;
51+ import { BuildDiagnosticsService } from '../diagnostics/buildDiagnosticsService' ;
52+ import { getComponentPaths } from '../extensions/builtInComponents' ;
53+ import { OnAutoInsertFeature } from '../autoInsert/onAutoInsertFeature' ;
54+ import { ProjectContextService } from '../projectContext/projectContextService' ;
55+ import { ProvideDynamicFileResponse } from '../../razor/src/dynamicFile/provideDynamicFileResponse' ;
56+ import { ProvideDynamicFileParams } from '../../razor/src/dynamicFile/provideDynamicFileParams' ;
5857import {
5958 ActionOption ,
6059 CommandOption ,
6160 showErrorMessage ,
6261 showInformationMessage ,
63- } from '../shared/observers/utils/showMessage' ;
64- import { registerSourceGeneratedFilesContentProvider } from './sourceGeneratedFilesContentProvider' ;
65- import { registerMiscellaneousFileNotifier } from './miscellaneousFileNotifier' ;
66- import { RazorDynamicFileChangedParams } from '../razor/src/dynamicFile/dynamicFileUpdatedParams' ;
62+ } from '../../shared/observers/utils/showMessage' ;
63+ import { RazorDynamicFileChangedParams } from '../../razor/src/dynamicFile/dynamicFileUpdatedParams' ;
64+ import { getProfilingEnvVars } from '../profiling/profiling' ;
6765import { isString } from '../utils/isString' ;
6866import { getServerPath } from '../activate' ;
6967import { UriConverter } from '../utils/uriConverter' ;
@@ -72,9 +70,6 @@ import {
7270 copilotLanguageServerExtensionComponentName ,
7371} from '../copilot/contextProviders' ;
7472
75- let _channel : vscode . LogOutputChannel ;
76- let _traceChannel : vscode . OutputChannel ;
77-
7873// Flag indicating if C# Devkit was installed the last time we activated.
7974// Used to determine if we need to restart the server on extension changes.
8075let _wasActivatedWithCSharpDevkit : boolean | undefined ;
@@ -120,7 +115,8 @@ export class RoslynLanguageServer {
120115 private _languageClient : RoslynLanguageClient ,
121116 private _platformInfo : PlatformInformation ,
122117 private _context : vscode . ExtensionContext ,
123- private _languageServerEvents : RoslynLanguageServerEvents
118+ private _languageServerEvents : RoslynLanguageServerEvents ,
119+ private _channel : vscode . LogOutputChannel
124120 ) {
125121 this . registerSetTrace ( ) ;
126122 this . registerSendOpenSolution ( ) ;
@@ -186,7 +182,6 @@ export class RoslynLanguageServer {
186182 state : ServerState . Started ,
187183 workspaceLabel : this . workspaceDisplayName ( ) ,
188184 } ) ;
189- this . _telemetryReporter . sendTelemetryEvent ( TelemetryEventNames . ClientServerReady ) ;
190185 } else if ( state . newState === State . Stopped ) {
191186 this . _languageServerEvents . onServerStateChangeEmitter . fire ( {
192187 state : ServerState . Stopped ,
@@ -254,7 +249,13 @@ export class RoslynLanguageServer {
254249 }
255250
256251 const serverOptions : ServerOptions = async ( ) => {
257- return await this . startServer ( platformInfo , hostExecutableResolver , context , additionalExtensionPaths ) ;
252+ return await this . startServer (
253+ platformInfo ,
254+ hostExecutableResolver ,
255+ context ,
256+ additionalExtensionPaths ,
257+ channel
258+ ) ;
258259 } ;
259260
260261 const documentSelector = languageServerOptions . documentSelector ;
@@ -296,7 +297,8 @@ export class RoslynLanguageServer {
296297
297298 client . registerProposedFeatures ( ) ;
298299
299- const server = new RoslynLanguageServer ( client , platformInfo , context , languageServerEvents ) ;
300+ const server = new RoslynLanguageServer ( client , platformInfo , context , languageServerEvents , channel ) ;
301+
300302 client . registerFeature ( server . _onAutoInsertFeature ) ;
301303
302304 // Start the client. This will also launch the server process.
@@ -564,13 +566,14 @@ export class RoslynLanguageServer {
564566 platformInfo : PlatformInformation ,
565567 hostExecutableResolver : IHostExecutableResolver ,
566568 context : vscode . ExtensionContext ,
567- additionalExtensionPaths : string [ ]
569+ additionalExtensionPaths : string [ ] ,
570+ channel : vscode . LogOutputChannel
568571 ) : Promise < MessageTransports > {
569572 const serverPath = getServerPath ( platformInfo ) ;
570573
571574 const dotnetInfo = await hostExecutableResolver . getHostExecutableInfo ( ) ;
572575 const dotnetExecutablePath = dotnetInfo . path ;
573- _channel . info ( 'Dotnet path: ' + dotnetExecutablePath ) ;
576+ channel . info ( 'Dotnet path: ' + dotnetExecutablePath ) ;
574577
575578 let args : string [ ] = [ ] ;
576579
@@ -1079,130 +1082,6 @@ export class RoslynLanguageServer {
10791082 }
10801083}
10811084
1082- /**
1083- * Creates and activates the Roslyn language server.
1084- * The returned promise will complete when the server starts.
1085- */
1086- export async function activateRoslynLanguageServer (
1087- context : vscode . ExtensionContext ,
1088- platformInfo : PlatformInformation ,
1089- optionObservable : Observable < void > ,
1090- outputChannel : vscode . LogOutputChannel ,
1091- languageServerEvents : RoslynLanguageServerEvents
1092- ) : Promise < RoslynLanguageServer > {
1093- // Create a channel for outputting general logs from the language server.
1094- _channel = outputChannel ;
1095- // Create a separate channel for outputting trace logs - these are incredibly verbose and make other logs very difficult to see.
1096- // The trace channel verbosity is controlled by the _channel verbosity.
1097- _traceChannel = vscode . window . createOutputChannel ( vscode . l10n . t ( 'C# LSP Trace Logs' ) ) ;
1098-
1099- const hostExecutableResolver = new DotnetRuntimeExtensionResolver (
1100- platformInfo ,
1101- getServerPath ,
1102- outputChannel ,
1103- context . extensionPath
1104- ) ;
1105- const additionalExtensionPaths = scanExtensionPlugins ( ) ;
1106-
1107- const languageServer = await RoslynLanguageServer . initializeAsync (
1108- platformInfo ,
1109- hostExecutableResolver ,
1110- context ,
1111- additionalExtensionPaths ,
1112- languageServerEvents
1113- ) ;
1114-
1115- registerLanguageStatusItems ( context , languageServer , languageServerEvents ) ;
1116- registerMiscellaneousFileNotifier ( context , languageServer ) ;
1117- registerCopilotExtension ( languageServer , _channel ) ;
1118-
1119- // Register any commands that need to be handled by the extension.
1120- registerCommands ( context , languageServer , hostExecutableResolver , _channel ) ;
1121- registerNestedCodeActionCommands ( context , languageServer , _channel ) ;
1122- registerCodeActionFixAllCommands ( context , languageServer , _channel ) ;
1123-
1124- registerRazorCommands ( context , languageServer ) ;
1125-
1126- registerUnitTestingCommands ( context , languageServer ) ;
1127-
1128- // Register any needed debugger components that need to communicate with the language server.
1129- registerDebugger ( context , languageServer , languageServerEvents , platformInfo , _channel ) ;
1130-
1131- registerRestoreCommands ( context , languageServer ) ;
1132-
1133- registerSourceGeneratedFilesContentProvider ( context , languageServer ) ;
1134-
1135- context . subscriptions . push ( registerLanguageServerOptionChanges ( optionObservable ) ) ;
1136-
1137- return languageServer ;
1138-
1139- function scanExtensionPlugins ( ) : string [ ] {
1140- const extensionsFromPackageJson = vscode . extensions . all . flatMap ( ( extension ) => {
1141- let loadPaths = extension . packageJSON . contributes ?. [ 'csharpExtensionLoadPaths' ] ;
1142- if ( loadPaths === undefined || loadPaths === null ) {
1143- _channel . debug ( `Extension ${ extension . id } does not contribute csharpExtensionLoadPaths` ) ;
1144- return [ ] ;
1145- }
1146-
1147- if ( ! Array . isArray ( loadPaths ) || loadPaths . some ( ( loadPath ) => typeof loadPath !== 'string' ) ) {
1148- _channel . warn (
1149- `Extension ${ extension . id } has invalid csharpExtensionLoadPaths. Expected string array, found ${ loadPaths } `
1150- ) ;
1151- return [ ] ;
1152- }
1153-
1154- loadPaths = loadPaths . map ( ( loadPath ) => path . join ( extension . extensionPath , loadPath ) ) ;
1155- _channel . trace ( `Extension ${ extension . id } contributes csharpExtensionLoadPaths: ${ loadPaths } ` ) ;
1156- return loadPaths ;
1157- } ) ;
1158- const extensionsFromOptions = languageServerOptions . extensionsPaths ?? [ ] ;
1159- return extensionsFromPackageJson . concat ( extensionsFromOptions ) ;
1160- }
1161- }
1162-
1163- function getServerPath ( platformInfo : PlatformInformation ) {
1164- let serverPath = process . env . DOTNET_ROSLYN_SERVER_PATH ;
1165-
1166- if ( serverPath ) {
1167- _channel . appendLine ( `Using server path override from DOTNET_ROSLYN_SERVER_PATH: ${ serverPath } ` ) ;
1168- } else {
1169- serverPath = commonOptions . serverPath ;
1170- if ( ! serverPath ) {
1171- // Option not set, use the path from the extension.
1172- serverPath = getInstalledServerPath ( platformInfo ) ;
1173- }
1174- }
1175-
1176- if ( ! fs . existsSync ( serverPath ) ) {
1177- throw new Error ( `Cannot find language server in path '${ serverPath } '` ) ;
1178- }
1179-
1180- return serverPath ;
1181- }
1182-
1183- function getInstalledServerPath ( platformInfo : PlatformInformation ) : string {
1184- const clientRoot = __dirname ;
1185- const serverFilePath = path . join ( clientRoot , '..' , '.roslyn' , 'Microsoft.CodeAnalysis.LanguageServer' ) ;
1186-
1187- let extension = '' ;
1188- if ( platformInfo . isWindows ( ) ) {
1189- extension = '.exe' ;
1190- } else if ( platformInfo . isMacOS ( ) ) {
1191- // MacOS executables must be signed with codesign. Currently all Roslyn server executables are built on windows
1192- // and therefore dotnet publish does not automatically sign them.
1193- // Tracking bug - https://devdiv.visualstudio.com/DevDiv/_workitems/edit/1767519/
1194- extension = '.dll' ;
1195- }
1196-
1197- let pathWithExtension = `${ serverFilePath } ${ extension } ` ;
1198- if ( ! fs . existsSync ( pathWithExtension ) ) {
1199- // We might be running a platform neutral vsix which has no executable, instead we run the dll directly.
1200- pathWithExtension = `${ serverFilePath } .dll` ;
1201- }
1202-
1203- return pathWithExtension ;
1204- }
1205-
12061085// VS code will have a default session id when running under tests. Since we may still
12071086// report telemetry, we need to give a unique session id instead of the default value.
12081087function getSessionId ( ) : string {
0 commit comments