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

Allow loading of custom data #142

merged 7 commits into from
Jan 11, 2019

Conversation

octref
Copy link
Contributor

@octref octref commented Jan 8, 2019

For microsoft/vscode#64164.

  • Refactor languageFacts
  • Allow loading custom properties/at-directives/pseudo-classes/pseudo-elements
  • Strongly type the browser data


export type Stylesheet = {};
export * from './cssLanguageTypes';
export * from 'vscode-languageserver-types';

export interface LanguageServiceOptions {
Copy link
Contributor

Choose a reason for hiding this comment

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

move to 'types'...


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.

@@ -581,7 +581,10 @@ export class CSSCompletion {
}

public getCompletionForTopLevel(result: CompletionList): CompletionList {
for (let entry of languageFacts.getAtDirectives()) {
const atDirectives = languageFacts.getAtDirectives();
Copy link
Contributor

Choose a reason for hiding this comment

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

I find the original code more readable.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

We need atDirectives[entryName] for accessing the each entry. It previously returns an array, so let...of works, now it's an object.

import { addPseudoClasses } from './pseudoClasses';
import { addPseudoElements } from './pseudoElements';

let { properties, atdirectives, pseudoclasses, pseudoelements } = browsers.data.css;
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's avoid globals at more than one place.

}
}

const propertySet: { [key: string]: IEntry } = {};
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's avoid globals at more than one point...

return getCSSLanguageService(customData);
}

function assertCompletion(completions: CompletionList, expected: ItemDescription, document: TextDocument) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I'd rather not copy, but just add new tests to completions.tests

@octref octref merged commit e80ce98 into master Jan 11, 2019
@octref octref deleted the octref/customCSSData branch January 21, 2019 06:15
@aeschli aeschli added this to the December/January 2019 milestone Mar 4, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants