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
Changes from 1 commit
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
6 changes: 5 additions & 1 deletion src/lsptoolshost/commands.ts
Original file line number Diff line number Diff line change
@@ -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
@@ -50,6 +51,9 @@ export function registerCommands(
)
)
);
context.subscriptions.push(
vscode.commands.registerCommand('csharp.showOutputWindow', async () => outputChannel.show())
);
}

/**
54 changes: 53 additions & 1 deletion src/lsptoolshost/roslynLanguageServer.ts
Original file line number Diff line number Diff line change
@@ -39,6 +39,7 @@ import {
CompletionItem,
PartialResultParams,
ProtocolRequestType,
MessageType,
} from 'vscode-languageclient/node';
import { PlatformInformation } from '../shared/platform';
import { readConfigurations } from './configurationMiddleware';
@@ -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);

@@ -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);

13 changes: 13 additions & 0 deletions src/lsptoolshost/roslynProtocol.ts
Original file line number Diff line number Diff line change
@@ -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 {
@@ -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;
@@ -142,6 +149,12 @@ export namespace ProjectInitializationCompleteNotification {
export const type = new lsp.NotificationType(method);
}

export namespace ShowToastNotification {
export const method = 'window/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;