Skip to content

Commit a8c6cdd

Browse files
authored
Merge pull request #90 from willofindie/feat/issue-72
[Feat] Enable all useful language ids | add `enable` setting to enable/disable app per root folder
2 parents 47061f8 + 9b9fc36 commit a8c6cdd

File tree

7 files changed

+51
-10
lines changed

7 files changed

+51
-10
lines changed
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
{
2-
"cssvar.ignore": ["broken.css"]
2+
"cssvar.ignore": ["broken.css"],
3+
"cssvar.mode": "error"
34
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{
22
"cssvar.files": ["**/*.scss"],
3+
"cssvar.extensions": ["scss"],
34
"cssvar.mode": "warn"
45
}

package.json

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,28 @@
4444
"onLanguage:sass",
4545
"onLanguage:less",
4646
"onLanguage:postcss",
47-
"onLanguage:svelte",
48-
"onLanguage:vue",
49-
"onLanguage:astro",
47+
"onLanguage:stylus",
48+
"onLanguage:sugarss",
49+
"onLanguage:tailwindcss",
50+
51+
"onLanguage:django-html",
52+
"onLanguage:ejs",
53+
"onLanguage:gohtml",
54+
"onLanguage:GoHTML",
55+
"onLanguage:gohtmltmpl",
56+
"onLanguage:handlebars",
57+
"onLanguage:html",
58+
"onLanguage:jade",
59+
5060
"onLanguage:javascript",
5161
"onLanguage:javascriptreact",
5262
"onLanguage:typescript",
53-
"onLanguage:typescriptreact"
63+
"onLanguage:typescriptreact",
64+
"onLanguage:coffeescript",
65+
66+
"onLanguage:svelte",
67+
"onLanguage:vue",
68+
"onLanguage:astro"
5469
],
5570
"main": "./out/extension.js",
5671
"preview": false,
@@ -94,6 +109,19 @@
94109
]
95110
]
96111
},
112+
"cssvar.enable": {
113+
"type": [
114+
"boolean",
115+
"null"
116+
],
117+
"default": null,
118+
"markdownDescription": "Enable/Disable extension for a workspace/folder",
119+
"scope": "resource",
120+
"examples": [
121+
true,
122+
false
123+
]
124+
},
97125
"cssvar.extensions": {
98126
"type": [
99127
"array",

src/constants.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ export interface Config {
6464
files: CSSVarLocation[];
6565
// Ignore could be a glob as well.
6666
ignore: string[];
67+
enable: boolean;
6768
extensions: SupportedExtensionNames[];
6869
themes: string[];
6970
mode: [LintingSeverity, { ignore?: RegExp | null }];
@@ -93,6 +94,7 @@ export type WorkspaceConfig = Omit<
9394
export const DEFAULT_CONFIG: WorkspaceConfig = {
9495
files: ["**/*.css"],
9596
ignore: ["**/node_modules/**"],
97+
enable: true,
9698
extensions: [...SUPPORTED_LANGUAGE_IDS],
9799
mode: "off",
98100
themes: [],

src/extension.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import {
99
} from "vscode";
1010
import { CssColorProvider } from "./providers/color-provider";
1111
import { CssCompletionProvider } from "./providers/completion-provider";
12-
import { CACHE, DEFAULT_CONFIG, EXTENSION_NAME } from "./constants";
12+
import { CACHE, EXTENSION_NAME } from "./constants";
1313
import { CssDefinitionProvider } from "./providers/definition-provider";
1414
import { LOGGER } from "./logger";
1515
import { setup } from "./main";
@@ -27,6 +27,10 @@ const watchers: FileSystemWatcher[] = [];
2727
export async function activate(context: ExtensionContext): Promise<void> {
2828
try {
2929
const { config } = await setup();
30+
if (!config[CACHE.activeRootPath].enable) {
31+
return;
32+
}
33+
3034
const [, errorPaths] = await parseFiles(config, { parseAll: true }); // Cache Parsed CSS Vars for all Root folders
3135
if (errorPaths.length > 0) {
3236
const relativePaths = errorPaths;
@@ -42,7 +46,7 @@ export async function activate(context: ExtensionContext): Promise<void> {
4246
);
4347

4448
const completionDisposable = languages.registerCompletionItemProvider(
45-
config[CACHE.activeRootPath].extensions || DEFAULT_CONFIG.extensions,
49+
config[CACHE.activeRootPath].extensions,
4650
new CssCompletionProvider(),
4751
"-",
4852
"v",
@@ -54,23 +58,23 @@ export async function activate(context: ExtensionContext): Promise<void> {
5458

5559
if (config[CACHE.activeRootPath].enableColors) {
5660
const colorDisposable = languages.registerColorProvider(
57-
config[CACHE.activeRootPath].extensions || DEFAULT_CONFIG.extensions,
61+
config[CACHE.activeRootPath].extensions,
5862
new CssColorProvider()
5963
);
6064
context.subscriptions.push(colorDisposable);
6165
}
6266

6367
if (config[CACHE.activeRootPath].enableGotoDef) {
6468
const definitionDisposable = languages.registerDefinitionProvider(
65-
config[CACHE.activeRootPath].extensions || DEFAULT_CONFIG.extensions,
69+
config[CACHE.activeRootPath].extensions,
6670
new CssDefinitionProvider()
6771
);
6872
context.subscriptions.push(definitionDisposable);
6973
}
7074

7175
if (config[CACHE.activeRootPath].enableHover) {
7276
const definitionDisposable = languages.registerHoverProvider(
73-
config[CACHE.activeRootPath].extensions || DEFAULT_CONFIG.extensions,
77+
config[CACHE.activeRootPath].extensions,
7478
new CssHoverProvider()
7579
);
7680
context.subscriptions.push(definitionDisposable);

src/providers/diagnostics.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,9 @@ export function refreshDiagnostics(
5858
cssvarDiagnostics: DiagnosticCollection
5959
): void {
6060
if (
61+
!CACHE.config[CACHE.activeRootPath].extensions.includes(
62+
doc.languageId as any
63+
) ||
6164
CACHE.cssVarCount[CACHE.activeRootPath] === 0 ||
6265
CACHE.config[CACHE.activeRootPath].mode[0] === "off"
6366
) {

src/test/test-utilities.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,14 @@ export class TextDocumentStub {
1212
private _uri: string;
1313
lineCount: number;
1414
lines: string[] = [];
15+
languageId: string;
1516

1617
constructor(doc: string, uri = "foo") {
1718
this.document = doc;
1819
this.lines = doc.split("\n");
1920
this.lineCount = this.lines.length;
2021
this._uri = uri;
22+
this.languageId = "css";
2123
}
2224

2325
// I have used a getter here, so that I can spy it if I want

0 commit comments

Comments
 (0)