Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show toast when project loading fails #6060

Merged
merged 4 commits into from
Aug 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
}
},
"defaults": {
"roslyn": "4.8.0-1.23406.1",
"roslyn": "4.8.0-1.23407.6",
"omniSharp": "1.39.7",
"razor": "7.0.0-preview.23405.1",
"razorOmnisharp": "7.0.0-preview.23363.1"
Expand Down
6 changes: 5 additions & 1 deletion src/lsptoolshost/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ export function registerCommands(
context: vscode.ExtensionContext,
languageServer: RoslynLanguageServer,
optionProvider: OptionProvider,
hostExecutableResolver: IHostExecutableResolver
hostExecutableResolver: IHostExecutableResolver,
outputChannel: vscode.OutputChannel
) {
// It is very important to be careful about the types used as parameters for these command callbacks.
// If the arguments are coming from the server as json, it is NOT appropriate to use type definitions
Expand Down Expand Up @@ -50,6 +51,9 @@ export function registerCommands(
)
)
);
context.subscriptions.push(
vscode.commands.registerCommand('csharp.showOutputWindow', async () => outputChannel.show())
);
}

/**
Expand Down
54 changes: 53 additions & 1 deletion src/lsptoolshost/roslynLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ import {
CompletionItem,
PartialResultParams,
ProtocolRequestType,
MessageType,
} from 'vscode-languageclient/node';
import { PlatformInformation } from '../shared/platform';
import { readConfigurations } from './configurationMiddleware';
Expand Down Expand Up @@ -198,6 +199,57 @@ export class RoslynLanguageServer {
);
});

this._languageClient.onNotification(RoslynProtocol.ShowToastNotification.type, async (notification) => {
const messageOptions: vscode.MessageOptions = {
modal: false,
};
const commands = notification.commands.map((command) => command.title);
const executeCommandByName = async (result: string | undefined) => {
if (result) {
const command = notification.commands.find((command) => command.title === result);
if (!command) {
throw new Error(`Unknown command ${result}`);
}

if (command.arguments) {
await vscode.commands.executeCommand(command.command, ...command.arguments);
} else {
await vscode.commands.executeCommand(command.command);
}
}
};

switch (notification.messageType) {
case MessageType.Error: {
const result = await vscode.window.showErrorMessage(
notification.message,
messageOptions,
...commands
);
executeCommandByName(result);
break;
}
case MessageType.Warning: {
const result = await vscode.window.showWarningMessage(
notification.message,
messageOptions,
...commands
);
executeCommandByName(result);
break;
}
default: {
const result = await vscode.window.showInformationMessage(
notification.message,
messageOptions,
...commands
);
executeCommandByName(result);
break;
}
}
});

this.registerExtensionsChanged(this._languageClient);
this.registerTelemetryChanged(this._languageClient);

Expand Down Expand Up @@ -664,7 +716,7 @@ export async function activateRoslynLanguageServer(
);

// Register any commands that need to be handled by the extension.
registerCommands(context, _languageServer, optionProvider, hostExecutableResolver);
registerCommands(context, _languageServer, optionProvider, hostExecutableResolver, _channel);

registerRazorCommands(context, _languageServer);

Expand Down
13 changes: 13 additions & 0 deletions src/lsptoolshost/roslynProtocol.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/

import { Command } from 'vscode';
import * as lsp from 'vscode-languageserver-protocol';

export interface WorkspaceDebugConfigurationParams {
Expand Down Expand Up @@ -116,6 +117,12 @@ export interface DebugAttachResult {
didAttach: boolean;
}

export interface ShowToastNotificationParams {
messageType: lsp.MessageType;
message: string;
commands: Command[];
}

export namespace WorkspaceDebugConfigurationRequest {
export const method = 'workspace/debugConfiguration';
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
Expand All @@ -142,6 +149,12 @@ export namespace ProjectInitializationCompleteNotification {
export const type = new lsp.NotificationType(method);
}

export namespace ShowToastNotification {
export const method = 'window/_roslyn_showToast';
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.serverToClient;
export const type = new lsp.NotificationType<ShowToastNotificationParams>(method);
}

export namespace RunTestsRequest {
export const method = 'textDocument/runTests';
export const messageDirection: lsp.MessageDirection = lsp.MessageDirection.clientToServer;
Expand Down