-
Notifications
You must be signed in to change notification settings - Fork 3.9k
fix: lsTool path management and improve workspace file resolution #8985
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
19f0815
de930a7
931d455
9a7d15b
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,7 @@ | ||
| import { expect, test, vi } from "vitest"; | ||
| import { ToolExtras } from "../.."; | ||
| import * as walkDirModule from "../../indexing/walkDir"; | ||
| import { lsToolImpl, resolveLsToolDirPath } from "./lsTool"; | ||
| import { lsToolImpl } from "./lsTool"; | ||
|
|
||
| vi.mock("../../indexing/walkDir"); | ||
|
|
||
|
|
@@ -12,30 +12,6 @@ const mockExtras = { | |
| }, | ||
| } as unknown as ToolExtras; | ||
|
|
||
| test("resolveLsToolDirPath handles undefined path", () => { | ||
| expect(resolveLsToolDirPath(undefined)).toBe("/"); | ||
| }); | ||
|
|
||
| test("resolveLsToolDirPath handles empty string", () => { | ||
| expect(resolveLsToolDirPath("")).toBe("/"); | ||
| }); | ||
|
|
||
| test("resolveLsToolDirPath handles dot", () => { | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why remove these tests? Should we only remove the ones checking for empty path?
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The input path is now only processed through Is it better to test for those cases while testing In the original path parsing function (
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah, thanks for explaining. The simple reason is that "." doesn't work with our file reading and listing IDE utils, they require URIs, so we assume "." means relative. So you're right that it's a bug. I think the fix is that "." and "./" paths should resolve relative to the workspace URI root (first workspace if there are multiple) |
||
| expect(resolveLsToolDirPath(".")).toBe("/"); | ||
| }); | ||
|
|
||
| test("resolveLsToolDirPath handles dot relative", () => { | ||
| expect(resolveLsToolDirPath("./hi")).toBe("./hi"); | ||
| }); | ||
|
|
||
| test("resolveLsToolDirPath normalizes backslashes to forward slashes", () => { | ||
| expect(resolveLsToolDirPath("path\\to\\dir")).toBe("path/to/dir"); | ||
| }); | ||
|
|
||
| test("resolveLsToolDirPath preserves forward slashes", () => { | ||
| expect(resolveLsToolDirPath("path/to/dir")).toBe("path/to/dir"); | ||
| }); | ||
|
|
||
| test("lsToolImpl truncates output when entries exceed MAX_LS_TOOL_LINES", async () => { | ||
| // Generate more than MAX_LS_TOOL_LINES entries (which is 200) | ||
| const mockEntries = Array.from({ length: 250 }, (_, i) => `file${i}.txt`); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -18,11 +18,11 @@ export interface ResolvedPath { | |
| */ | ||
| async function isUriWithinWorkspace(ide: IDE, uri: string): Promise<boolean> { | ||
| const workspaceDirs = await ide.getWorkspaceDirs(); | ||
| const { foundInDir } = findUriInDirs(uri, workspaceDirs); | ||
| const { foundInDir, uri: foundUri } = findUriInDirs(uri, workspaceDirs); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be unnecessary, foundUri and original uri should be the same
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, my bad, I didn't go deeper looking at the implementation of |
||
|
|
||
| // Check both: within workspace path AND file exists | ||
| if (foundInDir !== null) { | ||
| return await ide.fileExists(uri); | ||
| return await ide.fileExists(foundUri); | ||
| } | ||
|
|
||
| return false; | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@andreapizzato please add a
ContinueErrorReasonfor this or use an existing one