From bbfbe8d95a6052c30bb832da601d9868433d7141 Mon Sep 17 00:00:00 2001 From: Derek Kniffin Date: Fri, 19 Feb 2021 15:21:00 -0500 Subject: [PATCH 1/2] Add support for haml and slim Fixes #141 --- package.json | 12 +++++++++++- src/extension.ts | 16 ++++++++++++++++ 2 files changed, 27 insertions(+), 1 deletion(-) diff --git a/package.json b/package.json index d7f191e..43ed35e 100644 --- a/package.json +++ b/package.json @@ -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": { diff --git a/src/extension.ts b/src/extension.ts index 5028ee5..f7dbdcc 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -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", } @@ -33,6 +34,7 @@ const completionTriggerChars = ['"', "'", " ", "."]; let caching = false; const htmlDisposables: Disposable[] = []; +const hamlDisposables: Disposable[] = []; const cssDisposables: Disposable[] = []; const javaScriptDisposables: Disposable[] = []; const emmetDisposables: Disposable[] = []; @@ -144,6 +146,13 @@ const registerHTMLProviders = (disposables: Disposable[]) => disposables.push(registerCompletionProvider(extension, /class=["|']([\w- ]*$)/)); }); +const registerHAMLProviders = (disposables: Disposable[]) => + workspace.getConfiguration() + ?.get(Configuration.HAMLLanguages) + ?.forEach((extension) => { + disposables.push(registerCompletionProvider(extension, /(?=\.)([\w-. ]*$)/, "", ".")); + }); + const registerCSSProviders = (disposables: Disposable[]) => workspace.getConfiguration() .get(Configuration.CSSLanguages) @@ -207,6 +216,11 @@ export async function activate(context: ExtensionContext): Promise { registerHTMLProviders(htmlDisposables); } + if (e.affectsConfiguration(Configuration.HAMLLanguages)) { + unregisterProviders(hamlDisposables); + registerHAMLProviders(hamlDisposables); + } + if (e.affectsConfiguration(Configuration.CSSLanguages)) { unregisterProviders(cssDisposables); registerCSSProviders(cssDisposables); @@ -246,6 +260,7 @@ export async function activate(context: ExtensionContext): Promise { } registerHTMLProviders(htmlDisposables); + registerHAMLProviders(hamlDisposables); registerCSSProviders(cssDisposables); registerJavaScriptProviders(javaScriptDisposables); @@ -263,6 +278,7 @@ export async function activate(context: ExtensionContext): Promise { export function deactivate(): void { unregisterProviders(htmlDisposables); + unregisterProviders(hamlDisposables); unregisterProviders(cssDisposables); unregisterProviders(javaScriptDisposables); unregisterProviders(emmetDisposables); From c88e4d2cf2a57f65d6cbb8408486b991ea29f7e4 Mon Sep 17 00:00:00 2001 From: Derek Kniffin Date: Fri, 19 Feb 2021 15:21:28 -0500 Subject: [PATCH 2/2] Extend erb support to include class: param --- package.json | 9 +++++++++ src/extension.ts | 16 ++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/package.json b/package.json index 43ed35e..e5ea245 100644 --- a/package.json +++ b/package.json @@ -75,6 +75,15 @@ "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": { "type": "array", "description": "A list of CSS based languages where suggestions are enabled.", diff --git a/src/extension.ts b/src/extension.ts index f7dbdcc..645b8e7 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -22,6 +22,7 @@ enum Configuration { 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", } @@ -35,6 +36,7 @@ let caching = false; const htmlDisposables: Disposable[] = []; const hamlDisposables: Disposable[] = []; +const erbDisposables: Disposable[] = []; const cssDisposables: Disposable[] = []; const javaScriptDisposables: Disposable[] = []; const emmetDisposables: Disposable[] = []; @@ -153,6 +155,13 @@ const registerHAMLProviders = (disposables: Disposable[]) => disposables.push(registerCompletionProvider(extension, /(?=\.)([\w-. ]*$)/, "", ".")); }); +const registerERBProviders = (disposables: Disposable[]) => + workspace.getConfiguration() + ?.get(Configuration.HAMLLanguages) + ?.forEach((extension) => { + disposables.push(registerCompletionProvider(extension, /class:\s+["|']([\w- ]*$)/)); + }); + const registerCSSProviders = (disposables: Disposable[]) => workspace.getConfiguration() .get(Configuration.CSSLanguages) @@ -221,6 +230,11 @@ export async function activate(context: ExtensionContext): Promise { registerHAMLProviders(hamlDisposables); } + if (e.affectsConfiguration(Configuration.ERBLanguages)) { + unregisterProviders(erbDisposables); + registerERBProviders(erbDisposables); + } + if (e.affectsConfiguration(Configuration.CSSLanguages)) { unregisterProviders(cssDisposables); registerCSSProviders(cssDisposables); @@ -261,6 +275,7 @@ export async function activate(context: ExtensionContext): Promise { registerHTMLProviders(htmlDisposables); registerHAMLProviders(hamlDisposables); + registerERBProviders(erbDisposables); registerCSSProviders(cssDisposables); registerJavaScriptProviders(javaScriptDisposables); @@ -279,6 +294,7 @@ export async function activate(context: ExtensionContext): Promise { export function deactivate(): void { unregisterProviders(htmlDisposables); unregisterProviders(hamlDisposables); + unregisterProviders(erbDisposables); unregisterProviders(cssDisposables); unregisterProviders(javaScriptDisposables); unregisterProviders(emmetDisposables);