mirror of
https://github.com/Kilo-Org/kilocode.git
synced 2026-09-19 01:51:21 +08:00
Merge pull request #6575 from Kilo-Org/fix/file-mention-prioritize-open-files
This commit is contained in:
@@ -442,10 +442,19 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
|
||||
const sdkClient = this.client
|
||||
if (sdkClient) {
|
||||
const dir = this.getWorkspaceDirectory(this.currentSession?.id)
|
||||
const openPaths = dir ? await this.getOpenTabPaths(dir) : new Set<string>()
|
||||
void sdkClient.find
|
||||
.files({ query: message.query, directory: dir }, { throwOnError: true })
|
||||
.then(({ data: paths }) => {
|
||||
this.postMessage({ type: "fileSearchResult", paths, dir, requestId: message.requestId })
|
||||
// Prioritize open files: open tabs first, then the rest
|
||||
const open = paths.filter((p) => openPaths.has(p))
|
||||
const rest = paths.filter((p) => !openPaths.has(p))
|
||||
this.postMessage({
|
||||
type: "fileSearchResult",
|
||||
paths: [...open, ...rest],
|
||||
dir,
|
||||
requestId: message.requestId,
|
||||
})
|
||||
})
|
||||
.catch((error: unknown) => {
|
||||
console.error("[Kilo New] File search failed:", error)
|
||||
@@ -549,7 +558,11 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
|
||||
case "enhancePrompt": {
|
||||
const sdkClient = this.client
|
||||
if (!sdkClient) {
|
||||
this.postMessage({ type: "enhancePromptError", error: "Not connected to CLI backend", requestId: message.requestId })
|
||||
this.postMessage({
|
||||
type: "enhancePromptError",
|
||||
error: "Not connected to CLI backend",
|
||||
requestId: message.requestId,
|
||||
})
|
||||
break
|
||||
}
|
||||
void sdkClient.enhancePrompt
|
||||
@@ -1895,6 +1908,29 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
|
||||
/**
|
||||
* Gather VS Code editor context to send alongside messages to the CLI backend.
|
||||
*/
|
||||
/**
|
||||
* Return the set of relative paths for all open text-editor tabs within the
|
||||
* given directory, filtered through .kilocodeignore.
|
||||
*/
|
||||
private async getOpenTabPaths(dir: string): Promise<Set<string>> {
|
||||
const controller = await this.getIgnoreController(dir)
|
||||
const result = new Set<string>()
|
||||
for (const group of vscode.window.tabGroups.all) {
|
||||
for (const tab of group.tabs) {
|
||||
if (tab.input instanceof vscode.TabInputText) {
|
||||
const uri = tab.input.uri
|
||||
if (uri.scheme === "file") {
|
||||
const rel = path.relative(dir, uri.fsPath)
|
||||
if (!rel.startsWith("..") && controller.validateAccess(uri.fsPath)) {
|
||||
result.add(rel.replaceAll("\\", "/"))
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Get or create a FileIgnoreController for the current workspace directory.
|
||||
* Reinitializes if the workspace directory has changed.
|
||||
@@ -1934,21 +1970,7 @@ export class KiloProvider implements vscode.WebviewViewProvider, TelemetryProper
|
||||
.slice(0, 200)
|
||||
|
||||
// Open tabs — use instanceof TabInputText to exclude notebooks, diffs, custom editors
|
||||
const openTabSet = new Set<string>()
|
||||
for (const group of vscode.window.tabGroups.all) {
|
||||
for (const tab of group.tabs) {
|
||||
if (tab.input instanceof vscode.TabInputText) {
|
||||
const uri = tab.input.uri
|
||||
if (uri.scheme === "file") {
|
||||
const rel = toRelative(uri.fsPath)
|
||||
if (rel && controller.validateAccess(uri.fsPath)) {
|
||||
openTabSet.add(rel)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
const openTabs = [...openTabSet].slice(0, 20)
|
||||
const openTabs = [...(await this.getOpenTabPaths(workspaceDir))].slice(0, 20)
|
||||
|
||||
// Active file (also filtered through .kilocodeignore)
|
||||
const activeEditor = vscode.window.activeTextEditor
|
||||
|
||||
@@ -1,9 +1,10 @@
|
||||
export function fileName(path: string): string {
|
||||
return path.replaceAll("\\", "/").split("/").pop() ?? path
|
||||
const normalized = path.replaceAll("\\", "/").replace(/\/+$/, "")
|
||||
return normalized.split("/").pop() ?? normalized
|
||||
}
|
||||
|
||||
export function dirName(path: string): string {
|
||||
const parts = path.replaceAll("\\", "/").split("/")
|
||||
const parts = path.replaceAll("\\", "/").replace(/\/+$/, "").split("/")
|
||||
if (parts.length <= 1) return ""
|
||||
const dir = parts.slice(0, -1).join("/")
|
||||
return dir.length > 30 ? `…/${parts.slice(-3, -1).join("/")}` : dir
|
||||
|
||||
Reference in New Issue
Block a user