Skip to content

Commit b484824

Browse files
author
James Pogran
authored
Merge pull request #394 from glennsarti/fix-minor-errors
(maint) Convert FormatDocumentProvider to async function
2 parents a381afb + 3adab02 commit b484824

File tree

1 file changed

+15
-19
lines changed

1 file changed

+15
-19
lines changed

src/feature/FormatDocumentFeature.ts

Lines changed: 15 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -16,32 +16,27 @@ class RequestParams implements messages.PuppetFixDiagnosticErrorsRequestParams {
1616
class FormatDocumentProvider {
1717
private connectionManager: IConnectionManager = undefined;
1818

19-
constructor(connectionManager:IConnectionManager) {
19+
constructor(connectionManager: IConnectionManager) {
2020
this.connectionManager = connectionManager;
2121
}
2222

23-
public formatTextEdits(document: vscode.TextDocument, options:vscode.FormattingOptions) : Thenable<vscode.TextEdit[]> {
24-
if (this.connectionManager.status !== ConnectionStatus.Running ) {
23+
public async formatTextEdits(document: vscode.TextDocument, options: vscode.FormattingOptions): Promise<vscode.TextEdit[]> {
24+
if (this.connectionManager.status !== ConnectionStatus.Running) {
2525
vscode.window.showInformationMessage("Please wait and try again. The Puppet extension is still loading...");
26-
return new Promise((resolve) => { resolve([]); });
26+
return [];
2727
}
28-
28+
2929
let requestParams = new RequestParams;
3030
requestParams.documentUri = document.uri.toString(false);
3131
requestParams.alwaysReturnContent = false;
32-
33-
return this.connectionManager.languageClient
34-
.sendRequest(messages.PuppetFixDiagnosticErrorsRequest.type, requestParams)
35-
.then(
36-
(result) => {
37-
result = result as messages.PuppetFixDiagnosticErrorsResponse;
38-
if (result.fixesApplied > 0 && result.newContent != null) {
39-
return [vscode.TextEdit.replace(new vscode.Range(0,0, document.lineCount,0), result.newContent)]
40-
} else {
41-
return []
42-
}
43-
}
44-
);
32+
33+
const result = await this.connectionManager
34+
.languageClient
35+
.sendRequest(messages.PuppetFixDiagnosticErrorsRequest.type, requestParams) as messages.PuppetFixDiagnosticErrorsResponse;
36+
if (result.fixesApplied > 0 && result.newContent !== undefined) {
37+
return [vscode.TextEdit.replace(new vscode.Range(0, 0, document.lineCount, 0), result.newContent)];
38+
}
39+
return [];
4540
}
4641
}
4742

@@ -60,7 +55,8 @@ export class FormatDocumentFeature implements IFeature {
6055
if (settings.format.enable === true) {
6156
logger.debug("Registered Format Document provider");
6257
context.subscriptions.push(vscode.languages.registerDocumentFormattingEditProvider(langID, {
63-
provideDocumentFormattingEdits: (document, options, token) => { return this.provider.formatTextEdits(document, options); }}
58+
provideDocumentFormattingEdits: (document, options, token) => { return this.provider.formatTextEdits(document, options); }
59+
}
6460
));
6561
} else {
6662
logger.debug("Format Document provider has not been registered");

0 commit comments

Comments
 (0)