@@ -11,6 +11,8 @@ import { renderMainHeader } from "../sections";
1111export type StateErrorNavigation = {
1212 index : number ;
1313 count : number ;
14+ // the 1-based line of the shown error, if any error is shown
15+ line ?: number | null ;
1416} ;
1517
1618const NO_STATE_ERROR_NAVIGATION : StateErrorNavigation = { index : - 1 , count : 0 } ;
@@ -48,7 +50,9 @@ function renderStateMachineViewHtml(sm: LJStateMachine | undefined, diagram: str
4850 ${ renderCodiconButton ( "copy" , { id : "copy-diagram-btn" , className : "diagram-control-btn" , title : "Copy Mermaid Source" } ) }
4951 </div>
5052 </div>
51- ${ errorFocus ? renderStateErrorSummary ( errorFocus , stateErrors ) + renderStateErrorLegend ( errorFocus , focusOnError ) : '' }
53+ ${ errorFocus
54+ ? renderStateErrorSummary ( getStateErrorSummary ( errorFocus ) , stateErrors ) + renderStateErrorLegend ( errorFocus , focusOnError )
55+ : isStateErrorShown ( stateErrors ) ? renderStateErrorSummary ( getUnmarkedStateErrorSummary ( sm , stateErrors ) , stateErrors ) : '' }
5256 ${ showConditions && hasConditionExpansions ? /*html*/ `
5357 <div class="diagram-condition-legend">
5458 <span class="diagram-condition-legend-pre">Precondition</span>
@@ -67,7 +71,11 @@ function renderStateMachineViewHtml(sm: LJStateMachine | undefined, diagram: str
6771 ` ;
6872}
6973
70- function renderStateErrorSummary ( focus : StateErrorFocus , stateErrors : StateErrorNavigation ) : string {
74+ function isStateErrorShown ( stateErrors : StateErrorNavigation ) : boolean {
75+ return stateErrors . index >= 0 || stateErrors . line !== undefined ;
76+ }
77+
78+ function getStateErrorSummary ( focus : StateErrorFocus ) : string {
7179 const call = getRejectedCallText ( focus ) ;
7280 const receiver = focus . receiver ? `<code>${ escapeHtml ( focus . receiver ) } </code>` : 'the receiver' ;
7381 const rejected = `${ call ? `<code>${ escapeHtml ( call ) } </code>` : 'The call' } is rejected` ;
@@ -81,6 +89,20 @@ function renderStateErrorSummary(focus: StateErrorFocus, stateErrors: StateError
8189 summary = `${ rejected } here` ;
8290 }
8391 if ( allowedStates . length > 0 ) summary += ` \u00B7 allowed in state ${ renderStates ( allowedStates ) } ` ;
92+ return summary ;
93+ }
94+
95+ // the shown error cannot be marked on the diagram when the verifier could not tell which states allow the call
96+ function getUnmarkedStateErrorSummary ( sm : LJStateMachine , stateErrors : StateErrorNavigation ) : string {
97+ const context = sm . errorContext ;
98+ if ( context ?. calledMethod ) {
99+ const call = `${ context . receiver ? `${ context . receiver } .` : '' } ${ context . calledMethod } ()` ;
100+ return `<code>${ escapeHtml ( call ) } </code> is rejected here` ;
101+ }
102+ return stateErrors . line ? `The call at line ${ stateErrors . line } is rejected` : 'The call is rejected' ;
103+ }
104+
105+ function renderStateErrorSummary ( summary : string , stateErrors : StateErrorNavigation ) : string {
84106 return /*html*/ `
85107 <div class="diagram-error-summary">
86108 <p class="diagram-error-text">${ summary } </p>
0 commit comments