diff --git a/src/editor/lsp/diagnostics.test.ts b/src/editor/lsp/diagnostics.test.ts index 75953ce9ba..594b684d93 100644 --- a/src/editor/lsp/diagnostics.test.ts +++ b/src/editor/lsp/diagnostics.test.ts @@ -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: " 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({ diff --git a/src/editor/lsp/diagnostics.ts b/src/editor/lsp/diagnostics.ts index c695074a15..04739da48f 100644 --- a/src/editor/lsp/diagnostics.ts +++ b/src/editor/lsp/diagnostics.ts @@ -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() {