дзеркало
https://github.com/l0ng-ai/openidea.git
синхронізовано 2026-12-04 01:01:17 +02:00
fix(editor): mark problems that have no text to underline (#7812)
A problem whose range is empty (an error at the end of a file ending in a blank line) or covers only a line break was listed in Problems and on the marker bar but not drawn in the editor, because the theme hid CodeMirror's lint point. It now draws one column of the severity's usual underline as a zero-width inline block, so WebKit paints it on empty lines too; hints stay hidden and the reported range is unchanged. Closes #7784 Co-authored-by: og-orca <[email protected]>
Цей коміт міститься в:
2 files changed
+79
-26
No files matched your search
@@ -114,6 +114,38 @@ describe("toLintDiagnostics", () => {
|
||||
});
|
||||
|
||||
describe("editor diagnostics in a view", () => {
|
||||
it("marks a problem that has no text to underline", async () => {
|
||||
const path = "/p/eof.php";
|
||||
const view = new EditorView({
|
||||
state: EditorState.create({
|
||||
doc: "<?php\n\n$a = 1\n$b = 2;\n",
|
||||
extensions: [lspDoc.of({ doc: 1, path } as EditorDocContext), diagnosticsExtension()],
|
||||
}),
|
||||
parent: document.body,
|
||||
});
|
||||
const lineBreak = { range: { start: { line: 2, col: 6 }, end: { line: 3, col: 0 } } };
|
||||
setFileDiagnostics(path, "intelephense", [d(1, 0, 0, "warning"), d(2, 6, 6, "error", lineBreak), d(4, 0, 0)]);
|
||||
await Promise.resolve();
|
||||
const marks = [...view.contentDOM.querySelectorAll(".cm-lintPoint")].map((el) => el.className);
|
||||
expect(marks).toEqual([
|
||||
"cm-lintPoint cm-lintPoint-warning",
|
||||
"cm-lintPoint cm-lintPoint-error",
|
||||
"cm-lintPoint cm-lintPoint-error",
|
||||
]);
|
||||
// The mark is drawn like the underline of a range of the same severity.
|
||||
const style = (selector: string) =>
|
||||
[...document.styleSheets]
|
||||
.flatMap((sheet) => [...sheet.cssRules])
|
||||
.filter((rule) => rule instanceof CSSStyleRule)
|
||||
.findLast((rule) => rule.selectorText.endsWith(selector))?.style;
|
||||
expect(style(".cm-lintPoint:after")?.display).toBe("inline-block");
|
||||
for (const severity of ["error", "warning", "info"])
|
||||
expect(style(`.cm-lintPoint-${severity}:after`)?.cssText).toBe(style(`.cm-lintRange-${severity}`)?.cssText);
|
||||
expect(style(".cm-lintPoint-hint:after")?.display).toBe("none");
|
||||
view.destroy();
|
||||
setFileDiagnostics(path, "intelephense", []);
|
||||
});
|
||||
|
||||
it("skips a hidden view and catches up when it is shown again", async () => {
|
||||
const view = new EditorView({
|
||||
state: EditorState.create({
|
||||
|
||||
@@ -312,33 +312,39 @@ const diagnosticsSync = ViewPlugin.fromClass(
|
||||
// a yellow background (light, via --editor-warning-*); weak warnings dotted; typos wavy green.
|
||||
// WebKit drops a `text-decoration` with a style or colour; `-webkit-text-decoration`, set after
|
||||
// it, takes the whole value there.
|
||||
const errorEffect = {
|
||||
textDecoration: "var(--editor-error-decoration, underline wavy var(--danger))",
|
||||
WebkitTextDecoration: "var(--editor-error-decoration, underline wavy var(--danger))",
|
||||
fontWeight: "var(--wave-error-bold, inherit)",
|
||||
fontStyle: "var(--wave-error-italic, inherit)",
|
||||
textDecorationSkipInk: "none",
|
||||
textUnderlineOffset: "3px",
|
||||
};
|
||||
|
||||
const warningEffect = {
|
||||
textDecoration: "var(--editor-warning-decoration, underline wavy var(--warning))",
|
||||
WebkitTextDecoration: "var(--editor-warning-decoration, underline wavy var(--warning))",
|
||||
fontWeight: "var(--wave-warning-bold, inherit)",
|
||||
fontStyle: "var(--wave-warning-italic, inherit)",
|
||||
// Light schemes paint the warning as a background: fill the whole row like the selection
|
||||
// (inlineBg grows the mark's box to the row and centres a 1lh-capped fill in it).
|
||||
...inlineBackground("var(--editor-warning-background, transparent)"),
|
||||
textDecorationSkipInk: "none",
|
||||
textUnderlineOffset: "3px",
|
||||
};
|
||||
|
||||
const infoEffect = {
|
||||
textDecoration: "underline dotted color-mix(in srgb, var(--fg-muted) 80%, transparent)",
|
||||
WebkitTextDecoration: "underline dotted color-mix(in srgb, var(--fg-muted) 80%, transparent)",
|
||||
textDecorationSkipInk: "none",
|
||||
textUnderlineOffset: "3px",
|
||||
};
|
||||
|
||||
const lintTheme = EditorView.theme({
|
||||
".cm-lintRange": { backgroundImage: "none", paddingBlock: "0" },
|
||||
".cm-lintRange-error": {
|
||||
textDecoration: "var(--editor-error-decoration, underline wavy var(--danger))",
|
||||
WebkitTextDecoration: "var(--editor-error-decoration, underline wavy var(--danger))",
|
||||
fontWeight: "var(--wave-error-bold, inherit)",
|
||||
fontStyle: "var(--wave-error-italic, inherit)",
|
||||
textDecorationSkipInk: "none",
|
||||
textUnderlineOffset: "3px",
|
||||
},
|
||||
".cm-lintRange-warning": {
|
||||
textDecoration: "var(--editor-warning-decoration, underline wavy var(--warning))",
|
||||
WebkitTextDecoration: "var(--editor-warning-decoration, underline wavy var(--warning))",
|
||||
fontWeight: "var(--wave-warning-bold, inherit)",
|
||||
fontStyle: "var(--wave-warning-italic, inherit)",
|
||||
// Light schemes paint the warning as a background: fill the whole row like the selection
|
||||
// (inlineBg grows the mark's box to the row and centres a 1lh-capped fill in it).
|
||||
...inlineBackground("var(--editor-warning-background, transparent)"),
|
||||
textDecorationSkipInk: "none",
|
||||
textUnderlineOffset: "3px",
|
||||
},
|
||||
".cm-lintRange-info": {
|
||||
textDecoration: "underline dotted color-mix(in srgb, var(--fg-muted) 80%, transparent)",
|
||||
WebkitTextDecoration: "underline dotted color-mix(in srgb, var(--fg-muted) 80%, transparent)",
|
||||
textDecorationSkipInk: "none",
|
||||
textUnderlineOffset: "3px",
|
||||
},
|
||||
".cm-lintRange-error": errorEffect,
|
||||
".cm-lintRange-warning": warningEffect,
|
||||
".cm-lintRange-info": infoEffect,
|
||||
".cm-lintRange-hint": { textDecoration: "none" },
|
||||
// Typo level: IDEA's green wavy underline.
|
||||
".cm-lintRange.cm-lsp-typo": {
|
||||
@@ -375,7 +381,22 @@ const lintTheme = EditorView.theme({
|
||||
// The active warning keeps its fill: it is an image now, which the transparent colour below
|
||||
// does not touch.
|
||||
".cm-lintRange-active": { backgroundColor: "transparent" },
|
||||
".cm-lintPoint:after": { display: "none" },
|
||||
// A problem with no text of its own (on an empty line, on a line break) gets a mark one
|
||||
// column wide that takes no room in the line. An inline block, because WebKit does not
|
||||
// paint an inline box on a line that is 0 wide.
|
||||
".cm-lintPoint": { position: "static" },
|
||||
".cm-lintPoint-error:after": errorEffect,
|
||||
".cm-lintPoint-warning:after": warningEffect,
|
||||
".cm-lintPoint-info:after": infoEffect,
|
||||
".cm-lintPoint:after": {
|
||||
content: '"\\00a0"',
|
||||
position: "static",
|
||||
display: "inline-block",
|
||||
border: "none",
|
||||
paddingBlock: "0",
|
||||
marginRight: "-1ch",
|
||||
},
|
||||
".cm-lintPoint-hint:after": { display: "none" },
|
||||
});
|
||||
|
||||
export function diagnosticsExtension() {
|
||||
|
||||
Reference in new issue
Заблокувати користувача