mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-23 18:19:12 +01:00
Emmet suggestions in non markup/stylesheet languages #29532
This commit is contained in:
@@ -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);
|
||||
|
||||
Reference in New Issue
Block a user