Skip to content

Commit dec6d0c

Browse files
committed
Add filename to description to improve matching for file templates
Fixes #124
1 parent 63c7411 commit dec6d0c

File tree

2 files changed

+9
-19
lines changed

2 files changed

+9
-19
lines changed

src/extension/competitiveCompanion.ts

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,9 @@ async function processProblem(problem: Problem, judge: JudgeViewProvider): Promi
144144

145145
if (needsPrompt) {
146146
// Gather files before prompting to include newly created files from previous problems
147-
const updatedFiles = await gatherWorkspaceFiles();
147+
const include = config.get<string>("includePattern")!;
148+
const exclude = config.get<string>("excludePattern")!;
149+
const updatedFiles = await vscode.workspace.findFiles(include, exclude);
148150
relativePath = await promptForTargetFile(
149151
problem,
150152
workspaceRoot,
@@ -194,16 +196,6 @@ async function processProblem(problem: Problem, judge: JudgeViewProvider): Promi
194196
}
195197
}
196198

197-
/**
198-
* Gather files using VSCode's API with include and exclude patterns from settings.
199-
*/
200-
async function gatherWorkspaceFiles(): Promise<vscode.Uri[]> {
201-
const config = vscode.workspace.getConfiguration("fastolympiccoding");
202-
const includePattern = config.get<string>("includePattern")!;
203-
const excludePattern = config.get<string>("excludePattern")!;
204-
return vscode.workspace.findFiles(includePattern, excludePattern);
205-
}
206-
207199
/**
208200
* Creates the request handler for the Competitive Companion HTTP server.
209201
*/

src/extension/index.ts

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,16 @@ function registerCommands(context: vscode.ExtensionContext): void {
202202
const config = vscode.workspace.getConfiguration("fastolympiccoding");
203203
const dependencies = config.get<Dependencies>("fileTemplatesDependencies");
204204
const baseDirectory = resolveVariables(config.get("fileTemplatesBaseDirectory")!);
205-
const files = (
206-
await fs.readdir(baseDirectory, {
207-
recursive: true,
208-
withFileTypes: true,
209-
})
210-
).filter((value) => value.isFile());
205+
const workspaceRoot = vscode.workspace.workspaceFolders?.at(0)?.uri.fsPath ?? "";
206+
const relativeBaseDirectory = path.relative(workspaceRoot, baseDirectory);
207+
const files = await vscode.workspace.findFiles(`${relativeBaseDirectory}/**`);
211208
const items = files.map((file) => ({
212-
label: file.name,
213-
description: file.path,
209+
label: path.parse(file.fsPath).base,
210+
description: path.relative(workspaceRoot, file.fsPath),
214211
}));
215212
const pickedFile = await vscode.window.showQuickPick(items, {
216213
title: "Insert File Template",
214+
matchOnDescription: true,
217215
});
218216
if (!pickedFile) {
219217
return;

0 commit comments

Comments
 (0)