Файли
openidea/src/editor/core/cm/docLineComment.test.ts
T
l0ng-ai b20e0b0902 fix(editor): continue Rust /// documentation comments on Enter (#5107)
Enter after `/// Summary` above a Rust function gave a blank line: `enterInLineComment` only splits a comment when text follows the caret, so at the end of the line nothing continued the documentation. RustRover (and Rider for C#) continue documentation line comments.

`enterAfterDocLineComment` handles Enter at the end of a `///` line (Rust, C#, Dart, Swift, F#) or a Rust `//!` line: the next line gets the same indentation and prefix, caret after `/// `. Plain `//` comments and `////` banners are unchanged, as is Enter in the middle of a comment (still split by `enterInLineComment`).
2026-11-22 11:21:28 +08:00

33 рядки
1.3 KiB
TypeScript

import { afterEach, describe, expect, it } from "vitest";
import { EditorState } from "@codemirror/state";
import { EditorView } from "@codemirror/view";
import { enterAfterDocLineComment } from "./comments";
const views: EditorView[] = [];
afterEach(() => views.splice(0).forEach((v) => v.destroy()));
function enter(doc: string, language: string): string | null {
const anchor = doc.indexOf("|");
const v = new EditorView({ state: EditorState.create({ doc: doc.replace("|", ""), selection: { anchor } }) });
views.push(v);
if (!enterAfterDocLineComment(language)(v)) return null;
const s = v.state;
const h = s.selection.main.head;
return s.sliceDoc(0, h) + "|" + s.sliceDoc(h);
}
describe("Enter after a documentation line comment", () => {
it("continues /// and //! in Rust", () => {
expect(enter("/// Summary|\nfn f() {}", "rust")).toBe("/// Summary\n/// |\nfn f() {}");
expect(enter(" //! Crate docs|", "rust")).toBe(" //! Crate docs\n //! |");
expect(enter("/// Summary|", "csharp")).toBe("/// Summary\n/// |");
});
it("leaves plain comments, mid-line carets and other languages alone", () => {
expect(enter("// note|", "rust")).toBeNull();
expect(enter("//// banner|", "rust")).toBeNull();
expect(enter("/// Sum|mary", "rust")).toBeNull();
expect(enter("/// Summary|", "go")).toBeNull();
});
});