mirror of
https://github.com/Microsoft/vscode
synced 2024-08-27 21:09:43 +00:00
* Allow css emmet completions when abbr contains period Fixes #44352 * Move css related workaround to cssMode #44352 * getEmbeddedParsedDocument is now not needed * Show emmet completions everywhere inside the embedded css doc
This commit is contained in:
parent
b3a1b98d54
commit
d7dca142ad
|
@ -9,7 +9,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"vscode-css-languageservice": "^3.0.7",
|
||||
"vscode-emmet-helper": "^1.1.38",
|
||||
"vscode-emmet-helper": "^1.2.0",
|
||||
"vscode-languageserver": "4.0.0-next.4"
|
||||
},
|
||||
"devDependencies": {
|
||||
|
|
|
@ -25,9 +25,9 @@ vscode-css-languageservice@^3.0.7:
|
|||
vscode-languageserver-types "^3.6.0-next.1"
|
||||
vscode-nls "^2.0.1"
|
||||
|
||||
vscode-emmet-helper@^1.1.38:
|
||||
version "1.1.38"
|
||||
resolved "https://registry.yarnpkg.com/vscode-emmet-helper/-/vscode-emmet-helper-1.1.38.tgz#6b7de1abe39f8b41d4713c4e85ace4a7261ef0d8"
|
||||
vscode-emmet-helper@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-emmet-helper/-/vscode-emmet-helper-1.2.0.tgz#6b9311be065c9c99d5de2dae18ea0730d9cfb734"
|
||||
dependencies:
|
||||
"@emmetio/extract-abbreviation" "0.1.6"
|
||||
jsonc-parser "^1.0.0"
|
||||
|
|
|
@ -338,7 +338,7 @@
|
|||
"@emmetio/html-matcher": "^0.3.3",
|
||||
"@emmetio/css-parser": "ramya-rao-a/css-parser#vscode",
|
||||
"@emmetio/math-expression": "^0.1.1",
|
||||
"vscode-emmet-helper": "^1.1.38",
|
||||
"vscode-emmet-helper": "^1.2.0",
|
||||
"vscode-languageserver-types": "^3.5.0",
|
||||
"image-size": "^0.5.2",
|
||||
"vscode-nls": "3.2.1"
|
||||
|
|
|
@ -2052,9 +2052,9 @@ vinyl@~2.0.1:
|
|||
remove-trailing-separator "^1.0.1"
|
||||
replace-ext "^1.0.0"
|
||||
|
||||
vscode-emmet-helper@^1.1.38:
|
||||
version "1.1.38"
|
||||
resolved "https://registry.yarnpkg.com/vscode-emmet-helper/-/vscode-emmet-helper-1.1.38.tgz#6b7de1abe39f8b41d4713c4e85ace4a7261ef0d8"
|
||||
vscode-emmet-helper@^1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-emmet-helper/-/vscode-emmet-helper-1.2.0.tgz#6b9311be065c9c99d5de2dae18ea0730d9cfb734"
|
||||
dependencies:
|
||||
"@emmetio/extract-abbreviation" "0.1.6"
|
||||
jsonc-parser "^1.0.0"
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
},
|
||||
"dependencies": {
|
||||
"vscode-css-languageservice": "^3.0.6",
|
||||
"vscode-emmet-helper": "1.1.38",
|
||||
"vscode-emmet-helper": "1.2.0",
|
||||
"vscode-html-languageservice": "^2.0.17-next.3",
|
||||
"vscode-languageserver": "4.0.0-next.4",
|
||||
"vscode-languageserver-types": "^3.6.0-next.1",
|
||||
|
|
|
@ -284,21 +284,17 @@ connection.onCompletion(async textDocumentPosition => {
|
|||
items: []
|
||||
};
|
||||
|
||||
if (mode.setCompletionParticipants) {
|
||||
const emmetCompletionParticipant = getEmmetCompletionParticipants(document, textDocumentPosition.position, mode.getId(), emmetSettings, emmetCompletionList);
|
||||
const emmetCompletionParticipant = getEmmetCompletionParticipants(document, textDocumentPosition.position, mode.getId(), emmetSettings, emmetCompletionList);
|
||||
const completionParticipants = [emmetCompletionParticipant];
|
||||
// Ideally, fix this in the Language Service side
|
||||
// Check participants' methods before calling them
|
||||
if (mode.getId() === 'html') {
|
||||
const pathCompletionParticipant = getPathCompletionParticipant(document, workspaceFolders, pathCompletionList);
|
||||
|
||||
// Ideally, fix this in the Language Service side
|
||||
// Check participants' methods before calling them
|
||||
if (mode.getId() === 'html') {
|
||||
mode.setCompletionParticipants([emmetCompletionParticipant, pathCompletionParticipant]);
|
||||
} else {
|
||||
mode.setCompletionParticipants([emmetCompletionParticipant]);
|
||||
}
|
||||
completionParticipants.push(pathCompletionParticipant);
|
||||
}
|
||||
|
||||
let settings = await getDocumentSettings(document, () => mode.doComplete.length > 2);
|
||||
let result = mode.doComplete(document, textDocumentPosition.position, settings);
|
||||
let result = mode.doComplete(document, textDocumentPosition.position, settings, completionParticipants);
|
||||
result.items = [...pathCompletionList.items, ...result.items];
|
||||
if (emmetCompletionList && emmetCompletionList.items) {
|
||||
cachedCompletionList = result;
|
||||
|
|
|
@ -10,6 +10,7 @@ import { getCSSLanguageService, Stylesheet, ICompletionParticipant } from 'vscod
|
|||
import { LanguageMode, Settings } from './languageModes';
|
||||
import { HTMLDocumentRegions, CSS_STYLE_RULE } from './embeddedSupport';
|
||||
import { Color } from 'vscode-languageserver-protocol/lib/protocol.colorProvider.proposed';
|
||||
import { extractAbbreviation } from 'vscode-emmet-helper';
|
||||
|
||||
export function getCSSMode(documentRegions: LanguageModelCache<HTMLDocumentRegions>): LanguageMode {
|
||||
let cssLanguageService = getCSSLanguageService();
|
||||
|
@ -27,9 +28,27 @@ export function getCSSMode(documentRegions: LanguageModelCache<HTMLDocumentRegio
|
|||
let embedded = embeddedCSSDocuments.get(document);
|
||||
return cssLanguageService.doValidation(embedded, cssStylesheets.get(embedded), settings && settings.css);
|
||||
},
|
||||
doComplete(document: TextDocument, position: Position) {
|
||||
doComplete(document: TextDocument, position: Position, settings: Settings, registeredCompletionParticipants: ICompletionParticipant[]) {
|
||||
let embedded = embeddedCSSDocuments.get(document);
|
||||
return cssLanguageService.doComplete(embedded, position, cssStylesheets.get(embedded));
|
||||
const stylesheet = cssStylesheets.get(embedded);
|
||||
|
||||
if (registeredCompletionParticipants) {
|
||||
const nonEmmetCompletionParticipants = [];
|
||||
// Css Emmet completions in html files are provided no matter where the cursor is inside the embedded css document
|
||||
// Mimic the same here, until we solve the issue of css language service not able to parse complete embedded documents when there are errors
|
||||
for (let i = 0; i < registeredCompletionParticipants.length; i++) {
|
||||
if (typeof (<any>registeredCompletionParticipants[i]).getId === 'function' && (<any>registeredCompletionParticipants[i]).getId() === 'emmet') {
|
||||
const extractedResults = extractAbbreviation(document, position, { lookAhead: false, syntax: 'css' });
|
||||
if (extractedResults && extractedResults.abbreviation) {
|
||||
registeredCompletionParticipants[i].onCssProperty({ propertyName: extractedResults.abbreviation, range: extractedResults.abbreviationRange });
|
||||
}
|
||||
} else {
|
||||
nonEmmetCompletionParticipants.push(registeredCompletionParticipants[i]);
|
||||
}
|
||||
}
|
||||
cssLanguageService.setCompletionParticipants(nonEmmetCompletionParticipants);
|
||||
}
|
||||
return cssLanguageService.doComplete(embedded, position, stylesheet);
|
||||
},
|
||||
setCompletionParticipants(registeredCompletionParticipants: ICompletionParticipant[]) {
|
||||
cssLanguageService.setCompletionParticipants(registeredCompletionParticipants);
|
||||
|
|
|
@ -22,7 +22,10 @@ export function getHTMLMode(htmlLanguageService: HTMLLanguageService): LanguageM
|
|||
configure(options: any) {
|
||||
globalSettings = options;
|
||||
},
|
||||
doComplete(document: TextDocument, position: Position, settings: Settings = globalSettings) {
|
||||
doComplete(document: TextDocument, position: Position, settings: Settings = globalSettings, registeredCompletionParticipants: any[]) {
|
||||
if (registeredCompletionParticipants) {
|
||||
completionParticipants = registeredCompletionParticipants;
|
||||
}
|
||||
let options = settings && settings.html && settings.html.suggest;
|
||||
let doAutoComplete = settings && settings.html && settings.html.autoClosingTags;
|
||||
if (doAutoComplete) {
|
||||
|
|
|
@ -37,7 +37,7 @@ export interface LanguageMode {
|
|||
getId(): string;
|
||||
configure?: (options: Settings) => void;
|
||||
doValidation?: (document: TextDocument, settings?: Settings) => Diagnostic[];
|
||||
doComplete?: (document: TextDocument, position: Position, settings?: Settings) => CompletionList | null;
|
||||
doComplete?: (document: TextDocument, position: Position, settings?: Settings, registeredCompletionParticipants?: any[]) => CompletionList | null;
|
||||
setCompletionParticipants?: (registeredCompletionParticipants: any[]) => void;
|
||||
doResolve?: (document: TextDocument, item: CompletionItem) => CompletionItem | null;
|
||||
doHover?: (document: TextDocument, position: Position) => Hover | null;
|
||||
|
|
|
@ -25,9 +25,9 @@ vscode-css-languageservice@^3.0.6:
|
|||
vscode-languageserver-types "^3.6.0-next.1"
|
||||
vscode-nls "^2.0.1"
|
||||
|
||||
vscode-emmet-helper@1.1.38:
|
||||
version "1.1.38"
|
||||
resolved "https://registry.yarnpkg.com/vscode-emmet-helper/-/vscode-emmet-helper-1.1.38.tgz#6b7de1abe39f8b41d4713c4e85ace4a7261ef0d8"
|
||||
vscode-emmet-helper@1.2.0:
|
||||
version "1.2.0"
|
||||
resolved "https://registry.yarnpkg.com/vscode-emmet-helper/-/vscode-emmet-helper-1.2.0.tgz#6b9311be065c9c99d5de2dae18ea0730d9cfb734"
|
||||
dependencies:
|
||||
"@emmetio/extract-abbreviation" "0.1.6"
|
||||
jsonc-parser "^1.0.0"
|
||||
|
|
Loading…
Reference in a new issue