Skip to content
Open
Show file tree
Hide file tree
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
21 changes: 20 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,26 @@
"markdown",
"erb",
"ejs",
"svelte"
"svelte",
"haml",
"slim"
]
},
"html-css-class-completion.HAMLLanguages": {
"type": "array",
"description": "A list of HAML based languages where suggestions are enabled.",
"default": [
"haml",
"slim"
]
},
"html-css-class-completion.ERBLanguages": {
"type": "array",
"description": "A list of ERB based languages where suggestions are enabled.",
"default": [
"erb",
"haml",
"slim"
]
},
"html-css-class-completion.CSSLanguages": {
Expand Down
32 changes: 32 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ enum Configuration {
ExcludeGlobPattern = "html-css-class-completion.excludeGlobPattern",
EnableEmmetSupport = "html-css-class-completion.enableEmmetSupport",
HTMLLanguages = "html-css-class-completion.HTMLLanguages",
HAMLLanguages = "html-css-class-completion.HAMLLanguages",
ERBLanguages = "html-css-class-completion.ERBLanguages",
CSSLanguages = "html-css-class-completion.CSSLanguages",
JavaScriptLanguages = "html-css-class-completion.JavaScriptLanguages",
}
Expand All @@ -33,6 +35,8 @@ const completionTriggerChars = ['"', "'", " ", "."];
let caching = false;

const htmlDisposables: Disposable[] = [];
const hamlDisposables: Disposable[] = [];
const erbDisposables: Disposable[] = [];
const cssDisposables: Disposable[] = [];
const javaScriptDisposables: Disposable[] = [];
const emmetDisposables: Disposable[] = [];
Expand Down Expand Up @@ -144,6 +148,20 @@ const registerHTMLProviders = (disposables: Disposable[]) =>
disposables.push(registerCompletionProvider(extension, /class=["|']([\w- ]*$)/));
});

const registerHAMLProviders = (disposables: Disposable[]) =>
workspace.getConfiguration()
?.get<string[]>(Configuration.HAMLLanguages)
?.forEach((extension) => {
disposables.push(registerCompletionProvider(extension, /(?=\.)([\w-. ]*$)/, "", "."));
});

const registerERBProviders = (disposables: Disposable[]) =>
workspace.getConfiguration()
?.get<string[]>(Configuration.HAMLLanguages)
?.forEach((extension) => {
disposables.push(registerCompletionProvider(extension, /class:\s+["|']([\w- ]*$)/));
});

const registerCSSProviders = (disposables: Disposable[]) =>
workspace.getConfiguration()
.get<string[]>(Configuration.CSSLanguages)
Expand Down Expand Up @@ -207,6 +225,16 @@ export async function activate(context: ExtensionContext): Promise<void> {
registerHTMLProviders(htmlDisposables);
}

if (e.affectsConfiguration(Configuration.HAMLLanguages)) {
unregisterProviders(hamlDisposables);
registerHAMLProviders(hamlDisposables);
}

if (e.affectsConfiguration(Configuration.ERBLanguages)) {
unregisterProviders(erbDisposables);
registerERBProviders(erbDisposables);
}

if (e.affectsConfiguration(Configuration.CSSLanguages)) {
unregisterProviders(cssDisposables);
registerCSSProviders(cssDisposables);
Expand Down Expand Up @@ -246,6 +274,8 @@ export async function activate(context: ExtensionContext): Promise<void> {
}

registerHTMLProviders(htmlDisposables);
registerHAMLProviders(hamlDisposables);
registerERBProviders(erbDisposables);
registerCSSProviders(cssDisposables);
registerJavaScriptProviders(javaScriptDisposables);

Expand All @@ -263,6 +293,8 @@ export async function activate(context: ExtensionContext): Promise<void> {

export function deactivate(): void {
unregisterProviders(htmlDisposables);
unregisterProviders(hamlDisposables);
unregisterProviders(erbDisposables);
unregisterProviders(cssDisposables);
unregisterProviders(javaScriptDisposables);
unregisterProviders(emmetDisposables);
Expand Down