mirror of
https://github.com/microsoft/vscode.git
synced 2026-04-19 16:18:58 +01:00
Allow to run css language server headless
This commit is contained in:
@@ -3,42 +3,78 @@
|
||||
* Licensed under the MIT License. See License.txt in the project root for license information.
|
||||
*--------------------------------------------------------------------------------------------*/
|
||||
|
||||
import * as path from 'path';
|
||||
import { workspace, WorkspaceFolder, extensions } from 'vscode';
|
||||
import { workspace, extensions, Uri, EventEmitter, Disposable } from 'vscode';
|
||||
import { resolvePath } from './requests';
|
||||
|
||||
interface ExperimentalConfig {
|
||||
customData?: string[];
|
||||
experimental?: {
|
||||
customData?: string[];
|
||||
export function getCustomDataSource(toDispose: Disposable[]) {
|
||||
let pathsInWorkspace = getCustomDataPathsInAllWorkspaces();
|
||||
let pathsInExtensions = getCustomDataPathsFromAllExtensions();
|
||||
|
||||
const onChange = new EventEmitter<void>();
|
||||
|
||||
toDispose.push(extensions.onDidChange(_ => {
|
||||
const newPathsInExtensions = getCustomDataPathsFromAllExtensions();
|
||||
if (newPathsInExtensions.length !== pathsInExtensions.length || !newPathsInExtensions.every((val, idx) => val === pathsInExtensions[idx])) {
|
||||
pathsInExtensions = newPathsInExtensions;
|
||||
onChange.fire();
|
||||
}
|
||||
}));
|
||||
toDispose.push(workspace.onDidChangeConfiguration(e => {
|
||||
if (e.affectsConfiguration('css.customData')) {
|
||||
pathsInWorkspace = getCustomDataPathsInAllWorkspaces();
|
||||
onChange.fire();
|
||||
}
|
||||
}));
|
||||
|
||||
return {
|
||||
get uris() {
|
||||
return pathsInWorkspace.concat(pathsInExtensions);
|
||||
},
|
||||
get onDidChange() {
|
||||
return onChange.event;
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
export function getCustomDataPathsInAllWorkspaces(workspaceFolders: readonly WorkspaceFolder[] | undefined): string[] {
|
||||
|
||||
function getCustomDataPathsInAllWorkspaces(): string[] {
|
||||
const workspaceFolders = workspace.workspaceFolders;
|
||||
|
||||
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.customData) {
|
||||
const customData = wfCSSConfig.workspaceFolderValue.customData;
|
||||
if (Array.isArray(customData)) {
|
||||
customData.forEach(t => {
|
||||
if (typeof t === 'string') {
|
||||
dataPaths.push(path.resolve(wf.uri.fsPath, t));
|
||||
}
|
||||
});
|
||||
const collect = (paths: string[] | undefined, rootFolder: Uri) => {
|
||||
if (Array.isArray(paths)) {
|
||||
for (const path of paths) {
|
||||
if (typeof path === 'string') {
|
||||
dataPaths.push(resolvePath(rootFolder, path).toString());
|
||||
}
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
for (let i = 0; i < workspaceFolders.length; i++) {
|
||||
const folderUri = workspaceFolders[i].uri;
|
||||
const allCssConfig = workspace.getConfiguration('css', folderUri);
|
||||
const customDataInspect = allCssConfig.inspect<string[]>('customData');
|
||||
if (customDataInspect) {
|
||||
collect(customDataInspect.workspaceFolderValue, folderUri);
|
||||
if (i === 0) {
|
||||
if (workspace.workspaceFile) {
|
||||
collect(customDataInspect.workspaceValue, workspace.workspaceFile);
|
||||
}
|
||||
collect(customDataInspect.globalValue, folderUri);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return dataPaths;
|
||||
}
|
||||
|
||||
export function getCustomDataPathsFromAllExtensions(): string[] {
|
||||
function getCustomDataPathsFromAllExtensions(): string[] {
|
||||
const dataPaths: string[] = [];
|
||||
|
||||
for (const extension of extensions.all) {
|
||||
@@ -47,7 +83,7 @@ export function getCustomDataPathsFromAllExtensions(): string[] {
|
||||
if (contributes && contributes.css && contributes.css.customData && Array.isArray(contributes.css.customData)) {
|
||||
const relativePaths: string[] = contributes.css.customData;
|
||||
relativePaths.forEach(rp => {
|
||||
dataPaths.push(path.resolve(extension.extensionPath, rp));
|
||||
dataPaths.push(Uri.joinPath(extension.extensionUri, rp).toString());
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user