Skip to content

Add slim and HAML support #300

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Add support for haml and slim
Fixes #141
  • Loading branch information
dkniffin committed Feb 19, 2021
commit bbfbe8d95a6052c30bb832da601d9868433d7141
12 changes: 11 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,17 @@
"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.CSSLanguages": {
Expand Down
16 changes: 16 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ 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",
CSSLanguages = "html-css-class-completion.CSSLanguages",
JavaScriptLanguages = "html-css-class-completion.JavaScriptLanguages",
}
Expand All @@ -33,6 +34,7 @@ const completionTriggerChars = ['"', "'", " ", "."];
let caching = false;

const htmlDisposables: Disposable[] = [];
const hamlDisposables: Disposable[] = [];
const cssDisposables: Disposable[] = [];
const javaScriptDisposables: Disposable[] = [];
const emmetDisposables: Disposable[] = [];
Expand Down Expand Up @@ -144,6 +146,13 @@ 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 registerCSSProviders = (disposables: Disposable[]) =>
workspace.getConfiguration()
.get<string[]>(Configuration.CSSLanguages)
Expand Down Expand Up @@ -207,6 +216,11 @@ export async function activate(context: ExtensionContext): Promise<void> {
registerHTMLProviders(htmlDisposables);
}

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

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

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

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

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