@@ -12,25 +12,25 @@ import { ConfigurationManager } from "../utils/config";
1212export class AshCodeLensProvider implements vscode . CodeLensProvider {
1313 // Track disposables for cleanup
1414 private disposables : vscode . Disposable [ ] = [ ] ;
15-
15+
1616 constructor ( private readonly parserService : AshParserService ) {
1717 // Listen for parse events to refresh code lenses when content changes
1818 this . disposables . push (
1919 this . parserService . onDidParse ( ( ) => {
2020 this . triggerCodeLensRefresh ( ) ;
2121 } )
2222 ) ;
23-
23+
2424 // Also listen for configuration changes that might affect code lens display
2525 this . disposables . push (
26- vscode . workspace . onDidChangeConfiguration ( ( event ) => {
26+ vscode . workspace . onDidChangeConfiguration ( event => {
2727 if ( event . affectsConfiguration ( "ashStudio.enableCodeLens" ) ) {
2828 this . triggerCodeLensRefresh ( ) ;
2929 }
3030 } )
3131 ) ;
3232 }
33-
33+
3434 /**
3535 * Provides CodeLens for the given document
3636 */
@@ -53,58 +53,69 @@ export class AshCodeLensProvider implements vscode.CodeLensProvider {
5353
5454 // Convert our CodeLensEntry objects to VS Code CodeLens objects
5555 const codeLenses : vscode . CodeLens [ ] = [ ] ;
56-
56+
5757 for ( const entry of parseResult . codeLenses ) {
5858 // Create a range for the CodeLens
5959 const line = Math . max ( 0 , entry . line - 1 ) ; // Convert to 0-based line number
6060 const range = new vscode . Range (
61- new vscode . Position ( line , entry . character ) ,
61+ new vscode . Position ( line , entry . character ) ,
6262 new vscode . Position ( line , entry . character + 1 )
6363 ) ;
64-
64+
6565 // Create the CodeLens with a command that opens the documentation URL
6666 const lens = new vscode . CodeLens ( range ) ;
67-
67+
6868 // Debug logging
69- Logger . getInstance ( ) . debug ( "AshCodeLensProvider" , `Creating code lens: ${ entry . title } -> ${ entry . target } ` ) ;
70-
69+ Logger . getInstance ( ) . debug (
70+ "AshCodeLensProvider" ,
71+ `Creating code lens: ${ entry . title } -> ${ entry . target } `
72+ ) ;
73+
7174 try {
7275 const uri = vscode . Uri . parse ( entry . target ) ;
73- Logger . getInstance ( ) . debug ( "AshCodeLensProvider" , `Parsed URI: ${ uri . toString ( ) } ` ) ;
74-
76+ Logger . getInstance ( ) . debug (
77+ "AshCodeLensProvider" ,
78+ `Parsed URI: ${ uri . toString ( ) } `
79+ ) ;
80+
7581 // Use our custom command for better control and logging
7682 lens . command = {
7783 title : entry . title ,
7884 command : "ash-studio.openDocumentation" ,
7985 arguments : [ entry . target ] ,
80- tooltip : `View documentation for ${ entry . source } `
86+ tooltip : `View documentation for ${ entry . source } ` ,
8187 } ;
82-
88+
8389 // Alternative: use the built-in vscode.open command if needed
8490 // lens.command = {
8591 // title: entry.title,
8692 // command: "vscode.open",
8793 // arguments: [uri],
8894 // tooltip: `View documentation for ${entry.source}`
8995 // };
90-
91-
9296 } catch ( error ) {
93- Logger . getInstance ( ) . error ( "AshCodeLensProvider" , `Failed to parse URI: ${ entry . target } ` , error ) ;
97+ Logger . getInstance ( ) . error (
98+ "AshCodeLensProvider" ,
99+ `Failed to parse URI: ${ entry . target } ` ,
100+ error
101+ ) ;
94102 // Fallback: create a command that shows an error message
95103 lens . command = {
96104 title : entry . title ,
97105 command : "vscode.window.showErrorMessage" ,
98- arguments : [ `Failed to open documentation: ${ entry . target } ` ]
106+ arguments : [ `Failed to open documentation: ${ entry . target } ` ] ,
99107 } ;
100108 }
101-
109+
102110 codeLenses . push ( lens ) ;
103111 }
104-
112+
105113 return codeLenses ;
106114 } catch ( error ) {
107- Logger . getInstance ( ) . error ( "AshCodeLensProvider" , `Error providing code lenses: ${ error } ` ) ;
115+ Logger . getInstance ( ) . error (
116+ "AshCodeLensProvider" ,
117+ `Error providing code lenses: ${ error } `
118+ ) ;
108119 return null ;
109120 }
110121 }
@@ -121,7 +132,7 @@ export class AshCodeLensProvider implements vscode.CodeLensProvider {
121132 * Dispose of resources
122133 */
123134 dispose ( ) : void {
124- this . disposables . forEach ( ( d ) => d . dispose ( ) ) ;
135+ this . disposables . forEach ( d => d . dispose ( ) ) ;
125136 this . disposables = [ ] ;
126137 }
127138}
@@ -134,7 +145,7 @@ export function registerAshCodeLensProvider(
134145 parserService : AshParserService
135146) : vscode . Disposable {
136147 const provider = new AshCodeLensProvider ( parserService ) ;
137-
148+
138149 // Register a test command to verify command execution works
139150 const testCommand = vscode . commands . registerCommand (
140151 "ash-studio.testCodeLens" ,
@@ -143,58 +154,82 @@ export function registerAshCodeLensProvider(
143154 vscode . window . showInformationMessage ( `Code lens clicked! URL: ${ url } ` ) ;
144155 }
145156 ) ;
146-
157+
147158 // Add the test command to context subscriptions
148159 context . subscriptions . push ( testCommand ) ;
149-
160+
150161 // Register a custom command for opening documentation URLs
151162 const openDocsCommand = vscode . commands . registerCommand (
152163 "ash-studio.openDocumentation" ,
153164 async ( url : string ) => {
154- console . log ( `[CodeLens Command] ash-studio.openDocumentation called with URL: ${ url } ` ) ;
155- Logger . getInstance ( ) . info ( "AshCodeLensProvider" , `Command called: opening documentation URL: ${ url } ` ) ;
156-
165+ console . log (
166+ `[CodeLens Command] ash-studio.openDocumentation called with URL: ${ url } `
167+ ) ;
168+ Logger . getInstance ( ) . info (
169+ "AshCodeLensProvider" ,
170+ `Command called: opening documentation URL: ${ url } `
171+ ) ;
172+
157173 try {
158174 console . log ( `[CodeLens Command] Attempting to open URL: ${ url } ` ) ;
159175 const uri = vscode . Uri . parse ( url ) ;
160176 console . log ( `[CodeLens Command] Parsed URI:` , uri . toString ( ) ) ;
161-
177+
162178 // Try multiple methods to handle different environments (like Windsurf)
163179 try {
164180 // Method 1: Use the VS Code built-in API (primary method)
165181 await vscode . env . openExternal ( uri ) ;
166- console . log ( `[CodeLens Command] Successfully opened URL with openExternal: ${ url } ` ) ;
182+ console . log (
183+ `[CodeLens Command] Successfully opened URL with openExternal: ${ url } `
184+ ) ;
167185 } catch ( primaryError ) {
168- console . warn ( `[CodeLens Command] openExternal failed, trying alternative: ${ primaryError } ` ) ;
169-
186+ console . warn (
187+ `[CodeLens Command] openExternal failed, trying alternative: ${ primaryError } `
188+ ) ;
189+
170190 // Method 2: Try to use the built-in open command as fallback
171- await vscode . commands . executeCommand ( 'vscode.open' , uri ) ;
172- console . log ( `[CodeLens Command] Successfully opened URL with vscode.open command: ${ url } ` ) ;
191+ await vscode . commands . executeCommand ( "vscode.open" , uri ) ;
192+ console . log (
193+ `[CodeLens Command] Successfully opened URL with vscode.open command: ${ url } `
194+ ) ;
173195 }
174-
196+
175197 // Show a user notification that we attempted to open the URL
176198 // This is useful in Windsurf where the browser might not open visibly
177199 vscode . window . showInformationMessage (
178200 `Documentation URL: ${ url } (URL should open in your default browser)`
179201 ) ;
180-
181- Logger . getInstance ( ) . info ( "AshCodeLensProvider" , `Successfully processed URL open request: ${ url } ` ) ;
202+
203+ Logger . getInstance ( ) . info (
204+ "AshCodeLensProvider" ,
205+ `Successfully processed URL open request: ${ url } `
206+ ) ;
182207 } catch ( error ) {
183208 console . error ( `[CodeLens Command] Failed to open URL: ${ url } ` , error ) ;
184- Logger . getInstance ( ) . error ( "AshCodeLensProvider" , `Failed to open URL: ${ url } ` , error ) ;
185- vscode . window . showErrorMessage ( `Failed to open documentation: ${ url } . Error: ${ error instanceof Error ? error . message : String ( error ) } ` ) ;
209+ Logger . getInstance ( ) . error (
210+ "AshCodeLensProvider" ,
211+ `Failed to open URL: ${ url } ` ,
212+ error
213+ ) ;
214+ vscode . window . showErrorMessage (
215+ `Failed to open documentation: ${ url } . Error: ${ error instanceof Error ? error . message : String ( error ) } `
216+ ) ;
186217 }
187218 }
188219 ) ;
189-
220+
190221 // Register the provider for Elixir files
191222 const providerDisposable = vscode . languages . registerCodeLensProvider (
192223 { language : "elixir" , scheme : "file" } ,
193224 provider
194225 ) ;
195-
226+
196227 context . subscriptions . push ( openDocsCommand ) ;
197228 context . subscriptions . push ( providerDisposable ) ;
198-
199- return vscode . Disposable . from ( testCommand , openDocsCommand , providerDisposable ) ;
229+
230+ return vscode . Disposable . from (
231+ testCommand ,
232+ openDocsCommand ,
233+ providerDisposable
234+ ) ;
200235}
0 commit comments