Skip to content

Commit f835bdf

Browse files
authored
Merge pull request #202 from dfinke/master
Wired up Show Information|Warning|Error Message
2 parents 21abcb0 + d0bebbb commit f835bdf

File tree

2 files changed

+76
-5
lines changed

2 files changed

+76
-5
lines changed

src/features/ExtensionCommands.ts

+71
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,31 @@ export namespace OpenFileRequest {
122122
{ get method() { return 'editor/openFile'; } };
123123
}
124124

125+
export namespace ShowErrorMessageRequest {
126+
export const type: RequestType<string, EditorOperationResponse, void> =
127+
{ get method() { return 'editor/showErrorMessage'; } };
128+
}
129+
130+
export namespace ShowWarningMessageRequest {
131+
export const type: RequestType<string, EditorOperationResponse, void> =
132+
{ get method() { return 'editor/showWarningMessage'; } };
133+
}
134+
135+
export namespace ShowInformationMessageRequest {
136+
export const type: RequestType<string, EditorOperationResponse, void> =
137+
{ get method() { return 'editor/showInformationMessage'; } };
138+
}
139+
140+
export namespace SetStatusBarMessageRequest {
141+
export const type: RequestType<StatusBarMessageDetails, EditorOperationResponse, void> =
142+
{ get method() { return 'editor/setStatusBarMessage'; } };
143+
}
144+
145+
export interface StatusBarMessageDetails {
146+
message: string;
147+
timeout?: number;
148+
}
149+
125150
export class ExtensionCommandsFeature implements IFeature {
126151

127152
private command: vscode.Disposable;
@@ -172,6 +197,22 @@ export class ExtensionCommandsFeature implements IFeature {
172197
this.languageClient.onRequest(
173198
OpenFileRequest.type,
174199
filePath => this.openFile(filePath));
200+
201+
this.languageClient.onRequest(
202+
ShowInformationMessageRequest.type,
203+
message => this.showInformationMessage(message));
204+
205+
this.languageClient.onRequest(
206+
ShowErrorMessageRequest.type,
207+
message => this.showErrorMessage(message));
208+
209+
this.languageClient.onRequest(
210+
ShowWarningMessageRequest.type,
211+
message => this.showWarningMessage(message));
212+
213+
this.languageClient.onRequest(
214+
SetStatusBarMessageRequest.type,
215+
messageDetails => this.setStatusBarMessage(messageDetails));
175216
}
176217
}
177218

@@ -285,4 +326,34 @@ export class ExtensionCommandsFeature implements IFeature {
285326

286327
return EditorOperationResponse.Completed;
287328
}
329+
330+
private showInformationMessage(message: string): Thenable<EditorOperationResponse> {
331+
return vscode.window
332+
.showInformationMessage(message)
333+
.then(_ => EditorOperationResponse.Completed);
334+
}
335+
336+
private showErrorMessage(message: string): Thenable<EditorOperationResponse> {
337+
return vscode.window
338+
.showErrorMessage(message)
339+
.then(_ => EditorOperationResponse.Completed);
340+
}
341+
342+
private showWarningMessage(message: string): Thenable<EditorOperationResponse> {
343+
return vscode.window
344+
.showWarningMessage(message)
345+
.then(_ => EditorOperationResponse.Completed);
346+
}
347+
348+
private setStatusBarMessage(messageDetails: StatusBarMessageDetails): EditorOperationResponse {
349+
350+
if (messageDetails.timeout) {
351+
vscode.window.setStatusBarMessage(messageDetails.message, messageDetails.timeout);
352+
}
353+
else {
354+
vscode.window.setStatusBarMessage(messageDetails.message);
355+
}
356+
357+
return EditorOperationResponse.Completed;
358+
}
288359
}

src/main.ts

+5-5
Original file line numberDiff line numberDiff line change
@@ -55,27 +55,27 @@ export function activate(context: vscode.ExtensionContext): void {
5555
// e.g. /** | */
5656
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
5757
afterText: /^\s*\*\/$/,
58-
action: { indentAction: IndentAction.IndentOutdent, appendText: ' * ' }
58+
action: { indentAction: vscode.IndentAction.IndentOutdent, appendText: ' * ' }
5959
},
6060
{
6161
// e.g. /** ...|
6262
beforeText: /^\s*\/\*\*(?!\/)([^\*]|\*(?!\/))*$/,
63-
action: { indentAction: IndentAction.None, appendText: ' * ' }
63+
action: { indentAction: vscode.IndentAction.None, appendText: ' * ' }
6464
},
6565
{
6666
// e.g. * ...|
6767
beforeText: /^(\t|(\ \ ))*\ \*(\ ([^\*]|\*(?!\/))*)?$/,
68-
action: { indentAction: IndentAction.None, appendText: '* ' }
68+
action: { indentAction: vscode.IndentAction.None, appendText: '* ' }
6969
},
7070
{
7171
// e.g. */|
7272
beforeText: /^(\t|(\ \ ))*\ \*\/\s*$/,
73-
action: { indentAction: IndentAction.None, removeText: 1 }
73+
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
7474
},
7575
{
7676
// e.g. *-----*/|
7777
beforeText: /^(\t|(\ \ ))*\ \*[^/]*\*\/\s*$/,
78-
action: { indentAction: IndentAction.None, removeText: 1 }
78+
action: { indentAction: vscode.IndentAction.None, removeText: 1 }
7979
}
8080
]
8181
});

0 commit comments

Comments
 (0)