-
Notifications
You must be signed in to change notification settings - Fork 187
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
Changes from 3 commits
56cb0bb
dcd599c
3040c43
1dbef17
8517950
4606395
5ec68b2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,11 +22,19 @@ import { LESSParser } from './parser/lessParser'; | |
import { LESSCompletion } from './services/lessCompletion'; | ||
import { getFoldingRanges } from './services/cssFolding'; | ||
import { LanguageSettings, ICompletionParticipant, DocumentContext } from './cssLanguageTypes'; | ||
import { addProperties, addAtDirectives, addPseudoClasses, addPseudoElements, IEntryData } from './services/languageFacts/index'; | ||
|
||
export type Stylesheet = {}; | ||
export * from './cssLanguageTypes'; | ||
export * from 'vscode-languageserver-types'; | ||
|
||
export interface LanguageServiceOptions { | ||
customProperties?: IEntryData[]; | ||
customAtDirectives?: IEntryData[]; | ||
customPseudoClasses?: IEntryData[]; | ||
customPseudoElements?: IEntryData[]; | ||
} | ||
|
||
export interface LanguageService { | ||
configure(raw: LanguageSettings): void; | ||
doValidation(document: TextDocument, stylesheet: Stylesheet, documentSettings?: LanguageSettings): Diagnostic[]; | ||
|
@@ -72,15 +80,34 @@ function createFacade(parser: Parser, completion: CSSCompletion, hover: CSSHover | |
}; | ||
} | ||
|
||
function handleCustomData(options?: LanguageServiceOptions) { | ||
if (options) { | ||
if (options.customProperties) { | ||
addProperties(options.customProperties); | ||
} | ||
if (options.customAtDirectives) { | ||
addAtDirectives(options.customAtDirectives); | ||
} | ||
if (options.customPseudoClasses) { | ||
addPseudoClasses(options.customPseudoClasses); | ||
} | ||
if (options.customPseudoElements) { | ||
addPseudoElements(options.customPseudoElements); | ||
} | ||
} | ||
} | ||
|
||
export function getCSSLanguageService(): LanguageService { | ||
export function getCSSLanguageService(options?: LanguageServiceOptions): LanguageService { | ||
handleCustomData(options); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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()); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -581,7 +581,10 @@ export class CSSCompletion { | |
} | ||
|
||
public getCompletionForTopLevel(result: CompletionList): CompletionList { | ||
for (let entry of languageFacts.getAtDirectives()) { | ||
const atDirectives = languageFacts.getAtDirectives(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I find the original code more readable. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We need |
||
|
||
for (let entryName in atDirectives) { | ||
const entry = atDirectives[entryName]; | ||
if (entry.browsers.count > 0) { | ||
result.items.push({ | ||
label: entry.name, | ||
|
@@ -591,6 +594,7 @@ export class CSSCompletion { | |
}); | ||
} | ||
} | ||
|
||
this.getCompletionsForSelector(null, false, result); | ||
return result; | ||
} | ||
|
@@ -618,7 +622,9 @@ export class CSSCompletion { | |
this.defaultReplaceRange = Range.create(Position.create(this.position.line, this.position.character - this.currentWord.length), this.position); | ||
} | ||
|
||
for (let entry of languageFacts.getPseudoClasses()) { | ||
const pseudoClasses = languageFacts.getPseudoClasses(); | ||
for (let entryName in pseudoClasses) { | ||
const entry = pseudoClasses[entryName]; | ||
if (entry.browsers.onCodeComplete) { | ||
let insertText = moveCursorInsideParenthesis(entry.name); | ||
let item: CompletionItem = { | ||
|
@@ -634,7 +640,10 @@ export class CSSCompletion { | |
result.items.push(item); | ||
} | ||
} | ||
for (let entry of languageFacts.getPseudoElements()) { | ||
|
||
const pseudoElements = languageFacts.getPseudoElements(); | ||
for (let entryName in pseudoElements) { | ||
const entry = pseudoElements[entryName]; | ||
if (entry.browsers.onCodeComplete) { | ||
let insertText = moveCursorInsideParenthesis(entry.name); | ||
let item: CompletionItem = { | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
move to 'types'...