Emmet suggestions in non markup/stylesheet languages #29532

This commit is contained in:
Ramya Achutha Rao
2017-06-28 13:59:28 -07:00
parent e692fc72c6
commit 7ba1dcff0c
6 changed files with 47 additions and 49 deletions

View File

@@ -8,20 +8,25 @@ import parseStylesheet from '@emmetio/css-parser';
import parse from '@emmetio/html-matcher';
import { Node, HtmlNode } from 'EmmetNode';
import { DocumentStreamReader } from './bufferStream';
import { EmmetCompletionItemProvider, isStyleSheet } from 'vscode-emmet-helper';
import { EmmetCompletionItemProvider, isStyleSheet, getEmmetMode } from 'vscode-emmet-helper';
import { isValidLocationForEmmetAbbreviation } from './abbreviationActions';
import { getSyntax, getNode, getInnerRange, getExcludedModes } from './util';
import { getNode, getInnerRange, getMappingForIncludedLanguages } from './util';
export class DefaultCompletionItemProvider implements vscode.CompletionItemProvider {
public provideCompletionItems(document: vscode.TextDocument, position: vscode.Position, token: vscode.CancellationToken): Thenable<vscode.CompletionList> {
let syntax = getSyntax(document);
if (getExcludedModes().indexOf(syntax) > -1) {
return;
}
syntax = this.syntaxHelper(syntax, document, position);
const mappedLanguages = getMappingForIncludedLanguages();
if (!syntax) {
let isSyntaxMapped = mappedLanguages[document.languageId] ? true : false;
let syntax = getEmmetMode(isSyntaxMapped ? mappedLanguages[document.languageId] : document.languageId);
if (document.languageId === 'html' || isStyleSheet(document.languageId)) {
// Document can be html/css parsed
// Use syntaxHelper to parse file, validate location and update sytnax if needed
syntax = this.syntaxHelper(syntax, document, position);
}
if (!syntax || (isSyntaxMapped && vscode.workspace.getConfiguration('emmet')['showExpandedAbbreviation'] !== 'always')) {
return;
}
@@ -30,12 +35,15 @@ export class DefaultCompletionItemProvider implements vscode.CompletionItemProvi
}
/**
* Checks whether given position is valid for emmet abbreviation and returns appropriate syntax
* Parses given document to check whether given position is valid for emmet abbreviation and returns appropriate syntax
* @param syntax string language mode of current document
* @param document vscode.Textdocument
* @param position vscode.Position position of the abbreviation that needs to be expanded
*/
private syntaxHelper(syntax: string, document: vscode.TextDocument, position: vscode.Position): string {
if (!syntax) {
return syntax;
}
let parseContent = isStyleSheet(syntax) ? parseStylesheet : parse;
let rootNode: Node = parseContent(new DocumentStreamReader(document));
let currentNode = getNode(rootNode, position);