1- import type { LJDiagnostic , LJHint , SourcePosition } from "../../types/diagnostics" ;
1+ import type { LJDiagnostic , LJHint , LJSourceReference , SourcePosition } from "../../types/diagnostics" ;
22import { escapeHtml , getFileName } from "../utils" ;
33import { renderHighlightedExpression , renderHighlightedInlineExpression } from "../highlighting" ;
44import { getDiagnosticRevealTarget , getDiagnosticRevealTargetKey } from "../diagnostic-reveal" ;
55import { renderCodicon , renderCodiconButton } from "../icons" ;
6+ import { renderMessageText } from "../message-text" ;
67import { LJVariable } from "../../types/context" ;
78
89export const renderMainHeader = ( title : string , selectedTab : NavTab , badges = NO_NAV_BADGES ) : string => /*html*/ `
@@ -34,8 +35,9 @@ export function setHintOpen(key: string, open: boolean) {
3435 * Several call sequences are alternatives, so they are listed as options apart from the hints that explain the error
3536 * @param hints The hints of the diagnostic
3637 * @param key Identifies the diagnostic, so opened hints stay open after a new verification
38+ * @param references The places in the source the hints name
3739 */
38- export function renderHints ( hints : LJHint [ ] | undefined , key ?: string ) : string {
40+ export function renderHints ( hints : LJHint [ ] | undefined , key ?: string , references : LJSourceReference [ ] = [ ] ) : string {
3941 const shown = ( hints ?? [ ] ) . filter ( hint => hint . message . trim ( ) ) ;
4042 if ( shown . length === 0 ) return '' ;
4143 const options = shown . filter ( hint => hint . kind === 'call-sequence' ) ;
@@ -49,17 +51,26 @@ export function renderHints(hints: LJHint[] | undefined, key?: string): string {
4951 ${ listsOptions ? /*html*/ `
5052 <div class="hint-options">
5153 <p class="hint-options-title">Any one of these:</p>
52- <ul>${ options . map ( hint => `<li>${ renderHintMessage ( hint ) } </li>` ) . join ( '' ) } </ul>
54+ <ul>${ options . map ( hint => `<li>${ renderHintMessage ( hint , references ) } </li>` ) . join ( '' ) } </ul>
5355 </div>
5456 ` : '' }
55- ${ notes . map ( hint => `<div class="hint-note">${ renderHintMessage ( hint ) } </div>` ) . join ( '' ) }
57+ ${ notes . map ( hint => `<div class="hint-note">${ renderHintMessage ( hint , references ) } </div>` ) . join ( '' ) }
5658 </div>
5759 </details>
5860 ` ;
5961}
6062
61- function renderHintMessage ( hint : LJHint ) : string {
62- return `<span class="hint-message">${ escapeHtml ( hint . message . trim ( ) ) } </span>` ;
63+ function renderHintMessage ( hint : LJHint , references : LJSourceReference [ ] ) : string {
64+ return `<span class="hint-message">${ renderMessageText ( hint . message , references ) } </span>` ;
65+ }
66+
67+ /**
68+ * Renders the notes under the message of a diagnostic, such as where a value comes from, with their links
69+ */
70+ export function renderMessageNotes ( diagnostic : LJDiagnostic ) : string {
71+ if ( diagnostic . messageNotes . length === 0 ) return '' ;
72+ return /*html*/ `<div class="section message-notes">${ diagnostic . messageNotes
73+ . map ( note => `<p class="message-note">${ renderMessageText ( note , diagnostic . references ) } </p>` ) . join ( '' ) } </div>`;
6374}
6475
6576export const renderToggleSection = ( title : string , targetId : string , isExpanded : boolean = true ) : string => /*html*/ `
@@ -74,7 +85,7 @@ export const renderDiagnosticHeader = (title: string, message: string, actions =
7485 <h3>${ title } </h3>
7586 ${ actions . trim ( ) ? `<div class="diagnostic-actions">${ actions } </div>` : '' }
7687 </div>
77- <div class="diagnostic-header"><p>${ message } </p></div>
88+ <div class="diagnostic-header"><p>${ renderMessageText ( message ) } </p></div>
7889` ;
7990
8091export function renderDiagnosticDataAttributes ( diagnostic : LJDiagnostic ) : string {
@@ -97,7 +108,7 @@ export const renderLocation = (diagnostic: LJDiagnostic): string => {
97108 const links = positions . map ( renderLocationLink ) . join ( "\n" ) ;
98109 // the notes explain the declarations, so they are shown only under their links
99110 const notes = declarationPositions . length > 0 ? declaration ?. declarationNotes ?? [ ] : [ ] ;
100- const noteLines = notes . map ( note => `<span class="location-note">${ escapeHtml ( note ) } </span>` ) . join ( "" ) ;
111+ const noteLines = notes . map ( note => `<span class="location-note">${ renderMessageText ( note ) } </span>` ) . join ( "" ) ;
101112 return renderCustomSection ( title , /*html*/ `<pre>${ links } ${ noteLines } </pre>` ) ;
102113} ;
103114
0 commit comments