@@ -13,16 +13,53 @@ export class AshCodeLensProvider implements vscode.CodeLensProvider {
1313 // Track disposables for cleanup
1414 private disposables : vscode . Disposable [ ] = [ ] ;
1515
16- // Cache the latest parse result
17- private latestParseResult : ReturnType <
18- AshParserService [ "documentActivated" ]
19- > | null = null ;
16+ // Internal code lens list, always reflects the latest parse event
17+ private codeLenses : vscode . CodeLens [ ] = [ ] ;
2018
2119 constructor ( private readonly parserService : AshParserService ) {
22- // Listen for parse events to refresh code lenses and update cache
20+ // Listen for parse events to update code lenses and trigger refresh
2321 this . disposables . push (
2422 this . parserService . onDidParse ( result => {
25- this . latestParseResult = result ;
23+ this . codeLenses = [ ] ;
24+ for ( const entry of result . codeLenses ) {
25+ // Create a range for the CodeLens
26+ const line = Math . max ( 0 , entry . line - 1 ) ; // Convert to 0-based line number
27+ const range = new vscode . Range (
28+ new vscode . Position ( line , entry . character ) ,
29+ new vscode . Position ( line , entry . character + 1 )
30+ ) ;
31+
32+ // Create the CodeLens with a command that opens the documentation URL
33+ const lens = new vscode . CodeLens ( range ) ;
34+
35+ // Debug logging
36+ Logger . getInstance ( ) . debug (
37+ "AshCodeLensProvider" ,
38+ `Creating code lens: ${ entry . title } -> ${ entry . target } `
39+ ) ;
40+
41+ // Assign command directly from entry
42+ if ( entry . command === "ash-studio.showDiagram" ) {
43+ lens . command = {
44+ title : entry . title ,
45+ command : entry . command ,
46+ arguments : [
47+ vscode . window . activeTextEditor ?. document . uri . fsPath ?? "" ,
48+ entry ,
49+ ] ,
50+ tooltip : `View diagram for ${ entry . source } ` ,
51+ } ;
52+ } else {
53+ const logger = Logger . getInstance ( ) ;
54+ logger . error (
55+ "Code Lens Provider" ,
56+ `Unknown Command ${ entry . command } `
57+ ) ;
58+ vscode . window . showErrorMessage ( `Unknown Command ${ entry . command } ` ) ;
59+ }
60+
61+ this . codeLenses . push ( lens ) ;
62+ }
2663 this . triggerCodeLensRefresh ( ) ;
2764 } )
2865 ) ;
@@ -38,75 +75,13 @@ export class AshCodeLensProvider implements vscode.CodeLensProvider {
3875 }
3976
4077 /**
41- * Provides CodeLens for the given document
78+ * Provides CodeLens for Ash DSL files
4279 */
43- async provideCodeLenses (
44- document : vscode . TextDocument ,
45- _token : vscode . CancellationToken
46- ) : Promise < vscode . CodeLens [ ] | null > {
80+ async provideCodeLenses ( ) : Promise < vscode . CodeLens [ ] > {
4781 if ( ! ConfigurationManager . getInstance ( ) . get ( "enableCodeLens" ) ) {
48- return null ;
49- }
50- try {
51- if ( ! this . latestParseResult ) {
52- return null ;
53- }
54- // Convert our CodeLensEntry objects to VS Code CodeLens objects
55- const codeLenses : vscode . CodeLens [ ] = [ ] ;
56- for ( const entry of this . latestParseResult . codeLenses ) {
57- // Create a range for the CodeLens
58- const line = Math . max ( 0 , entry . line - 1 ) ; // Convert to 0-based line number
59- const range = new vscode . Range (
60- new vscode . Position ( line , entry . character ) ,
61- new vscode . Position ( line , entry . character + 1 )
62- ) ;
63-
64- // Create the CodeLens with a command that opens the documentation URL
65- const lens = new vscode . CodeLens ( range ) ;
66-
67- // Debug logging
68- Logger . getInstance ( ) . debug (
69- "AshCodeLensProvider" ,
70- `Creating code lens: ${ entry . title } -> ${ entry . target } `
71- ) ;
72-
73- // Assign command directly from entry
74- if ( entry . command === "ash-studio.showDiagram" ) {
75- lens . command = {
76- title : entry . title ,
77- command : entry . command ,
78- arguments : [ document . uri . fsPath , entry ] ,
79- tooltip : `View diagram for ${ entry . source } ` ,
80- } ;
81- } else if ( entry . command === "ash-studio.openDocumentation" ) {
82- lens . command = {
83- title : entry . title ,
84- command : entry . command ,
85- arguments : [ entry . target ] ,
86- tooltip : `View documentation for ${ entry . source } ` ,
87- } ;
88- } else {
89- const logger = Logger . getInstance ( ) ;
90- logger . error (
91- "Code Lens Provicer" ,
92- `Unknown Command ${ entry . command } `
93- ) ;
94- vscode . window . showErrorMessage ( `Unknown Command ${ entry . command } ` ) ;
95- }
96-
97- codeLenses . push ( lens ) ;
98- }
99-
100- // Remove manual diagram CodeLens logic; all CodeLenses now come from parseResult.codeLenses
101-
102- return codeLenses ;
103- } catch ( error ) {
104- Logger . getInstance ( ) . error (
105- "AshCodeLensProvider" ,
106- `Error providing code lenses: ${ error } `
107- ) ;
108- return null ;
82+ return [ ] ;
10983 }
84+ return this . codeLenses ;
11085 }
11186
11287 /**
0 commit comments