From a4b47f945197588d6b581d206215e927b3d9d2ed Mon Sep 17 00:00:00 2001 From: Ramya Achutha Rao Date: Thu, 10 Aug 2017 18:27:38 -0700 Subject: [PATCH] Return promise from emmet expand method --- extensions/emmet/src/abbreviationActions.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/extensions/emmet/src/abbreviationActions.ts b/extensions/emmet/src/abbreviationActions.ts index c4b77df6514..4bb8908f31d 100644 --- a/extensions/emmet/src/abbreviationActions.ts +++ b/extensions/emmet/src/abbreviationActions.ts @@ -85,14 +85,14 @@ export function wrapIndividualLinesWithAbbreviation(args) { export function expandEmmetAbbreviation(args) { const syntax = getSyntaxFromArgs(args); if (!syntax || !validate()) { - return; + return Promise.resolve(false); } const editor = vscode.window.activeTextEditor; let rootNode = parseDocument(editor.document); if (!rootNode) { - return; + return Promise.resolve(false); } let abbreviationList: ExpandAbbreviationInput[] = []; @@ -119,13 +119,21 @@ export function expandEmmetAbbreviation(args) { return [rangeToReplace, abbr, []]; } } - let { abbreviationRange, abbreviation, filters } = extractAbbreviation(editor.document, position); + let extractedResults = extractAbbreviation(editor.document, position); + if (!extractedResults) { + return [null, '', []]; + } + + let { abbreviationRange, abbreviation, filters } = extractedResults; return [new vscode.Range(abbreviationRange.start.line, abbreviationRange.start.character, abbreviationRange.end.line, abbreviationRange.end.character), abbreviation, filters]; }; editor.selections.forEach(selection => { let position = selection.isReversed ? selection.anchor : selection.active; let [rangeToReplace, abbreviation, filters] = getAbbreviation(editor.document, selection, position, syntax === 'html'); + if (!rangeToReplace) { + return; + } if (!isAbbreviationValid(syntax, abbreviation)) { vscode.window.showErrorMessage('Emmet: Invalid abbreviation'); return; @@ -195,7 +203,7 @@ export function isValidLocationForEmmetAbbreviation(currentNode: Node, syntax: s */ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: ExpandAbbreviationInput[], insertSameSnippet: boolean): Thenable { if (!expandAbbrList || expandAbbrList.length === 0) { - return; + return Promise.resolve(false); } // Snippet to replace at multiple cursors are not the same @@ -223,6 +231,7 @@ function expandAbbreviationInRange(editor: vscode.TextEditor, expandAbbrList: Ex if (expandedText) { return editor.insertSnippet(new vscode.SnippetString(expandedText), allRanges); } + return Promise.resolve(false); } /** -- GitLab