Skip to content

Wired up Show Information|Warning|Error Message #202

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

Merged
merged 3 commits into from
Dec 7, 2016
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
71 changes: 71 additions & 0 deletions src/features/ExtensionCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,31 @@ export namespace OpenFileRequest {
{ get method() { return 'editor/openFile'; } };
}

export namespace ShowErrorMessageRequest {
export const type: RequestType<string, EditorOperationResponse, void> =
{ get method() { return 'editor/showErrorMessage'; } };
}

export namespace ShowWarningMessageRequest {
export const type: RequestType<string, EditorOperationResponse, void> =
{ get method() { return 'editor/showWarningMessage'; } };
}

export namespace ShowInformationMessageRequest {
export const type: RequestType<string, EditorOperationResponse, void> =
{ get method() { return 'editor/showInformationMessage'; } };
}

export namespace SetStatusBarMessageRequest {
export const type: RequestType<StatusBarMessageDetails, EditorOperationResponse, void> =
{ get method() { return 'editor/setStatusBarMessage'; } };
}

export interface StatusBarMessageDetails {
message: string;
timeout?: number;
}

export class ExtensionCommandsFeature implements IFeature {

private command: vscode.Disposable;
Expand Down Expand Up @@ -172,6 +197,22 @@ export class ExtensionCommandsFeature implements IFeature {
this.languageClient.onRequest(
OpenFileRequest.type,
filePath => this.openFile(filePath));

this.languageClient.onRequest(
ShowInformationMessageRequest.type,
message => this.showInformationMessage(message));

this.languageClient.onRequest(
ShowErrorMessageRequest.type,
message => this.showErrorMessage(message));

this.languageClient.onRequest(
ShowWarningMessageRequest.type,
message => this.showWarningMessage(message));

this.languageClient.onRequest(
SetStatusBarMessageRequest.type,
messageDetails => this.setStatusBarMessage(messageDetails));
}
}

Expand Down Expand Up @@ -285,4 +326,34 @@ export class ExtensionCommandsFeature implements IFeature {

return EditorOperationResponse.Completed;
}

private showInformationMessage(message: string): Thenable<EditorOperationResponse> {
return vscode.window
.showInformationMessage(message)
.then(_ => EditorOperationResponse.Completed);
}

private showErrorMessage(message: string): Thenable<EditorOperationResponse> {
return vscode.window
.showErrorMessage(message)
.then(_ => EditorOperationResponse.Completed);
}

private showWarningMessage(message: string): Thenable<EditorOperationResponse> {
return vscode.window
.showWarningMessage(message)
.then(_ => EditorOperationResponse.Completed);
}

private setStatusBarMessage(messageDetails: StatusBarMessageDetails): EditorOperationResponse {

if (messageDetails.timeout) {
vscode.window.setStatusBarMessage(messageDetails.message, messageDetails.timeout);
}
else {
vscode.window.setStatusBarMessage(messageDetails.message);
}

return EditorOperationResponse.Completed;
}
}
10 changes: 5 additions & 5 deletions src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,27 +55,27 @@ export function activate(context: vscode.ExtensionContext): void {
// e.g. /** | */
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
afterText: /^\s*\*\/$/,
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
action: { indentAction: vscode.IndentAction.IndentOutdent, appendText: ' * ' }
},
{
// e.g. /** ...|
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
action: { indentAction: IndentAction.None, appendText: ' * ' }
action: { indentAction: vscode.IndentAction.None, appendText: ' * ' }
},
{
// e.g. * ...|
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
action: { indentAction: IndentAction.None, appendText: '* ' }
action: { indentAction: vscode.IndentAction.None, appendText: '* ' }
},
{
// e.g. */|
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
},
{
// e.g. *-----*/|
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
action: { indentAction: IndentAction.None, removeText: 1 }
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
}
]
});
Expand Down