Skip to content

Commit fc07367

Browse files
authored
Merge pull request #93 from willofindie/feat/issue-58
[Feat] Improve config contributions to make it compatible with VSCode's Settings UI.
2 parents a8c6cdd + 5971ff6 commit fc07367

File tree

15 files changed

+247
-73
lines changed

15 files changed

+247
-73
lines changed

examples/js-parser/.vscode/settings.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@
33
"src/global/*.tsx",
44
"src/global/*.jsx",
55
],
6+
"cssvar.extensions": [
7+
"css",
8+
"tsx",
9+
"ts",
10+
"ejs",
11+
"html"
12+
]
613
// "cssvar.postcssSyntax": {
714
// "postcss-syntax": ["js", "jsx", "ts", "tsx"]
815
// }

examples/js-parser/index.ejs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<!DOCTYPE html>
2+
<html>
3+
<body>
4+
<style>
5+
.app-root {
6+
margin: var(--spacing-0);
7+
padding: var(--space-2);
8+
}
9+
</style>
10+
</body>
11+
</html>

examples/js-parser/src/global/BrandStyles.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,6 @@ import { styled } from "@linaria/react";
33
export default styled.div`
44
:root {
55
--brand: var(--color-red);
6+
--spacing-0: 0;
67
}
78
`;

examples/multi-root/proj-3/.vscode/settings.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@
66
"dark",
77
"dim"
88
],
9-
"cssvar.excludeThemedVariables": false
9+
"cssvar.excludeThemedVariables": false,
10+
"cssvar.mode": "warn"
1011
}

feature-contributions.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,17 @@ This Extension supports the following properties as of now:
5757
</tr>
5858
</thead>
5959
<tbody>
60+
<tr align="left">
61+
<td><code>cssvar.enable</code></td>
62+
<td>
63+
Enable/Disable extension for a workspace/folder
64+
</td>
65+
<td><code>boolean</code></td>
66+
<td><br>
67+
<pre lang="js">true</pre>
68+
<br>
69+
</td>
70+
</tr>
6071
<tr align="left">
6172
<td><code>cssvar.files</code></td>
6273
<td>
@@ -82,6 +93,7 @@ This Extension supports the following properties as of now:
8293
<tr align="left">
8394
<td>
8495
<code>cssvar.extensions</code>
96+
<br>Use language identifiers mentioned in <a href="https://code.visualstudio.com/docs/languages/identifiers#_known-language-identifiers">this doc</a>
8597
</td>
8698
<td>File extensions in which IntelliSense will be enabled</td>
8799
<td><code>string[]</code></td>

package.json

