Skip to content

Commit afc4b32

Browse files
Merged PR 477022: Ensure we don't run both project systems at once
2 parents b1636bf + 9f3eeb4 commit afc4b32

File tree

1 file changed

+32
-23
lines changed

1 file changed

+32
-23
lines changed

src/lsptoolshost/roslynLanguageServer.ts

Lines changed: 32 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -150,9 +150,10 @@ export class RoslynLanguageServer {
150150
}
151151

152152
/**
153-
* Resolves server options and starts the dotnet language server process.
153+
* Resolves server options and starts the dotnet language server process. The process is started asynchronously and this method will not wait until
154+
* the process is launched.
154155
*/
155-
public async start(): Promise<void> {
156+
public start(): void {
156157
let options = this.optionProvider.GetLatestOptions();
157158
let logLevel = options.languageServerOptions.logLevel;
158159
const languageClientTraceLevel = this.GetTraceLevel(logLevel);
@@ -207,7 +208,11 @@ export class RoslynLanguageServer {
207208
this._languageClient.onDidChangeState(async (state) => {
208209
if (state.newState === State.Running) {
209210
await this._languageClient!.setTrace(languageClientTraceLevel);
210-
await this.sendOpenSolutionNotification();
211+
if (this._solutionFile) {
212+
await this.sendOpenSolutionNotification();
213+
} else {
214+
await this.openDefaultSolution();
215+
}
211216
await this.sendOrSubscribeForServiceBrokerConnection();
212217
this._eventBus.emit(RoslynLanguageServer.serverStateChangeEvent, ServerStateChange.Started);
213218
}
@@ -222,20 +227,6 @@ export class RoslynLanguageServer {
222227

223228
// Register Razor dynamic file info handling
224229
this.registerRazor(this._languageClient);
225-
226-
// If Dev Kit isn't installed, then we are responsible for picking the solution to open, assuming the user hasn't explicitly
227-
// disabled it.
228-
if (!this._wasActivatedWithCSharpDevkit && options.commonOptions.defaultSolution !== 'disable' && this._solutionFile === undefined) {
229-
if (options.commonOptions.defaultSolution !== '') {
230-
this.openSolution(vscode.Uri.file(options.commonOptions.defaultSolution));
231-
} else {
232-
// Auto open if there is just one solution target; if there's more the one we'll just let the user pick with the picker.
233-
const solutionUris = await vscode.workspace.findFiles('**/*.sln', '**/node_modules/**', 2);
234-
if (solutionUris && solutionUris.length === 1) {
235-
this.openSolution(solutionUris[0]);
236-
}
237-
}
238-
}
239230
}
240231

241232
public async stop(): Promise<void> {
@@ -245,13 +236,13 @@ export class RoslynLanguageServer {
245236
}
246237

247238
/**
248-
* Restarts the language server.
239+
* Restarts the language server. This does not wait until the server has been restarted.
249240
* Note that since some options affect how the language server is initialized, we must
250-
* re-create the LanguageClient instance instead of just stopping/starting it.
241+
* re-create the LanguageClient instance instead of just stopping/starting it.
251242
*/
252243
public async restart(): Promise<void> {
253244
await this.stop();
254-
await this.start();
245+
this.start();
255246
}
256247

257248
/**
@@ -309,14 +300,32 @@ export class RoslynLanguageServer {
309300
await this.sendOpenSolutionNotification();
310301
}
311302

312-
private async sendOpenSolutionNotification() {
303+
private async sendOpenSolutionNotification(): Promise<void> {
313304
if (this._solutionFile !== undefined && this._languageClient !== undefined && this._languageClient.isRunning()) {
314305
let protocolUri = this._languageClient.clientOptions.uriConverters!.code2Protocol(this._solutionFile);
315306
await this._languageClient.sendNotification("solution/open", new OpenSolutionParams(protocolUri));
316307
}
317308
}
318309

319-
private async sendOrSubscribeForServiceBrokerConnection() {
310+
private async openDefaultSolution(): Promise<void> {
311+
const options = this.optionProvider.GetLatestOptions();
312+
313+
// If Dev Kit isn't installed, then we are responsible for picking the solution to open, assuming the user hasn't explicitly
314+
// disabled it.
315+
if (!this._wasActivatedWithCSharpDevkit && options.commonOptions.defaultSolution !== 'disable' && this._solutionFile === undefined) {
316+
if (options.commonOptions.defaultSolution !== '') {
317+
this.openSolution(vscode.Uri.file(options.commonOptions.defaultSolution));
318+
} else {
319+
// Auto open if there is just one solution target; if there's more the one we'll just let the user pick with the picker.
320+
const solutionUris = await vscode.workspace.findFiles('**/*.sln', '**/node_modules/**', 2);
321+
if (solutionUris && solutionUris.length === 1) {
322+
this.openSolution(solutionUris[0]);
323+
}
324+
}
325+
}
326+
}
327+
328+
private async sendOrSubscribeForServiceBrokerConnection(): Promise<void> {
320329
const csharpDevKitExtension = vscode.extensions.getExtension<CSharpDevKitExports>(csharpDevkitExtensionId);
321330
if (csharpDevKitExtension) {
322331
const exports = await csharpDevKitExtension.activate();
@@ -627,7 +636,7 @@ export async function activateRoslynLanguageServer(context: vscode.ExtensionCont
627636
});
628637

629638
// Start the language server.
630-
await _languageServer.start();
639+
_languageServer.start();
631640
}
632641

633642
async function applyAutoInsertEdit(e: vscode.TextDocumentChangeEvent, token: vscode.CancellationToken) {

0 commit comments

Comments
 (0)