Skip to content

Allow loading of custom data - #142

Merged
Pine (octref) merged 7 commits into
masterfrom
octref/customCSSData
Jan 11, 2019
Merged

Pine (octref) merged 7 commits into
masterfrom
octref/customCSSData

Conversation

@octref

Copy link
Copy Markdown
Contributor

For microsoft/vscode#64164.

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

Comment thread src/cssLanguageService.ts Outdated
export * from './cssLanguageTypes';
export * from 'vscode-languageserver-types';

export interface LanguageServiceOptions {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

move to 'types'...

Comment thread src/cssLanguageService.ts

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

@aeschli Martin Aeschlimann (aeschli) Jan 9, 2019 •

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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.

Comment thread src/services/cssCompletion.ts Outdated

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

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
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.

Comment thread src/services/languageFacts/index.ts Outdated
import { addPseudoClasses } from './pseudoClasses';
import { addPseudoElements } from './pseudoElements';

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

Copy link
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

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
Copy Markdown
Collaborator

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
Pine (octref) merged commit e80ce98 into master Jan 11, 2019
@octref
Pine (octref) deleted the octref/customCSSData branch January 21, 2019 06:15
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