mirror of
https://github.com/microsoft/vscode.git
synced 2026-05-23 00:29:35 +01:00
Use await
This commit is contained in:
@@ -75,28 +75,30 @@ export class TypeScriptFormattingProvider implements DocumentRangeFormattingEdit
|
||||
if (!filepath) {
|
||||
return [];
|
||||
}
|
||||
|
||||
await this.formattingOptionsManager.ensureFormatOptions(document, options, token);
|
||||
|
||||
const args: Proto.FormatOnKeyRequestArgs = {
|
||||
file: filepath,
|
||||
line: position.line + 1,
|
||||
offset: position.character + 1,
|
||||
key: ch
|
||||
};
|
||||
|
||||
await this.formattingOptionsManager.ensureFormatOptions(document, options, token);
|
||||
return this.client.execute('formatonkey', args, token).then((response): TextEdit[] => {
|
||||
let edits = response.body;
|
||||
let result: TextEdit[] = [];
|
||||
try {
|
||||
const response = await this.client.execute('formatonkey', args, token);
|
||||
const edits = response.body;
|
||||
const result: TextEdit[] = [];
|
||||
if (!edits) {
|
||||
return result;
|
||||
}
|
||||
for (const edit of edits) {
|
||||
let textEdit = this.codeEdit2SingleEditOperation(edit);
|
||||
let range = textEdit.range;
|
||||
const textEdit = this.codeEdit2SingleEditOperation(edit);
|
||||
const range = textEdit.range;
|
||||
// Work around for https://github.com/Microsoft/TypeScript/issues/6700.
|
||||
// Check if we have an edit at the beginning of the line which only removes white spaces and leaves
|
||||
// an empty line. Drop those edits
|
||||
if (range.start.character === 0 && range.start.line === range.end.line && textEdit.newText === '') {
|
||||
let lText = document.lineAt(range.start.line).text;
|
||||
const lText = document.lineAt(range.start.line).text;
|
||||
// If the edit leaves something on the line keep the edit (note that the end character is exclusive).
|
||||
// Keep it also if it removes something else than whitespace
|
||||
if (lText.trim().length > 0 || lText.length > range.end.character) {
|
||||
@@ -107,9 +109,10 @@ export class TypeScriptFormattingProvider implements DocumentRangeFormattingEdit
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}, () => {
|
||||
return [];
|
||||
});
|
||||
} catch {
|
||||
// noop
|
||||
}
|
||||
return [];
|
||||
}
|
||||
|
||||
private codeEdit2SingleEditOperation(edit: Proto.CodeEdit): TextEdit {
|
||||
|
||||
Reference in New Issue
Block a user