diff --git a/extensions/html-language-features/client/src/customData.ts b/extensions/html-language-features/client/src/customData.ts new file mode 100644 index 00000000000..5e7c1c99c16 --- /dev/null +++ b/extensions/html-language-features/client/src/customData.ts @@ -0,0 +1,56 @@ +/*--------------------------------------------------------------------------------------------- + * Copyright (c) Microsoft Corporation. All rights reserved. + * Licensed under the MIT License. See License.txt in the project root for license information. + *--------------------------------------------------------------------------------------------*/ + +import * as path from 'path'; +import { workspace, WorkspaceFolder } from 'vscode'; + +interface ExperimentalConfig { + experimental?: { + custom?: { + tags?: string[]; + attributes?: string[]; + } + }; +} + +export function getCustomDataPathsInAllWorkspaces(workspaceFolders: WorkspaceFolder[] | undefined) { + const tagPaths: string[] = []; + const attributePaths: string[] = []; + + if (!workspaceFolders) { + return { + tagPaths, + attributePaths + }; + } + + workspaceFolders.forEach(wf => { + const allHtmlConfig = workspace.getConfiguration(undefined, wf.uri); + const wfHtmlConfig = allHtmlConfig.inspect('html'); + + if ( + wfHtmlConfig && + wfHtmlConfig.workspaceFolderValue && + wfHtmlConfig.workspaceFolderValue.experimental && + wfHtmlConfig.workspaceFolderValue.experimental.custom + ) { + if (wfHtmlConfig.workspaceFolderValue.experimental.custom.tags) { + wfHtmlConfig.workspaceFolderValue.experimental.custom.tags.forEach(t => { + tagPaths.push(path.resolve(wf.uri.fsPath, t)); + }); + } + if (wfHtmlConfig.workspaceFolderValue.experimental.custom.attributes) { + wfHtmlConfig.workspaceFolderValue.experimental.custom.attributes.forEach(a => { + attributePaths.push(path.resolve(wf.uri.fsPath, a)); + }); + } + } + }); + + return { + tagPaths, + attributePaths + }; +} diff --git a/extensions/html-language-features/client/src/htmlMain.ts b/extensions/html-language-features/client/src/htmlMain.ts index 0b84091bed7..0b4a33b776b 100644 --- a/extensions/html-language-features/client/src/htmlMain.ts +++ b/extensions/html-language-features/client/src/htmlMain.ts @@ -13,6 +13,7 @@ import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Re import { EMPTY_ELEMENTS } from './htmlEmptyTagsShared'; import { activateTagClosing } from './tagClosing'; import TelemetryReporter from 'vscode-extension-telemetry'; +import { getCustomDataPathsInAllWorkspaces } from './customData'; namespace TagCloseRequest { export const type: RequestType = new RequestType('html/tag'); @@ -49,23 +50,7 @@ export function activate(context: ExtensionContext) { let documentSelector = ['html', 'handlebars', 'razor']; let embeddedLanguages = { css: true, javascript: true }; - let tagPaths: string[] = workspace.getConfiguration('html').get('experimental.custom.tags', []); - let attributePaths: string[] = workspace.getConfiguration('html').get('experimental.custom.attributes', []); - - if (tagPaths && tagPaths.length > 0) { - if (!workspace.workspaceFolders) { - tagPaths = []; - } else { - try { - const workspaceRoot = workspace.workspaceFolders[0].uri.fsPath; - tagPaths = tagPaths.map(d => { - return path.resolve(workspaceRoot, d); - }); - } catch (err) { - tagPaths = []; - } - } - } + let { tagPaths, attributePaths } = getCustomDataPathsInAllWorkspaces(workspace.workspaceFolders); // Options to control the language client let clientOptions: LanguageClientOptions = { diff --git a/extensions/html-language-features/package.json b/extensions/html-language-features/package.json index 01299004ebb..ca3320124e5 100644 --- a/extensions/html-language-features/package.json +++ b/extensions/html-language-features/package.json @@ -33,11 +33,11 @@ "properties": { "html.experimental.custom.tags": { "type": "array", - "description": "A list of JSON file paths that define custom tags." + "description": "A list of JSON file paths that define custom tags. Only workspace folder setting will be read." }, "html.experimental.custom.attributes": { "type": "array", - "description": "A list of JSON file paths that define custom attributes." + "description": "A list of JSON file paths that define custom attributes. Only workspace folder setting will be read." }, "html.format.enable": { "type": "boolean",