Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions core/autocomplete/prefiltering/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,11 @@ export async function shouldPrefilter(
return true;
}

// Check whether we're in the continue config.json file
if (helper.filepath === getConfigJsonPath()) {
// Check whether we're in the continue config.json or config.yaml file
if (
helper.filepath === getConfigJsonPath() ||
helper.filepath === getConfigJsonPath().replace(/\.json$/, ".yaml")
) {
return true;
}

Expand Down
50 changes: 50 additions & 0 deletions core/autocomplete/prefiltering/prefiltering.vitest.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, expect, it, vi } from "vitest";

import { IDE } from "../..";
import { shouldPrefilter } from ".";
import { getConfigJsonPath } from "../../util/paths";
import { HelperVars } from "../util/HelperVars";
import { AutocompleteLanguageInfo } from "../constants/AutocompleteLanguageInfo";

describe("shouldPrefilter", () => {
const mockLanguage: AutocompleteLanguageInfo = {
name: "TypeScript",
topLevelKeywords: [],
singleLineComment: "//",
endOfLine: [";"],
};

const mockIde: IDE = {
getWorkspaceDirs: vi.fn().mockResolvedValue([]),
} as unknown as IDE;

function createMockHelper(filepath: string): HelperVars {
return {
filepath,
pos: { line: 0, character: 0 },
fileContents: "test content",
fileLines: ["test content"],
lang: mockLanguage,
options: {},
} as unknown as HelperVars;
}

it("returns true when helper.filepath matches getConfigJsonPath()", async () => {
const helper = createMockHelper(getConfigJsonPath());
const result = await shouldPrefilter(helper, mockIde);
expect(result).toBe(true);
});

it("returns true when helper.filepath matches config.yaml path", async () => {
const yamlPath = getConfigJsonPath().replace(/\.json$/, ".yaml");
const helper = createMockHelper(yamlPath);
const result = await shouldPrefilter(helper, mockIde);
expect(result).toBe(true);
});

it("returns false for a normal file path", async () => {
const helper = createMockHelper("file:///home/user/project/main.ts");
const result = await shouldPrefilter(helper, mockIde);
expect(result).toBe(false);
});
});
Loading