Skip to content

Commit 29db557

Browse files
committed
fixed auto validation
1 parent 839e0bf commit 29db557

File tree

6 files changed

+60
-40
lines changed

6 files changed

+60
-40
lines changed

CHANGELOG.md

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

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

5+
## [2.0.8] - 2024-02-
6+
7+
- Added optional auto validation
8+
- Added feedback for clear cache
9+
- Updated dependencies
10+
511
## [2.0.7] - 2024-01-23
612

713
- Build fixes

README.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -57,17 +57,24 @@ Configuration depends on your layout of the project but some samples are below:
5757

5858
### Bootstrap
5959

60+
If you are using Bootstrap npm module:
61+
6062
```json
6163
{
62-
"css.enabledLanguages": ["html"]
64+
"css.styleSheets": [
65+
"node_modules/bootstrap/dist/css/bootstrap.css",
66+
"src/**/*.scss"
67+
]
6368
}
6469
```
6570

71+
If you are using Bootstrap CDN:
72+
6673
```json
6774
{
6875
"css.styleSheets": [
69-
"node_modules/bootstrap/dist/css/bootstrap.css",
70-
"src/**/*.css"
76+
"https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css",
77+
"src/**/*.scss"
7178
]
7279
}
7380
```

package-lock.json

Lines changed: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535
"ejs",
3636
"lit",
3737
"lit-html",
38+
"bootstrap",
39+
"template",
3840
"javascript",
3941
"typescript",
4042
"multi-root ready"
@@ -63,7 +65,7 @@
6365
"css.autoValidation": {
6466
"type": "string",
6567
"scope": "resource",
66-
"description": "When to validate class selectors.",
68+
"description": "Auto validation for class selectors.",
6769
"default": "Never",
6870
"enum": [
6971
"Never",
@@ -118,7 +120,7 @@
118120
"@rollup/plugin-typescript": "^11.1.6",
119121
"@types/line-column": "^1.0.2",
120122
"@types/mocha": "^10.0.6",
121-
"@types/node": "^20.11.9",
123+
"@types/node": "^20.11.10",
122124
"@types/sinon": "^17.0.3",
123125
"@types/vscode": "^1.75.0",
124126
"@vscode/test-electron": "^2.3.9",

src/extension.ts

Lines changed: 35 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import {
77
commands,
88
ExtensionContext,
99
languages,
10+
TextDocument,
1011
window,
1112
workspace,
1213
} from "vscode";
@@ -17,56 +18,59 @@ import {
1718
} from "./settings";
1819
import { Provider, clear, invalidate } from "./provider";
1920

20-
export function activate(context: ExtensionContext) {
21-
const enabledLanguages = getEnabledLanguages();
22-
const validations = languages.createDiagnosticCollection();
23-
const provider = new Provider();
21+
const enabledLanguages = getEnabledLanguages();
22+
const validations = languages.createDiagnosticCollection();
23+
const provider = new Provider();
24+
25+
async function validate(
26+
document: TextDocument,
27+
type: AutoValidation | undefined
28+
) {
29+
if (enabledLanguages.includes(document.languageId)) {
30+
const validation = getAutoValidation(document);
31+
if (!type || type === validation) {
32+
validations.set(document.uri, await provider.validate(document));
33+
} else if (validation !== AutoValidation.ALWAYS) {
34+
validations.delete(document.uri);
35+
}
36+
}
37+
}
2438

39+
export function activate(context: ExtensionContext) {
2540
context.subscriptions.push(
2641
languages.registerCompletionItemProvider(enabledLanguages, provider),
2742
languages.registerDefinitionProvider(enabledLanguages, provider),
2843
workspace.onDidSaveTextDocument(async (document) => {
2944
invalidate(document.uri.toString());
30-
if (enabledLanguages.includes(document.languageId)) {
31-
const validation = getAutoValidation(document);
32-
if (validation === AutoValidation.SAVE) {
33-
validations.set(document.uri, await provider.validate(document));
34-
}
35-
}
45+
await validate(document, AutoValidation.SAVE);
3646
}),
3747
workspace.onDidOpenTextDocument(async (document) => {
38-
if (enabledLanguages.includes(document.languageId)) {
39-
const validation = getAutoValidation(document);
40-
if (validation === AutoValidation.ALWAYS) {
41-
validations.set(document.uri, await provider.validate(document));
42-
}
43-
}
48+
await validate(document, AutoValidation.ALWAYS);
4449
}),
4550
workspace.onDidChangeTextDocument(async (event) => {
46-
const document = event.document;
47-
if (enabledLanguages.includes(document.languageId)) {
48-
const validation = getAutoValidation(document);
49-
if (validation === AutoValidation.ALWAYS) {
50-
validations.set(document.uri, await provider.validate(document));
51-
} else {
52-
validations.delete(document.uri);
53-
}
51+
if (event.contentChanges.length > 0) {
52+
await validate(event.document, AutoValidation.ALWAYS);
5453
}
5554
}),
5655
workspace.onDidCloseTextDocument((document) => {
5756
validations.delete(document.uri);
5857
}),
59-
commands.registerCommand("vscode-html-css.validate", async () => {
60-
const editor = window.activeTextEditor;
61-
if (editor) {
62-
const document = editor.document;
63-
if (enabledLanguages.includes(document.languageId)) {
64-
validations.set(document.uri, await provider.validate(document));
58+
commands.registerCommand(
59+
"vscode-html-css.validate",
60+
async (type: AutoValidation | undefined) => {
61+
const editor = window.activeTextEditor;
62+
if (editor) {
63+
await validate(editor.document, type);
6564
}
6665
}
67-
}),
66+
),
6867
commands.registerCommand("vscode-html-css.clear", () => clear())
6968
);
69+
70+
return commands.executeCommand(
71+
"vscode-html-css.validate",
72+
AutoValidation.ALWAYS
73+
);
7074
}
7175

7276
export function deactivate() {}

src/provider.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -238,6 +238,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
238238
}
239239

240240
export function clear() {
241+
window.showInformationMessage(`CSS: Style cache (${cache.size}) cleared.`);
241242
cache.clear();
242243
}
243244

0 commit comments

Comments
 (0)