提交 9efac599 编写于 作者: P Pine Wu

Improve custom data reading

上级 70696746
......@@ -11,6 +11,7 @@ const localize = nls.loadMessageBundle();
import { languages, window, commands, ExtensionContext, Range, Position, CompletionItem, CompletionItemKind, TextEdit, SnippetString, workspace } from 'vscode';
import { LanguageClient, LanguageClientOptions, ServerOptions, TransportKind, Disposable } from 'vscode-languageclient';
import { getCustomDataPathsInAllWorkspaces } from './customData';
// this method is called when vs code is activated
export function activate(context: ExtensionContext) {
......@@ -30,21 +31,7 @@ export function activate(context: ExtensionContext) {
let documentSelector = ['css', 'scss', 'less'];
let dataPaths: string[] = workspace.getConfiguration('css').get('experimental.customData', []);
if (dataPaths && dataPaths.length > 0) {
if (!workspace.workspaceFolders) {
dataPaths = [];
} else {
try {
const workspaceRoot = workspace.workspaceFolders[0].uri.fsPath;
dataPaths = dataPaths.map(d => {
return path.resolve(workspaceRoot, d);
});
} catch (err) {
dataPaths = [];
}
}
}
let dataPaths = getCustomDataPathsInAllWorkspaces(workspace.workspaceFolders);
// Options to control the language client
let clientOptions: LanguageClientOptions = {
......
/*---------------------------------------------------------------------------------------------
* 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?: {
customData?: string[]
};
}
export function getCustomDataPathsInAllWorkspaces(workspaceFolders: WorkspaceFolder[] | undefined): string[] {
const dataPaths: string[] = [];
if (!workspaceFolders) {
return dataPaths;
}
workspaceFolders.forEach(wf => {
const allCssConfig = workspace.getConfiguration(undefined, wf.uri);
const wfCSSConfig = allCssConfig.inspect<ExperimentalConfig>('css');
if (
wfCSSConfig &&
wfCSSConfig.workspaceFolderValue &&
wfCSSConfig.workspaceFolderValue.experimental &&
wfCSSConfig.workspaceFolderValue.experimental.customData
) {
wfCSSConfig.workspaceFolderValue.experimental.customData.forEach(p => [
dataPaths.push(path.resolve(wf.uri.fsPath, p))
]);
}
});
return dataPaths;
}
......@@ -34,7 +34,9 @@
"properties": {
"css.experimental.customData": {
"type": "array",
"description": "A list of JSON file paths that define custom CSS data that loads custom properties, at directives, pseudo classes / elements."
"description": "A list of JSON file paths that define custom CSS data that loads custom properties, at directives, pseudo classes / elements.",
"default": [],
"scope": "resource"
},
"css.validate": {
"type": "boolean",
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册