Skip to content

Commit bd5a8da

Browse files
committed
Added css.validation setting
1 parent 2fcb66e commit bd5a8da

File tree

4 files changed

+46
-13
lines changed

4 files changed

+46
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
All notable changes to the extension will be documented in this file.
44

5+
## [1.5.0] - 2020-12-28
6+
7+
- Added `css.validation` setting.
8+
59
## [1.4.5] - 2020-12-28
610

711
- Update documentation.

README.md

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -133,27 +133,37 @@ If it is not possible to specify local or remote styles in HTML or via template
133133
```js
134134
"css.styleSheets": [
135135

136-
// (1)
137-
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
136+
// (1)
137+
"https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css",
138138

139-
// (2)
140-
"/site.css",
139+
// (2)
140+
"/site.css",
141141

142-
// (3)
143-
"site.css",
142+
// (3)
143+
"site.css",
144144

145-
// (4)
146-
"./site.css"
145+
// (4)
146+
"./site.css"
147147
]
148148
```
149+
## Selector Validation
150+
151+
Validated selectors can be configured with the `css.validation` setting. By default `class` selectors are validated:
152+
153+
```json
154+
"css.validation": {
155+
"id": false,
156+
"class": true
157+
}
158+
```
149159

150160
## Supported Languages
151161

152162
Supported languages can be configured with the `css.enabledLanguages` setting. By default `html` is enabled:
153163

154164
```json
155165
"css.enabledLanguages": [
156-
"html"
166+
"html"
157167
]
158168
```
159169

package.json

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
"name": "vscode-html-css",
33
"displayName": "HTML CSS Support",
44
"description": "CSS Intellisense for HTML",
5-
"version": "1.4.5",
5+
"version": "1.5.0",
66
"publisher": "ecmel",
77
"license": "MIT",
88
"homepage": "https://github.com/ecmel/vscode-html-css",
@@ -49,6 +49,15 @@
4949
"default": [],
5050
"description": "A list of local or remote style sheets for suggestions.",
5151
"scope": "resource"
52+
},
53+
"css.validation": {
54+
"type": "object",
55+
"default": {
56+
"id": false,
57+
"class": true
58+
},
59+
"description": "Choose selectors for validation.",
60+
"scope": "resource"
5261
}
5362
}
5463
}

src/completion.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,11 @@ import {
2020
workspace
2121
} from "vscode";
2222

23+
type Validation = {
24+
id: boolean;
25+
class: boolean;
26+
};
27+
2328
export class SelectorCompletionItemProvider implements CompletionItemProvider, Disposable {
2429

2530
readonly none = "__!NONE!__";
@@ -63,6 +68,10 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
6368
return workspace.getConfiguration("css", uri).get<string[]>("styleSheets", []);
6469
}
6570

71+
getValidation(uri: Uri): Validation {
72+
return workspace.getConfiguration("css", uri).get<Validation>("validation", { id: false, class: true });
73+
}
74+
6675
getRelativePath(uri: Uri, spec: string, ext?: string): string {
6776
const folder = workspace.getWorkspaceFolder(uri);
6877
const name = ext ? join(dirname(spec), basename(spec, ext) + ext) : spec;
@@ -293,6 +302,7 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
293302
this.findAll(uri, text).then(sets => {
294303
const ids = new Set<string>();
295304
const classes = new Set<string>();
305+
const validation = this.getValidation(uri);
296306

297307
sets.forEach(set => set.forEach(key => this.getItems(key)?.forEach((v, k) => {
298308
if (v.kind === CompletionItemKind.Value) {
@@ -322,13 +332,13 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
322332
const start = document.positionAt(anchor - value[1].length);
323333

324334
if (attribute[1] === "id") {
325-
if (!ids.has(value[1])) {
335+
if (validation.id && !ids.has(value[1])) {
326336
diagnostics.push(new Diagnostic(new Range(start, end),
327337
`CSS id selector '${value[1]}' not found.`,
328-
DiagnosticSeverity.Warning));
338+
DiagnosticSeverity.Information));
329339
}
330340
} else {
331-
if (!classes.has(value[1])) {
341+
if (validation.class && !classes.has(value[1])) {
332342
diagnostics.push(new Diagnostic(new Range(start, end),
333343
`CSS class selector '${value[1]}' not found.`,
334344
DiagnosticSeverity.Warning));

0 commit comments

Comments
 (0)