diff --git a/extensions/css-language-features/package.json b/extensions/css-language-features/package.json index 4c46a1391c9fb..1021c7b2f98c8 100644 --- a/extensions/css-language-features/package.json +++ b/extensions/css-language-features/package.json @@ -66,6 +66,20 @@ "default": true, "description": "%css.validate.desc%" }, + "css.importAliases": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^[^/]+(/)?$": { + "type": "string", + "pattern": "((\\.css)|/)$", + "patternErrorMessage": "Path must end with stylesheet filetype or forward slash" + } + }, + "scope": "resource", + "default": null, + "description": "%css.importAliases%" + }, "css.hover.documentation": { "type": "boolean", "scope": "resource", @@ -382,6 +396,20 @@ "default": true, "description": "%scss.validate.desc%" }, + "scss.importAliases": { + "type": "object", + "additionalProperties": false, + "patternProperties": { + "^[^/]+(/)?$": { + "type": "string", + "pattern": "((\\.s?css)|/)$", + "patternErrorMessage": "Path must end with stylesheet filetype or forward slash" + } + }, + "scope": "resource", + "default": null, + "description": "%scss.importAliases%" + }, "scss.hover.documentation": { "type": "boolean", "scope": "resource", diff --git a/extensions/css-language-features/package.nls.json b/extensions/css-language-features/package.nls.json index 057ec214bc2f8..ff794d02bd5a6 100644 --- a/extensions/css-language-features/package.nls.json +++ b/extensions/css-language-features/package.nls.json @@ -2,6 +2,7 @@ "displayName": "CSS Language Features", "description": "Provides rich language support for CSS, LESS and SCSS files.", "css.title": "CSS", + "css.importAliases": "Defines path aliases for @import statements. Each key represents an alias and each value a file or folder path. Paths are resolved relative to the .vscode folder containing the settings file. In multi-root or monorepo workspaces, each folder can define its own aliases independently; an alias in workspace settings take priority over the same alias in nested settings.", "css.customData.desc": "A list of relative file paths pointing to JSON files following the [custom data format](https://github.com/microsoft/vscode-css-languageservice/blob/master/docs/customData.md).\n\nVS Code loads custom data on startup to enhance its CSS support for CSS custom properties (variables), at-rules, pseudo-classes, and pseudo-elements you specify in the JSON files.\n\nThe file paths are relative to workspace and only workspace folder settings are considered.", "css.completion.triggerPropertyValueCompletion.desc": "By default, VS Code triggers property value completion after selecting a CSS property. Use this setting to disable this behavior.", "css.completion.completePropertyWithSemicolon.desc": "Insert semicolon at end of line when completing CSS properties.", @@ -72,6 +73,7 @@ "less.format.preserveNewLines.desc": "Whether existing line breaks before rules and declarations should be preserved.", "less.format.maxPreserveNewLines.desc": "Maximum number of line breaks to be preserved in one chunk, when `#less.format.preserveNewLines#` is enabled.", "scss.title": "SCSS (Sass)", + "scss.importAliases": "Defines path aliases for @import/@use statements. Each key represents an alias and each value a file or folder path. Paths are resolved relative to the .vscode folder containing the settings file. In multi-root or monorepo workspaces, each folder can define its own aliases independently; an alias in workspace settings take priority over the same alias in nested settings.", "scss.completion.triggerPropertyValueCompletion.desc": "By default, VS Code triggers property value completion after selecting a CSS property. Use this setting to disable this behavior.", "scss.completion.completePropertyWithSemicolon.desc": "Insert semicolon at end of line when completing CSS properties.", "scss.lint.argumentsInColorFunction.desc": "Invalid number of parameters.", diff --git a/extensions/css-language-features/server/src/cssServer.ts b/extensions/css-language-features/server/src/cssServer.ts index c3ab75519c3e0..21a6a000bfa64 100644 --- a/extensions/css-language-features/server/src/cssServer.ts +++ b/extensions/css-language-features/server/src/cssServer.ts @@ -175,6 +175,7 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment) function updateConfiguration(settings: any) { for (const languageId in languageServices) { languageServices[languageId].configure(settings[languageId]); + languageServices[languageId].clearCache(); } // reset all document settings documentSettings = {}; @@ -238,9 +239,19 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment) return runSafeAsync(runtime, async () => { const document = documents.get(documentDefinitionParams.textDocument.uri); if (document) { - await dataProvidersReady; + const [settings] = await Promise.all([ + getDocumentSettings(document), + dataProvidersReady + ]); + const languageService = getLanguageService(document); + + // Apply per-document configuration + if (settings) { + languageService.configure(settings); + } + const stylesheet = stylesheets.get(document); - return getLanguageService(document).findDefinition(document, documentDefinitionParams.position, stylesheet); + return languageService.findDefinition(document, documentDefinitionParams.position, stylesheet); } return null; }, null, `Error while computing definitions for ${documentDefinitionParams.textDocument.uri}`, token); @@ -263,10 +274,19 @@ export function startServer(connection: Connection, runtime: RuntimeEnvironment) return runSafeAsync(runtime, async () => { const document = documents.get(documentLinkParams.textDocument.uri); if (document) { - await dataProvidersReady; + const settingsPromise = getDocumentSettings(document); + const [settings] = await Promise.all([settingsPromise, dataProvidersReady]); + + const languageService = getLanguageService(document); + + // Apply per-document configuration + if (settings) { + languageService.configure(settings); + } + const documentContext = getDocumentContext(document.uri, workspaceFolders); const stylesheet = stylesheets.get(document); - return getLanguageService(document).findDocumentLinks2(document, stylesheet, documentContext); + return languageService.findDocumentLinks2(document, stylesheet, documentContext); } return []; }, [], `Error while computing document links for ${documentLinkParams.textDocument.uri}`, token);