提交 fadd172c 编写于 作者: R Ramya Achutha Rao

Avoid emmet expansion inside html tag and css selectors. Fixes #28829

上级 47de9b40
......@@ -6,7 +6,11 @@
import * as vscode from 'vscode';
import { expand, createSnippetsRegistry } from '@emmetio/expand-abbreviation';
import { getSyntax, getProfile, extractAbbreviation, isStyleSheet } from './util';
import { getSyntax, getProfile, extractAbbreviation, isStyleSheet, getNode } from './util';
import parseStylesheet from '@emmetio/css-parser';
import parse from '@emmetio/html-matcher';
import Node from '@emmetio/node';
import { DocumentStreamReader } from './bufferStream';
const field = (index, placeholder) => `\${${index}${placeholder ? ':' + placeholder : ''}}`;
const snippetCompletionsCache = new Map<string, vscode.CompletionItem[]>();
......@@ -22,7 +26,11 @@ export class EmmetCompletionItemProvider implements vscode.CompletionItemProvide
let completionItems: vscode.CompletionItem[] = [];
let syntax = getSyntax(document);
let currentWord = getCurrentWord(document, position);
let expandedAbbr = this.getExpandedAbbreviation(document, position);
let parseContent = isStyleSheet(syntax) ? parseStylesheet : parse;
let rootNode: Node = parseContent(new DocumentStreamReader(document));
let currentNode = getNode(rootNode, position);
let expandedAbbr = this.getExpandedAbbreviation(document, position, syntax, currentNode);
if (!isStyleSheet(syntax)) {
if (expandedAbbr) {
......@@ -39,7 +47,7 @@ export class EmmetCompletionItemProvider implements vscode.CompletionItemProvide
return Promise.resolve(new vscode.CompletionList(completionItems, true));
}
getExpandedAbbreviation(document: vscode.TextDocument, position: vscode.Position): vscode.CompletionItem {
getExpandedAbbreviation(document: vscode.TextDocument, position: vscode.Position, syntax: string, currentNode: Node): vscode.CompletionItem {
if (!vscode.workspace.getConfiguration('emmet')['showExpandedAbbreviation']) {
return;
}
......@@ -47,7 +55,10 @@ export class EmmetCompletionItemProvider implements vscode.CompletionItemProvide
if (!rangeToReplace || !wordToExpand) {
return;
}
let syntax = getSyntax(document);
if (!isValidLocationForEmmetAbbreviation(currentNode, syntax, position)) {
return;
}
let expandedWord = expand(wordToExpand, {
field: field,
syntax: syntax,
......@@ -114,6 +125,17 @@ function removeTabStops(expandedWord: string): string {
return expandedWord.replace(/\$\{\d+\}/g, '').replace(/\$\{\d+:([^\}]+)\}/g, '$1');
}
function isValidLocationForEmmetAbbreviation(currentNode: Node, syntax: string, position: vscode.Position): boolean {
if (!currentNode) {
return true;
}
if (isStyleSheet(syntax)) {
return currentNode.type !== 'rule';
}
return position.isAfter(currentNode.open.end);
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册