File tree Expand file tree Collapse file tree 3 files changed +51
-1
lines changed
adev/src/app/editor/code-editor Expand file tree Collapse file tree 3 files changed +51
-1
lines changed Original file line number Diff line number Diff line change 128128 </ button >
129129 < ul >
130130 @for (error of errors(); track error) {
131- < li > (line: {{ error.lineNumber }}:{{ error.characterPosition }}) {{ error.message }}</ li >
131+ < li >
132+ < a
133+ class ="adev-error-location-link "
134+ href ="# "
135+ (click) ="$event.preventDefault(); openFileAtLocation(error) "
136+ >
137+ (line: {{ error.lineNumber }}:{{ error.characterPosition }})
138+ </ a >
139+ {{ error.message }}
140+ </ li >
132141 }
133142 </ ul >
134143 </ div >
Original file line number Diff line number Diff line change @@ -150,6 +150,25 @@ export class CodeEditor {
150150 this . displayErrorsBox . set ( false ) ;
151151 }
152152
153+ protected openFileAtLocation ( error : DiagnosticWithLocation ) : void {
154+ // Scroll the editor to the error location
155+ // The error is always in the current file since diagnostics are file-specific
156+ const lineNumber = error . lineNumber ;
157+ const characterPosition = error . characterPosition ;
158+
159+ // Calculate the position in the document
160+ // CodeMirror uses 0-based line numbers, but our error uses 1-based
161+ const line = Math . max ( 0 , lineNumber - 1 ) ;
162+
163+ // Request the editor to scroll to this line
164+ // We'll need to add a method to CodeMirrorEditor service to handle this
165+ this . codeMirrorEditor . scrollToLine ( line , characterPosition ) ;
166+ }
167+
168+ protected closeRenameFile ( ) : void {
169+ this . isRenamingFile . set ( false ) ;
170+ }
171+
153172 protected canRenameFile = ( filename : string ) => this . canDeleteFile ( filename ) ;
154173
155174 protected canDeleteFile ( filename : string ) {
Original file line number Diff line number Diff line change @@ -183,6 +183,28 @@ export class CodeMirrorEditor {
183183 this . _editorView . setState ( editorState ) ;
184184 }
185185
186+ scrollToLine ( line : number , character : number = 0 ) : void {
187+ if ( ! this . _editorView ) return ;
188+
189+ const state = this . _editorView . state ;
190+ const doc = state . doc ;
191+
192+ if ( line < 0 || line >= doc . lines ) {
193+ console . warn ( `Line ${ line } is out of bounds (0-${ doc . lines - 1 } )` ) ;
194+ return ;
195+ }
196+
197+ const lineObj = doc . line ( line + 1 ) ;
198+ const pos = lineObj . from + Math . min ( character , lineObj . length ) ;
199+
200+ this . _editorView . dispatch ( {
201+ selection : { anchor : pos , head : pos } ,
202+ scrollIntoView : true ,
203+ } ) ;
204+
205+ this . _editorView . focus ( ) ;
206+ }
207+
186208 private initTypescriptVfsWorker ( ) : void {
187209 if ( this . tsVfsWorker || ! this . tsVfsWorkerFactory ) {
188210 return ;
You can’t perform that action at this time.
0 commit comments