diff --git a/src/features/todo/model.ts b/src/features/todo/model.ts index 73fa89a49..cd5a844f9 100644 --- a/src/features/todo/model.ts +++ b/src/features/todo/model.ts @@ -71,10 +71,20 @@ export function buildTodoQuery(s: TodoSettings, scope: SearchScope = { kind: "pr }; } -const COMMENT_MARKER = /(\/\/|\/\*|^\s*\*|#|--|", + " ; TODO", // line-start ini comment + " % TODO", // line-start LaTeX comment + '""" TODO', // Python docstring + "''' TODO", + "x = 1; // TODO", // marker after whitespace, not just line start + "x (* TODO *)", // OCaml trailing comment + "x {- TODO -}", // Haskell trailing comment + // IDEA's default pattern matches anywhere inside a comment, so mentions count too: + "/** 业务类别:WORK_NOTICE 工作通知,TODO 待办。 */", // documents an enum value + "// fixed the TODO bug", + "/* see the TODO list */", + ]; + const drop = [ + "foo(); TODO", // statement separator + "if (a % 2) TODO", // modulo + "i--; TODO", // postfix decrement + 'let s = "a#b"; TODO', // # inside a string, no preceding space + "x = a--b; TODO", // -- with no preceding space + "see http://example.com TODO", // // inside a URL + '"//"; TODO', // // inside a string + "f(*) TODO", // OCaml-style wildcard + "a * b; TODO", // infix multiplication + ]; + + it.each(keep)("keeps %s", (line) => expect(looksLikeComment(`${line.slice(0, line.indexOf("TODO"))}`)).toBe(true)); + it.each(drop)("drops %s", (line) => expect(looksLikeComment(`${line.slice(0, line.indexOf("TODO"))}`)).toBe(false)); + + it("falls back to the lenient rule on truncated lines", () => { + // A 600-char shell line truncated by the backend: the window starts + // mid-line, so the leading rule cannot apply — any marker counts. + expect(looksLikeComment("very long code # remainder ", true)).toBe(true); + expect(looksLikeComment("very long code % remainder ", true)).toBe(true); + expect(looksLikeComment("i-- ", true)).toBe(true); + }); +}); + describe("query", () => { it("builds the keyword regex from enabled patterns", () => { expect(todoRegexSource(S)).toBe("\\b(TODO|FIXME|HACK|XXX)\\b.*");