diff --git a/core/autocomplete/prefiltering/index.ts b/core/autocomplete/prefiltering/index.ts index b322b9e223c..9677e07e444 100644 --- a/core/autocomplete/prefiltering/index.ts +++ b/core/autocomplete/prefiltering/index.ts @@ -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; } diff --git a/core/autocomplete/prefiltering/prefiltering.vitest.ts b/core/autocomplete/prefiltering/prefiltering.vitest.ts new file mode 100644 index 00000000000..b71294471dd --- /dev/null +++ b/core/autocomplete/prefiltering/prefiltering.vitest.ts @@ -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); + }); +});