Skip to content

Commit

Permalink
test: add tests for hide and show
Browse files Browse the repository at this point in the history
Fix a regression in hide functionality
  • Loading branch information
wkillerud committed Nov 18, 2023
1 parent 8ccf768 commit 896d2b8
Show file tree
Hide file tree
Showing 20 changed files with 123 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@forward "./base" hide $color-white;
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$color-black: black;
$color-grey: grey;
$color-white: white;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@forward "./base" hide $color-black;
3 changes: 3 additions & 0 deletions fixtures/unit/completion/multi-level-hide/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "./colors";

$text-color: colors.|
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@forward "./branch-a" hide $color-white;
@forward "./branch-b";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$color-white: white;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@forward "./base";
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$color-white: white;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@forward "./base";
3 changes: 3 additions & 0 deletions fixtures/unit/completion/same-symbol-name-hide/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "./colors";

$text-color: colors.|
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
@forward "./branch-a" show $color-black;
@forward "./branch-b";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$color-black: black;
$color-grey: grey;
$color-white: white;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@forward "./base";
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
$color-black: black;
$color-grey: grey;
$color-white: white;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
@forward "./base";
3 changes: 3 additions & 0 deletions fixtures/unit/completion/same-symbol-name-show/styles.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
@use "./colors";

$text-color: colors.|
6 changes: 2 additions & 4 deletions server/src/features/completion/completion.ts
Original file line number Diff line number Diff line change
Expand Up @@ -305,10 +305,6 @@ function traverseTree(

accumulator.set(leaf.uri, completionItems);

// Reset these once we've processed the document they refered to
let hidden: string[] = [];
let shown: string[] = [];

// Check to see if we have to go deeper
// Don't follow uses, since we start with the document behind the first use, and symbols from further uses aren't available to us
// Don't follow imports, since the whole point here is to use the new module system
Expand All @@ -322,6 +318,8 @@ function traverseTree(
continue;
}

let hidden = hiddenSymbols;
let shown = shownSymbols;
if (
(child as ScssForward).hide &&
(child as ScssForward).hide.length > 0
Expand Down
89 changes: 89 additions & 0 deletions server/src/test/features/completion-visibility.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
import * as assert from "assert";
import { changeConfiguration, useContext } from "../../context-provider";
import { doCompletion } from "../../features/completion";
import { NodeFileSystem } from "../../node-file-system";
import { IScssDocument } from "../../parser";
import ScannerService from "../../scanner";
import { getUri } from "../fixture-helper";
import * as helpers from "../helpers";

describe("Providers/Completion", () => {
beforeEach(async () => {
helpers.createTestContext(new NodeFileSystem());

const settings = helpers.makeSettings({
suggestFromUseOnly: true,
});
changeConfiguration(settings);
});

describe("Hide", () => {
it("supports multi-level hiding", async () => {
const workspaceUri = getUri("completion/multi-level-hide/");
const docUri = getUri("completion/multi-level-hide/styles.scss");
const scanner = new ScannerService();
await scanner.scan([docUri], workspaceUri);
const { storage } = useContext();
const stylesDoc = storage.get(docUri) as IScssDocument;

const completions = await doCompletion(
stylesDoc,
stylesDoc.getText().indexOf("|"),
);

// $color-black and $color-white are hidden at different points

assert.equal(
completions.items.length,
1,
"Expected only one suggestion from the multi-level-hide fixture",
);
assert.equal(completions.items[0].label, "$color-grey");
});

it("doesn't hide symbol with same name in different part of dependency graph", async () => {
const workspaceUri = getUri("completion/same-symbol-name-hide/");
const docUri = getUri("completion/same-symbol-name-hide/styles.scss");
const scanner = new ScannerService();
await scanner.scan([docUri], workspaceUri);
const { storage } = useContext();
const stylesDoc = storage.get(docUri) as IScssDocument;

const completions = await doCompletion(
stylesDoc,
stylesDoc.getText().indexOf("|"),
);

// $color-white is hidden in branch-a, but not in branch-b
assert.equal(
completions.items.length,
1,
"Expected a suggestion from the same-symbol-name-hide fixture",
);
assert.equal(completions.items[0].label, "$color-white");
});
});

describe("Show", () => {
it("doesn't show symbol with same name in different part of dependency graph", async () => {
const workspaceUri = getUri("completion/same-symbol-name-show/");
const docUri = getUri("completion/same-symbol-name-show/styles.scss");
const scanner = new ScannerService();
await scanner.scan([docUri], workspaceUri);
const { storage } = useContext();
const stylesDoc = storage.get(docUri) as IScssDocument;

const completions = await doCompletion(
stylesDoc,
stylesDoc.getText().indexOf("|"),
);

// One branch only shows $color-black, but the other has three symbols including another $color-black
assert.equal(
completions.items.length,
4,
"Expected four suggestions from the same-symbol-name-show fixture",
);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from "path";
import { URI } from "vscode-uri";

function getDocPath(p: string) {
return path.resolve(__dirname, "../../../../fixtures/unit", p);
return path.resolve(__dirname, "../../../fixtures/unit", p);
}

export function getUri(p: string) {
Expand Down
2 changes: 1 addition & 1 deletion server/src/test/scanner/scanner.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { isMatch } from "micromatch";
import { useContext } from "../../context-provider";
import { NodeFileSystem } from "../../node-file-system";
import ScannerService from "../../scanner";
import { getUri } from "../fixture-helper";
import * as helpers from "../helpers";
import { getUri } from "./scanner-helper";

describe("Services/Scanner", () => {
beforeEach(() => {
Expand Down

0 comments on commit 896d2b8

Please sign in to comment.