Skip to content

Commit

Permalink
Update test
Browse files Browse the repository at this point in the history
  • Loading branch information
ecmel committed Jan 11, 2021
1 parent 2d56c72 commit 1425feb
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
18 changes: 9 additions & 9 deletions src/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import {
workspace
} from "vscode";

export type Completion = {
export type Selector = {
ids: Map<string, CompletionItem>,
classes: Map<string, CompletionItem>
};
Expand Down Expand Up @@ -197,7 +197,7 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
}
}

async findAll(document: TextDocument): Promise<Completion> {
async findAll(document: TextDocument): Promise<Selector> {
const keys = new Set<string>();
const uri = document.uri;
const text = document.getText();
Expand All @@ -218,7 +218,7 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
}

async validate(document: TextDocument): Promise<Diagnostic[]> {
const completion = await this.findAll(document);
const selector = await this.findAll(document);
const text = document.getText();
const diagnostics: Diagnostic[] = [];
const findAttribute = /(id|class|className)\s*=\s*("|')(.*?)\2/gsi;
Expand All @@ -240,13 +240,13 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
const start = document.positionAt(anchor - value[1].length);

if (attribute[1] === "id") {
if (!completion.ids.has(value[1])) {
if (!selector.ids.has(value[1])) {
diagnostics.push(new Diagnostic(new Range(start, end),
`CSS id selector '${value[1]}' not found.`,
DiagnosticSeverity.Information));
}
} else {
if (!completion.classes.has(value[1])) {
if (!selector.classes.has(value[1])) {
diagnostics.push(new Diagnostic(new Range(start, end),
`CSS class selector '${value[1]}' not found.`,
DiagnosticSeverity.Information));
Expand All @@ -270,10 +270,10 @@ export class SelectorCompletionItemProvider implements CompletionItemProvider, D
const canComplete = this.canComplete.exec(text);

if (canComplete) {
this.findAll(document).then(completion => resolve([
...(canComplete[1] === "id"
? completion.ids
: completion.classes).values()]));
this.findAll(document).then(selector => resolve(
[...(canComplete[1] === "id"
? selector.ids
: selector.classes).values()]));
} else {
reject();
}
Expand Down
2 changes: 1 addition & 1 deletion src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@ import { SelectorCompletionItemProvider } from "./completion";
import { ExtensionContext, commands, languages, window, workspace } from "vscode";

export function activate(context: ExtensionContext) {
const validations = languages.createDiagnosticCollection();
const config = workspace.getConfiguration("css");
const enabledLanguages = config.get<string[]>("enabledLanguages", ["html"]);
const validations = languages.createDiagnosticCollection();
const provider = new SelectorCompletionItemProvider();

context.subscriptions.push(
Expand Down
2 changes: 1 addition & 1 deletion src/test/suite/completion.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ suite("SelectorCompletionItemProvider Test Suite", () => {
token,
context) as Thenable<CompletionItem[]>;

result.then(items => done(new Error("Should reject!")), () => done());
result.then(() => done(new Error("Should reject!")), () => done());
});

test("Completes from style tag", async () => {
Expand Down

0 comments on commit 1425feb

Please sign in to comment.