Порівняти коміти

...
Автор SHA1 Повідомлення Дата
l0ng-ai 3ccb499fec fix(search): exact Windows file URLs, and search again after a multi-line replace
- Search Everywhere decodes file URLs and strips the slash before a drive letter.
- A pattern that may match a line break, or a run that replaced fewer targets than planned, searches again instead of marking stale positions as replaced.
2026-11-18 11:34:48 +08:00
l0ng-ai cd370ed89a fix(search): a Windows workspace module scope searches the module's own folder 2026-11-18 11:34:48 +08:00
10 змінених файлів з 45 додано та 9 видалено

No files matched your search

+2 -1
Переглянути файл
@@ -115,7 +115,8 @@ export function declaredCatalogs(settings: string): DeclaredCatalog[] {
}
const readText = (path: string) => call(commands.fsReadText(path)).catch(() => null);
const join = (dir: string, rel: string) => (rel.startsWith("/") ? rel : `${dir}/${rel.replace(/^\.\//, "")}`);
const join = (dir: string, rel: string) =>
rel.startsWith("/") || /^[A-Za-z]:[\\/]/.test(rel) ? rel : `${dir}/${rel.replace(/^\.\//, "")}`;
/**
* The catalogs a build script sees: those of the nearest enclosing build (its settings file).
+6
Переглянути файл
@@ -41,6 +41,12 @@ describe("Find in Files module and custom scopes", () => {
path: "/p/web",
});
expect(resolveFindScope({ ...base, scopeTab: "module", module: "" }, inputs)).toEqual({ kind: "project" });
// A Windows workspace member is a drive-letter path, not one under the first project (#4069).
const windows = { ...inputs, root: "C:/tmp/alpha" };
expect(resolveFindScope({ ...base, scopeTab: "module", module: "C:/tmp/beta" }, windows)).toEqual({
kind: "directory",
path: "C:/tmp/beta",
});
});
it("named scopes resolve to file sets, files and custom patterns", () => {
+2
Переглянути файл
@@ -35,6 +35,8 @@ describe("parseLocationQuery", () => {
expect(parseLocationQuery('"src/a.ts"').text).toBe("src/a.ts");
expect(parseLocationQuery("file:///dev/acme/My%20File.kt", "/dev/acme").text).toBe("My File.kt");
expect(parseLocationQuery("src\\main\\App.kt").text).toBe("src/main/App.kt");
// Windows file URLs, with a space and an encoded `#` in the name (#4079).
expect(parseLocationQuery("file:///C:/work/sample/src/a%20b%23c.txt", "C:/work/sample").text).toBe("src/a b#c.txt");
});
it("selectionOf maps to an editor selection", () => {
+12
Переглянути файл
@@ -8,6 +8,7 @@ import {
countUsages,
groupState,
markDone,
mayMatchLineBreak,
nextPending,
pendingUsages,
replacePreviewLines,
@@ -217,3 +218,14 @@ describe("replace previews", () => {
]);
});
});
describe("mayMatchLineBreak", () => {
it("tells patterns whose matches can span lines (#4082)", () => {
expect(mayMatchLineBreak("JOIN\\nTARGET", true)).toBe(true);
expect(mayMatchLineBreak("a\\s+b", true)).toBe(true);
expect(mayMatchLineBreak("[^x]", true)).toBe(true);
expect(mayMatchLineBreak("JOIN.TARGET", true)).toBe(false);
expect(mayMatchLineBreak("JOIN\nTARGET", false)).toBe(true);
expect(mayMatchLineBreak("a\\nb", false)).toBe(false);
});
});
+4 -1
Переглянути файл
@@ -23,10 +23,13 @@ export function parseLocationQuery(raw: string, root?: string | null): ParsedQue
if (/^file:\/\//i.test(text)) {
text = text.replace(/^file:\/\//i, "");
try {
text = decodeURI(text);
// Component decoding: `%23` in a file name is a `#`, not a fragment.
text = decodeURIComponent(text);
} catch {
/* keep as is */
}
// `file:///C:/x` names `C:/x` on Windows.
if (/^\/[a-zA-Z]:\//.test(text)) text = text.slice(1);
}
if (/^[a-zA-Z]:\\/.test(text) || (text.includes("\\") && !text.includes("/"))) text = text.replace(/\\/g, "/");
+9 -2
Переглянути файл
@@ -41,6 +41,7 @@ import {
groupState,
loadReplacePreview,
markDone,
mayMatchLineBreak,
nextPending,
pendingUsages,
replacePreviewLines,
@@ -362,8 +363,14 @@ function FindInFilesDialog() {
});
clearPreviewCache();
setPreviewVersion((v) => v + 1);
// Replacements that add or remove lines (or a stopped run) invalidate the positions found.
if (summary.cancelled || /\n|\\n/.test(s.replacement)) {
// Positions found are stale when lines were added or removed (a multi-line replacement or
// match), the run stopped, or a target no longer matched (#4082): search again.
if (
summary.cancelled ||
/\n|\\n/.test(s.replacement) ||
mayMatchLineBreak(s.pattern, s.isRegex) ||
summary.replacements < usages.length
) {
setRerun((r) => r + 1);
return null;
}
+6
Переглянути файл
@@ -300,3 +300,9 @@ export function replacePreviewLines(before: string, edits: readonly TextEdit[]):
for (let l = next; l < lines.length; l++) out.push({ kind: "same", line: l, text: lines[l] ?? "" });
return out;
}
/** Whether a match of `pattern` can span lines, so replacing it may remove line breaks. */
export function mayMatchLineBreak(pattern: string, regex: boolean): boolean {
if (!regex) return pattern.includes("\n");
return /\n|\\[nrsSWD]|\[\^/.test(pattern);
}
+1 -3
Переглянути файл
@@ -255,9 +255,7 @@ export function resolveFindScope(o: FindOptions, inputs: ScopeInputs): SearchSco
if (o.scopeTab === "directory" && o.directory.trim())
return { kind: "directory", path: resolveDirectory(o.directory, root) };
if (o.scopeTab === "module")
return o.module && root
? { kind: "directory", path: o.module.startsWith("/") ? o.module : `${root}/${o.module}` }
: { kind: "project" };
return o.module && root ? { kind: "directory", path: resolveDirectory(o.module, root) } : { kind: "project" };
if (o.scopeTab !== "scope") return { kind: "project" };
const custom = customScopeName(o.namedScope);
if (custom !== null) {
+1
Переглянути файл
@@ -231,6 +231,7 @@ describe("markdown preview rendering", () => {
});
expect(resolveLink(file, "javascript:alert(1)")).toBeNull();
expect(joinPath("C:/repo/docs", "../a.md")).toBe("C:/repo/a.md");
expect(joinPath("C:/repo/docs", "D:/shared/a.md")).toBe("D:/shared/a.md");
expect(joinPath("/repo", "../../a.md")).toBe("/a.md");
});
+2 -2
Переглянути файл
@@ -192,9 +192,9 @@ export type LinkTarget =
/** Directory of `file` (forward slashes). */
const dirOf = (file: string) => file.slice(0, Math.max(0, file.lastIndexOf("/")));
/** Joins `rel` onto `dir`, resolving `.` / `..`. Absolute `rel` (leading `/`) is kept. */
/** Joins `rel` onto `dir`, resolving `.` / `..`. Absolute `rel` (`/…` or `C:/…`) is kept. */
export function joinPath(dir: string, rel: string): string {
const parts = (rel.startsWith("/") ? rel : `${dir}/${rel}`).split("/");
const parts = (rel.startsWith("/") || /^[A-Za-z]:\//.test(rel) ? rel : `${dir}/${rel}`).split("/");
const out: string[] = [];
for (const p of parts) {
if (p === "..") {