Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow loading of custom data #142

Merged
merged 7 commits into from
Jan 11, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
34 changes: 17 additions & 17 deletions build/generate_browserjs.js
Original file line number Diff line number Diff line change
@@ -358,28 +358,26 @@ const { addBrowserCompatDataToProperties } = require('./mdn/mdn-browser-compat-d

fs.readFile(path.resolve(__dirname, schemaFileName), (err, data) => {
parser.parseString(data, function(err, result) {
const atdirectives = toSource(result, 'atDirectives')
const atDirectives = toSource(result, 'atDirectives')

let pseudoclasses = toSource(result, 'pseudoClasses')
pseudoclasses = addMDNPseudoSelectors(pseudoclasses)
let pseudoClasses = toSource(result, 'pseudoClasses')
pseudoClasses = addMDNPseudoSelectors(pseudoClasses)

let pseudoelements = toSource(result, 'pseudoElements')
pseudoelements = addMDNPseudoElements(pseudoelements)
let pseudoElements = toSource(result, 'pseudoElements')
pseudoElements = addMDNPseudoElements(pseudoElements)

let properties = toSource(result, 'properties')
properties = addMDNProperties(properties)

addBrowserCompatDataToProperties(atdirectives, pseudoclasses, pseudoelements, properties)
addBrowserCompatDataToProperties(atDirectives, pseudoClasses, pseudoElements, properties)

const descriptions = internalizeDescriptions([].concat(atdirectives, pseudoclasses, pseudoelements, properties))
const descriptions = internalizeDescriptions([].concat(atDirectives, pseudoClasses, pseudoElements, properties))

const resultObject = {
css: {
atdirectives,
pseudoclasses,
pseudoelements,
properties,
}
properties,
atDirectives,
pseudoClasses,
pseudoElements,
}

function toJavaScript(obj) {
@@ -394,10 +392,12 @@ fs.readFile(path.resolve(__dirname, schemaFileName), (err, data) => {
' *--------------------------------------------------------------------------------------------*/',
'// file generated from ' +
schemaFileName +
' and https://github.com/mdn/data using css-exclude_generate_browserjs.js',
'',
'export const data : any = ' + toJavaScript(resultObject) + ';',
'export const descriptions : any = ' + toJavaScript(descriptions) + ';'
' and https://github.com/mdn/data using build/generate_browserjs.js',
'',
'import { CSSData } from "../services/languageFacts";',
'',
'export const cssData : CSSData = ' + toJavaScript(resultObject) + ';',
'export const descriptions : any = ' + toJavaScript(descriptions) + ';'
]

var outputPath = path.resolve(__dirname, '../src/data/browsers.ts')
17 changes: 13 additions & 4 deletions src/cssLanguageService.ts
Original file line number Diff line number Diff line change
@@ -21,7 +21,8 @@ import { SCSSCompletion } from './services/scssCompletion';
import { LESSParser } from './parser/lessParser';
import { LESSCompletion } from './services/lessCompletion';
import { getFoldingRanges } from './services/cssFolding';
import { LanguageSettings, ICompletionParticipant, DocumentContext } from './cssLanguageTypes';
import { LanguageSettings, ICompletionParticipant, DocumentContext, LanguageServiceOptions } from './cssLanguageTypes';
import { builtinCSSDataSet } from './services/languageFacts';

export type Stylesheet = {};
export * from './cssLanguageTypes';
@@ -72,15 +73,23 @@ function createFacade(parser: Parser, completion: CSSCompletion, hover: CSSHover
};
}

function handleCustomData(options?: LanguageServiceOptions) {
if (options && options.customDataCollections) {
options.customDataCollections.forEach(data => builtinCSSDataSet.addData(data));
}
}

export function getCSSLanguageService(): LanguageService {
export function getCSSLanguageService(options?: LanguageServiceOptions): LanguageService {
handleCustomData(options);
Copy link
Contributor

@aeschli aeschli Jan 9, 2019

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If we choose this API, we must store the properies/directives per LanguageService, not in global arrays. Users can create any number of language services, each with a different set of data.

I would suggest to make a new type CSSPropertySet (name to be debated) containing properties/directives/..., that is registered globaly with the vscode-css-languageservice (exported const propertySets : CSSPropertySet[]) Our built-in properties (generated from MDN) should also be represented in one (or multiple) CSSPropertySets.

In a first step, all language services just use that global list of propertySets. In a later step we allow to create a language service with a custom list of Sets. That language service would then only use that set. It would be good to already prepare our code to avoid accessing CSSPropertySet globaly.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I was about to check with you. The same problem with HTML now. Do we make the language services stateful? I'll go with stateful then.

return createFacade(new Parser(), new CSSCompletion(), new CSSHover(), new CSSNavigation(), new CSSCodeActions(), new CSSValidation());
}

export function getSCSSLanguageService(): LanguageService {
export function getSCSSLanguageService(options?: LanguageServiceOptions): LanguageService {
handleCustomData(options);
return createFacade(new SCSSParser(), new SCSSCompletion(), new CSSHover(), new CSSNavigation(), new CSSCodeActions(), new CSSValidation());
}

export function getLESSLanguageService(): LanguageService {
export function getLESSLanguageService(options?: LanguageServiceOptions): LanguageService {
handleCustomData(options);
return createFacade(new LESSParser(), new LESSCompletion(), new CSSHover(), new CSSNavigation(), new CSSCodeActions(), new CSSValidation());
}
10 changes: 8 additions & 2 deletions src/cssLanguageTypes.ts
Original file line number Diff line number Diff line change
@@ -4,7 +4,9 @@
*--------------------------------------------------------------------------------------------*/
'use strict';

import { Range, TextEdit, Position } from "vscode-languageserver-types";
import { Range, TextEdit, Position } from 'vscode-languageserver-types';
import { CSSData } from './services/languageFacts';
export { CSSData } from './services/languageFacts';

export { Range, TextEdit, Position };

@@ -47,4 +49,8 @@ export interface ICompletionParticipant {

export interface DocumentContext {
resolveReference(ref: string, base?: string): string;
}
}

export interface LanguageServiceOptions {
customDataCollections?: CSSData[];
}
Loading