Skip to content

Commit 6721972

Browse files
committed
fix: #99 merge extension and languageIds into one single settings property
1 parent 4bd64b5 commit 6721972

File tree

10 files changed

+285
-5
lines changed

10 files changed

+285
-5
lines changed

docs/customize-extension.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ The following list of source file extensions does not need any customization.
2020
> __*JS/TS source file parsing try*__
2121
> __*using [postcss-css-in-js][css-in-js] parser,*__
2222
> __*as described in the [following section](#example-ii)*__.
23+
>
24+
25+
> **NOTE:** Customization might not always work, because the way these syntax parsers work are different
26+
> for different css extensions. Thus if you find an extension is not working properly, do raise an issue
27+
> and appreciate a PR for the same.
2328
2429
<br><br>
2530

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
{
2+
"cssvar.files": ["*.styl"],
3+
"cssvar.extensions": ["styl"],
4+
"cssvar.postcssSyntax": {
5+
// [npm package name]: ["file extension list to use this syntax parser for"]
6+
"postcss-styl": ["styl"]
7+
}
8+
}
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
## Stylus CSS extension
2+
3+
This extension uses and creates a very different AST using postcss, which is incompatible with
4+
`cssvar` vscode extension.
5+
6+
To fully support this CSS extension, I will have to either provide in-built support for this
7+
CSS extension or ignore it for now.
8+
I am ignoring it for now.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
border-radius()
2+
-webkit-border-radius: arguments
3+
-moz-border-radius: arguments
4+
border-radius: arguments
5+
6+
body
7+
font: 12px Helvetica, Arial, sans-serif
8+
color: --c
9+
10+
a.button
11+
border-radius: 5px
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"name": "custom-extension",
3+
"version": "1.0.0",
4+
"description": "",
5+
"main": "index.js",
6+
"scripts": {
7+
"test": "echo \"Error: no test specified\" && exit 1"
8+
},
9+
"keywords": [],
10+
"author": "",
11+
"license": "ISC",
12+
"devDependencies": {
13+
"postcss": "^8.4.21",
14+
"postcss-styl": "^0.12.3"
15+
}
16+
}

examples/custom-extension/pnpm-lock.yaml

Lines changed: 193 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
color-variables()
2+
--color-1: red;
3+
--color-2: blue;
4+
5+
:root {
6+
color-variables();
7+
}

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,11 @@
138138
"sass",
139139
"less",
140140
"postcss",
141+
"pcss",
141142
"stylus",
143+
"styl",
142144
"sugarss",
145+
"sss",
143146
"tailwindcss",
144147
"vue",
145148
"svelte",
@@ -150,16 +153,22 @@
150153
"GoHTML",
151154
"gohtmltmpl",
152155
"handlebars",
156+
"hbs",
153157
"html",
154158
"jade",
159+
"pug",
155160
"ts",
156161
"tsx",
157162
"jsx",
158163
"js",
164+
"typescript",
165+
"typescriptreact",
166+
"javascriptreact",
167+
"javascript",
159168
"coffeescript"
160169
]
161170
},
162-
"markdownDescription": "File extensions for which IntelliSense will be enabled",
171+
"markdownDescription": "File extensions or VSCode language ids for which IntelliSense will be enabled. Details on [VSCode Language Ids can be found here](https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers)",
163172
"scope": "resource",
164173
"examples": [
165174
[

src/constants.ts

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,17 +19,23 @@ export const CSS_IDS = [
1919
] as const;
2020
export const SUPPORTED_LANGUAGE_IDS = [...CSS_IDS, ...JS_IDS] as const;
2121
export type SupportedLanguageIds = typeof SUPPORTED_LANGUAGE_IDS[number];
22+
export type ExtendedLanguageIds = "stylus" | "sugarss" | "handlebars";
2223
export type CssExtensions = Exclude<
2324
typeof CSS_IDS[number],
2425
"vue" | "svelte" | "astro"
2526
>;
2627

28+
/**
29+
* This should always be a combination of extension and language ids
30+
* to simplify user experience.
31+
*/
2732
export type SupportedExtensionNames =
2833
| "css"
2934
| "scss"
3035
| "sass"
3136
| "less"
3237
| "postcss"
38+
| "pcss"
3339
| "vue"
3440
| "svelte"
3541
| "astro"
@@ -42,6 +48,12 @@ export type SupportedExtensionNames =
4248
| "javascript"
4349
| "javascriptreact";
4450

51+
export type ExtendedExtensionNames =
52+
| ExtendedLanguageIds
53+
| "styl"
54+
| "sss"
55+
| "hbs";
56+
4557
export type JsExtensions = Extract<
4658
SupportedExtensionNames,
4759
"js" | "jsx" | "ts" | "tsx"
@@ -65,7 +77,7 @@ export interface Config {
6577
// Ignore could be a glob as well.
6678
ignore: string[];
6779
enable: boolean;
68-
extensions: SupportedExtensionNames[];
80+
extensions: (SupportedExtensionNames | ExtendedExtensionNames)[];
6981
themes: string[];
7082
mode: [LintingSeverity, { ignore?: RegExp | null }];
7183
postcssPlugins: [string, Record<string, any>][];
@@ -109,8 +121,8 @@ export const DEFAULT_CONFIG: WorkspaceConfig = {
109121
};
110122

111123
export const mapShortToFullExtension = (
112-
ext: SupportedExtensionNames
113-
): SupportedLanguageIds => {
124+
ext: SupportedExtensionNames | ExtendedExtensionNames
125+
): SupportedLanguageIds | ExtendedLanguageIds => {
114126
switch (ext) {
115127
case "ts":
116128
return "typescript";
@@ -120,6 +132,14 @@ export const mapShortToFullExtension = (
120132
return "javascript";
121133
case "jsx":
122134
return "javascriptreact";
135+
case "pcss":
136+
return "postcss";
137+
case "styl":
138+
return "stylus";
139+
case "sss":
140+
return "sugarss";
141+
case "hbs":
142+
return "handlebars";
123143
default:
124144
return ext;
125145
}

src/main.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import {
1515
CSSVarLocation,
1616
CSSVarRecord,
1717
DEFAULT_CONFIG,
18+
ExtendedExtensionNames,
1819
EXTENSION_NAME,
1920
mapShortToFullExtension,
2021
SUFFIX,
@@ -116,7 +117,9 @@ export async function setup(): Promise<{
116117
const value = getConfigValue(_config, key);
117118
config[fsPathKey][key] = value.map(ext => {
118119
const _ext = ext.startsWith(".")
119-
? (ext.substring(1) as SupportedExtensionNames)
120+
? (ext.substring(1) as
121+
| SupportedExtensionNames
122+
| ExtendedExtensionNames)
120123
: ext;
121124
return mapShortToFullExtension(_ext);
122125
});

0 commit comments

Comments
 (0)