Skip to content

Commit 1cbd85a

Browse files
committed
more tests
1 parent ada4a0b commit 1cbd85a

File tree

7 files changed

+334
-21
lines changed

7 files changed

+334
-21
lines changed

CHANGELOG.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

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

5-
## [2.0.2] - 2024-01-01
5+
## [2.0.3] - 2024-01-01
66

77
- Go to definition support
88
- Ported to custom parser

package-lock.json

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

package.json

Lines changed: 3 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": "2.0.2",
5+
"version": "2.0.3",
66
"license": "MIT",
77
"publisher": "ecmel",
88
"author": {
@@ -105,6 +105,7 @@
105105
"@types/line-column": "^1.0.2",
106106
"@types/mocha": "^10.0.6",
107107
"@types/node": "^20.10.6",
108+
"@types/sinon": "^17.0.2",
108109
"@types/vscode": "^1.66.0",
109110
"@vscode/test-electron": "^2.3.8",
110111
"@vscode/vsce": "^2.22.0",
@@ -114,6 +115,7 @@
114115
"mocha": "^10.2.0",
115116
"prettier": "^2.8.8",
116117
"rollup": "^4.9.2",
118+
"sinon": "^17.0.1",
117119
"tslib": "^2.6.2",
118120
"typescript": "^5.3.3"
119121
}

src/provider.ts

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,30 +74,28 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
7474
private async getStyles(document: TextDocument) {
7575
const styles = new Map<string, Style[]>();
7676
const folder = workspace.getWorkspaceFolder(document.uri);
77-
78-
if (folder) {
79-
const sheets = getStyleSheets(document.uri);
80-
for (const sheet of sheets) {
81-
if (isRemote.test(sheet)) {
82-
styles.set(sheet, await this.getRemote(sheet));
83-
} else {
84-
const files = await workspace.findFiles(
85-
new RelativePattern(folder, sheet).pattern
86-
);
87-
for (const file of files) {
88-
styles.set(file.toString(), await this.getLocal(file));
89-
}
77+
const sheets = getStyleSheets(document.uri);
78+
79+
for (const sheet of sheets) {
80+
if (isRemote.test(sheet)) {
81+
styles.set(sheet, await this.getRemote(sheet));
82+
} else if (folder) {
83+
const files = await workspace.findFiles(
84+
new RelativePattern(folder, sheet).pattern
85+
);
86+
for (const file of files) {
87+
styles.set(file.toString(), await this.getLocal(file));
9088
}
9189
}
9290
}
9391
styles.set(document.uri.toString(), parse(document.getText()));
94-
9592
return styles;
9693
}
9794

9895
private async getCompletionMap(document: TextDocument, type: StyleType) {
9996
const map = new Map<string, CompletionItem>();
10097
const styles = await this.getStyles(document);
98+
10199
for (const value of styles.values()) {
102100
for (const style of value) {
103101
if (style.type === type) {
@@ -122,6 +120,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
122120
const map = await this.getCompletionMap(document, type);
123121
const range = document.getWordRangeAtPosition(position, wordRange);
124122
const items = [];
123+
125124
for (const item of map.values()) {
126125
item.range = range;
127126
items.push(item);

test/suite/extension.test.ts

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,20 +3,38 @@
33
* Licensed under the MIT License
44
*/
55

6-
import * as assert from "assert";
6+
import assert from "assert";
7+
import { describe, it } from "mocha";
78
import { CompletionList, Position, commands, workspace } from "vscode";
89

9-
suite("Extension Test Suite", () => {
10-
test("should complete for html", async () => {
10+
describe("extension", () => {
11+
it("should suggest completion for html class tags", async () => {
1112
const document = await workspace.openTextDocument({
1213
language: "html",
1314
content: "<style>.selector{}</style>\n<a class='selecto'></a>",
1415
});
16+
1517
const list = await commands.executeCommand<CompletionList>(
1618
"vscode.executeCompletionItemProvider",
1719
document.uri,
1820
new Position(1, 17)
1921
);
22+
23+
assert.ok(list.items.find((item) => item.label === "selector"));
24+
});
25+
26+
it("should suggest completion for html id tags", async () => {
27+
const document = await workspace.openTextDocument({
28+
language: "html",
29+
content: "<style>#selector{}</style>\n<a id='selecto'></a>",
30+
});
31+
32+
const list = await commands.executeCommand<CompletionList>(
33+
"vscode.executeCompletionItemProvider",
34+
document.uri,
35+
new Position(1, 14)
36+
);
37+
2038
assert.ok(list.items.find((item) => item.label === "selector"));
2139
});
2240
});

0 commit comments

Comments
 (0)