Lines changed: 49 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -74,11 +74,8 @@
7474
"title": "CSS Variables",
7575
"properties": {
7676
"cssvar.files": {
77-
"type": [
78-
"array",
79-
"null"
80-
],
81-
"default": null,
77+
"type": "array",
78+
"default": ["**/*.css"],
8279
"items": {
8380
"type": "string"
8481
},
@@ -92,11 +89,8 @@
9289
]
9390
},
9491
"cssvar.ignore": {
95-
"type": [
96-
"array",
97-
"null"
98-
],
99-
"default": null,
92+
"type": "array",
93+
"default": ["**/node_modules/**"],
10094
"items": {
10195
"type": "string"
10296
},
@@ -110,11 +104,8 @@
110104
]
111105
},
112106
"cssvar.enable": {
113-
"type": [
114-
"boolean",
115-
"null"
116-
],
117-
"default": null,
107+
"type": "boolean",
108+
"default": true,
118109
"markdownDescription": "Enable/Disable extension for a workspace/folder",
119110
"scope": "resource",
120111
"examples": [
@@ -123,11 +114,21 @@
123114
]
124115
},
125116
"cssvar.extensions": {
126-
"type": [
127-
"array",
128-
"null"
117+
"type": "array",
118+
"default": [
119+
"css",
120+
"scss",
121+
"sass",
122+
"less",
123+
"postcss",
124+
"vue",
125+
"svelte",
126+
"astro",
127+
"ts",
128+
"tsx",
129+
"js",
130+
"jsx"
129131
],
130-
"default": null,
131132
"items": {
132133
"type": "string",
133134
"enum": [
@@ -136,13 +137,25 @@
136137
"sass",
137138
"less",
138139
"postcss",
140+
"stylus",
141+
"sugarss",
142+
"tailwindcss",
139143
"vue",
140144
"svelte",
141145
"astro",
146+
"django-html",
147+
"ejs",
148+
"gohtml",
149+
"GoHTML",
150+
"gohtmltmpl",
151+
"handlebars",
152+
"html",
153+
"jade",
142154
"ts",
143155
"tsx",
144156
"jsx",
145-
"js"
157+
"js",
158+
"coffeescript"
146159
]
147160
},
148161
"markdownDescription": "File extensions for which IntelliSense will be enabled",
@@ -157,11 +170,8 @@
157170
]
158171
},
159172
"cssvar.themes": {
160-
"type": [
161-
"array",
162-
"null"
163-
],
164-
"default": null,
173+
"type": "array",
174+
"default": [],
165175
"items": {
166176
"type": "string"
167177
},
@@ -175,11 +185,8 @@
175185
]
176186
},
177187
"cssvar.excludeThemedVariables": {
178-
"type": [
179-
"boolean",
180-
"null"
181-
],
182-
"default": null,
188+
"type": "boolean",
189+
"default": false,
183190
"markdownDescription": "Exclude themed variables to remove unnecessary duplicates",
184191
"scope": "resource",
185192
"examples": [
@@ -188,11 +195,8 @@
188195
]
189196
},
190197
"cssvar.disableSort": {
191-
"type": [
192-
"boolean",
193-
"null"
194-
],
195-
"default": null,
198+
"type": "boolean",
199+
"default": false,
196200
"markdownDescription": "Disables default sorting applied by VSCode",
197201
"scope": "resource",
198202
"examples": [
@@ -201,11 +205,8 @@
201205
]
202206
},
203207
"cssvar.enableColors": {
204-
"type": [
205-
"boolean",
206-
"null"
207-
],
208-
"default": null,
208+
"type": "boolean",
209+
"default": true,
209210
"markdownDescription": "Enable VScode's Color Representation feature when true",
210211
"scope": "window",
211212
"examples": [
@@ -214,11 +215,8 @@
214215
]
215216
},
216217
"cssvar.enableGotoDef": {
217-
"type": [
218-
"boolean",
219-
"null"
220-
],
221-
"default": null,
218+
"type": "boolean",
219+
"default": true,
222220
"markdownDescription": "Enable VScode's Goto Definition feature for CSS Variables",
223221
"scope": "window",
224222
"examples": [
@@ -227,11 +225,8 @@
227225
]
228226
},
229227
"cssvar.enableHover": {
230-
"type": [
231-
"boolean",
232-
"null"
233-
],
234-
"default": null,
228+
"type": "boolean",
229+
"default": true,
235230
"markdownDescription": "Enable VScode's Hover IntelliSense feature for CSS Variables",
236231
"scope": "window",
237232
"examples": [
@@ -240,11 +235,8 @@
240235
]
241236
},
242237
"cssvar.postcssPlugins": {
243-
"type": [
244-
"array",
245-
"null"
246-
],
247-
"default": null,
238+
"type": "array",
239+
"default": [],
248240
"items": {
249241
"oneOf": [
250242
{
@@ -414,7 +406,8 @@
414406
"watch": "rollup -c -m -w",
415407
"lint": "eslint src --ext ts",
416408
"lint:fix": "eslint src --ext ts --fix",
417-
"test": "concurrently \"tsc --project ./tsconfig.json --noEmit\" \"jest\""
409+
"test": "concurrently \"tsc --project ./tsconfig.json --noEmit\" \"jest\"",
410+
"jest": "jest"
418411
},
419412
"devDependencies": {
420413
"@babel/core": "^7.17.8",

src/constants.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,11 +79,12 @@ export interface Config {
7979

8080
export type WorkspaceConfig = Omit<
8181
Config,
82-
"files" | "mode" | "postcssPlugins"
82+
"files" | "mode" | "postcssPlugins" | "postcssSyntax"
8383
> & {
8484
files: string[];
8585
mode: LintingSeverity | [LintingSeverity, { ignore: string[] }];
8686
postcssPlugins: string[] | [string, Record<string, any>][];
87+
postcssSyntax: Record<string, string[]>;
8788
};
8889

8990
/**

src/main.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,9 @@ const getConfigValue = <T extends keyof WorkspaceConfig>(
4141
config: WorkspaceConfiguration,
4242
key: T
4343
): WorkspaceConfig[typeof key] => {
44-
let value = config.get<WorkspaceConfig[typeof key]>(key);
45-
if (value == null) {
46-
// Only overrride, if extension setting is untouched
47-
value = DEFAULT_CONFIG[key];
44+
const value = config.get<WorkspaceConfig[typeof key]>(key);
45+
if (value == null || !config.has(key)) {
46+
return DEFAULT_CONFIG[key];
4847
}
4948
return value;
5049
};
@@ -124,8 +123,7 @@ export async function setup(): Promise<{
124123
break;
125124
}
126125
case "postcssPlugins": {
127-
const _plugins =
128-
_config.get<WorkspaceConfig["postcssPlugins"]>(key);
126+
const _plugins = getConfigValue(_config, key);
129127
let plugins: Config["postcssPlugins"] = [];
130128
if (_plugins) {
131129
plugins = _plugins
@@ -144,7 +142,7 @@ export async function setup(): Promise<{
144142
break;
145143
}
146144
case "postcssSyntax": {
147-
const syntaxes = _config.get<Record<string, string[]>>(key);
145+
const syntaxes = getConfigValue(_config, key);
148146
if (syntaxes && !Array.isArray(syntaxes)) {
149147
config[fsPathKey][key] = Object.keys(syntaxes).reduce(
150148
(syntaxMap, key) => {
@@ -164,7 +162,7 @@ export async function setup(): Promise<{
164162
break;
165163
}
166164
case "mode": {
167-
const mode = _config.get<WorkspaceConfig["mode"]>(key);
165+
const mode = getConfigValue(_config, key);
168166
let _mode: Config["mode"];
169167
if (typeof mode === "string") {
170168
_mode = [mode, {}];

src/providers/hover-provider.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -64,13 +64,15 @@ export class CssHoverProvider implements HoverProvider {
6464
CACHE.activeRootPath = getActiveRootPath();
6565
const varDetails =
6666
CACHE.cssVarsMap[CACHE.activeRootPath][hoverDetails.name];
67-
const content = getMDString(
68-
varDetails.property,
69-
varDetails.real,
70-
varDetails.color || varDetails.value,
71-
varDetails.theme
72-
);
73-
return new Hover(content, hoverDetails.range);
67+
if (varDetails) {
68+
const content = getMDString(
69+
varDetails.property,
70+
varDetails.real,
71+
varDetails.color || varDetails.value,
72+
varDetails.theme
73+
);
74+
return new Hover(content, hoverDetails.range);
75+
}
7476
}
7577

7678
return null;

0 commit comments

Comments
 (0)