mirror of
https://github.com/microsoft/vscode.git
synced 2025-12-24 20:26:08 +00:00
Improve custom data reading
This commit is contained in:
@@ -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 = {
|
||||
|
||||
39
extensions/css-language-features/client/src/customData.ts
Normal file
39
extensions/css-language-features/client/src/customData.ts
Normal file
@@ -0,0 +1,39 @@
|
||||
/*---------------------------------------------------------------------------------------------
|
||||
* 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",
|
||||
|
||||
Reference in New Issue
Block a user