Allow to run css language server headless

This commit is contained in:
Martin Aeschlimann
2020-05-22 17:08:16 +02:00
parent 452dc54c78
commit 2e5b0824d1
22 changed files with 1100 additions and 721 deletions

View File

@@ -3,48 +3,36 @@
* Licensed under the MIT License. See License.txt in the project root for license information.
*--------------------------------------------------------------------------------------------*/
import { CSSDataV1, ICSSDataProvider } from 'vscode-css-languageservice';
import * as fs from 'fs';
import { ICSSDataProvider, newCSSDataProvider } from 'vscode-css-languageservice';
import { RequestService } from './requests';
export function getDataProviders(dataPaths: string[]): ICSSDataProvider[] {
const providers = dataPaths.map(p => {
if (fs.existsSync(p)) {
const data = parseCSSData(fs.readFileSync(p, 'utf-8'));
return {
provideProperties: () => data.properties || [],
provideAtDirectives: () => data.atDirectives || [],
providePseudoClasses: () => data.pseudoClasses || [],
providePseudoElements: () => data.pseudoElements || []
};
} else {
return {
provideProperties: () => [],
provideAtDirectives: () => [],
providePseudoClasses: () => [],
providePseudoElements: () => []
};
export function fetchDataProviders(dataPaths: string[], requestService: RequestService): Promise<ICSSDataProvider[]> {
const providers = dataPaths.map(async p => {
try {
const content = await requestService.getContent(p);
return parseCSSData(content);
} catch (e) {
return newCSSDataProvider({ version: 1 });
}
});
return providers;
return Promise.all(providers);
}
function parseCSSData(source: string): CSSDataV1 {
function parseCSSData(source: string): ICSSDataProvider {
let rawData: any;
try {
rawData = JSON.parse(source);
} catch (err) {
return {
version: 1
};
return newCSSDataProvider({ version: 1 });
}
return {
return newCSSDataProvider({
version: 1,
properties: rawData.properties || [],
atDirectives: rawData.atDirectives || [],
pseudoClasses: rawData.pseudoClasses || [],
pseudoElements: rawData.pseudoElements || []
};
});
}