Файли
openidea/src/features/debugger/__tests__/codeLines.test.ts
T
Lee Dong Geon ff187a10f6 fix(debugger): put no breakpoint on blank or comment-only lines (#1678)
A gutter click, Toggle Line Breakpoint or Toggle Temporary Line Breakpoint on a blank or comment-only line added a breakpoint the debugger can never stop at. Those lines now take no new breakpoint; comments come from the syntax tree, so this works for every language with a parser, and only blank lines are skipped otherwise. An existing breakpoint on such a line can still be removed.

Fixes #1676

Co-authored-by: ldg030201 <[email protected]>
2026-11-06 13:13:50 +08:00

31 рядки
1.0 KiB
TypeScript

import { describe, expect, it } from "vitest";
import { EditorState } from "@codemirror/state";
import { java } from "@codemirror/lang-java";
import { lineHasCode } from "../breakpoints/codeLines";
const lines = (state: EditorState) => Array.from({ length: state.doc.lines }, (_, i) => lineHasCode(state, i));
describe("lines that take a breakpoint", () => {
it("skips blank and comment-only lines", () => {
const doc = [
"class A {",
"",
" \t",
" // note",
" /** doc",
" * more",
" */",
" int f() { return 1; } // trailing",
" /* a */ int x = 1;",
" /* a */ /* b */",
"}",
].join("\n");
const state = EditorState.create({ doc, extensions: [java()] });
expect(lines(state)).toEqual([true, false, false, false, false, false, false, true, true, false, true]);
});
it("only skips blank lines in a file without a parser", () => {
expect(lines(EditorState.create({ doc: "x\n\n \n// y" }))).toEqual([true, false, false, true]);
});
});