Skip to content

Commit

Permalink
more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Jan 1, 2024
1 parent ada4a0b commit 1cbd85a
Show file tree
Hide file tree
Showing 7 changed files with 334 additions and 21 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

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

## [2.0.2] - 2024-01-01
## [2.0.3] - 2024-01-01

- Go to definition support
- Ported to custom parser
Expand Down
189 changes: 187 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 3 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"name": "vscode-html-css",
"displayName": "HTML CSS Support",
"description": "CSS Intellisense for HTML",
"version": "2.0.2",
"version": "2.0.3",
"license": "MIT",
"publisher": "ecmel",
"author": {
Expand Down Expand Up @@ -105,6 +105,7 @@
"@types/line-column": "^1.0.2",
"@types/mocha": "^10.0.6",
"@types/node": "^20.10.6",
"@types/sinon": "^17.0.2",
"@types/vscode": "^1.66.0",
"@vscode/test-electron": "^2.3.8",
"@vscode/vsce": "^2.22.0",
Expand All @@ -114,6 +115,7 @@
"mocha": "^10.2.0",
"prettier": "^2.8.8",
"rollup": "^4.9.2",
"sinon": "^17.0.1",
"tslib": "^2.6.2",
"typescript": "^5.3.3"
}
Expand Down
27 changes: 13 additions & 14 deletions src/provider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,30 +74,28 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
private async getStyles(document: TextDocument) {
const styles = new Map<string, Style[]>();
const folder = workspace.getWorkspaceFolder(document.uri);

if (folder) {
const sheets = getStyleSheets(document.uri);
for (const sheet of sheets) {
if (isRemote.test(sheet)) {
styles.set(sheet, await this.getRemote(sheet));
} else {
const files = await workspace.findFiles(
new RelativePattern(folder, sheet).pattern
);
for (const file of files) {
styles.set(file.toString(), await this.getLocal(file));
}
const sheets = getStyleSheets(document.uri);

for (const sheet of sheets) {
if (isRemote.test(sheet)) {
styles.set(sheet, await this.getRemote(sheet));
} else if (folder) {
const files = await workspace.findFiles(
new RelativePattern(folder, sheet).pattern
);
for (const file of files) {
styles.set(file.toString(), await this.getLocal(file));
}
}
}
styles.set(document.uri.toString(), parse(document.getText()));

return styles;
}

private async getCompletionMap(document: TextDocument, type: StyleType) {
const map = new Map<string, CompletionItem>();
const styles = await this.getStyles(document);

for (const value of styles.values()) {
for (const style of value) {
if (style.type === type) {
Expand All @@ -122,6 +120,7 @@ export class Provider implements CompletionItemProvider, DefinitionProvider {
const map = await this.getCompletionMap(document, type);
const range = document.getWordRangeAtPosition(position, wordRange);
const items = [];

for (const item of map.values()) {
item.range = range;
items.push(item);
Expand Down
24 changes: 21 additions & 3 deletions test/suite/extension.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,38 @@
* Licensed under the MIT License
*/

import * as assert from "assert";
import assert from "assert";
import { describe, it } from "mocha";
import { CompletionList, Position, commands, workspace } from "vscode";

suite("Extension Test Suite", () => {
test("should complete for html", async () => {
describe("extension", () => {
it("should suggest completion for html class tags", async () => {
const document = await workspace.openTextDocument({
language: "html",
content: "<style>.selector{}</style>\n<a class='selecto'></a>",
});

const list = await commands.executeCommand<CompletionList>(
"vscode.executeCompletionItemProvider",
document.uri,
new Position(1, 17)
);

assert.ok(list.items.find((item) => item.label === "selector"));
});

it("should suggest completion for html id tags", async () => {
const document = await workspace.openTextDocument({
language: "html",
content: "<style>#selector{}</style>\n<a id='selecto'></a>",
});

const list = await commands.executeCommand<CompletionList>(
"vscode.executeCompletionItemProvider",
document.uri,
new Position(1, 14)
);

assert.ok(list.items.find((item) => item.label === "selector"));
});
});
Loading

0 comments on commit 1cbd85a

Please sign in to comment.