11import * as vscode from "vscode" ;
22import {
3- ExecuteCommandParams ,
3+ type ExecuteCommandParams ,
44 ExecuteCommandRequest ,
5- LanguageClient ,
5+ type LanguageClient ,
66} from "vscode-languageclient/node" ;
77
88interface IParameters {
99 modules : string [ ] ;
1010}
1111
12- export class DocsAggregatorTool implements vscode . LanguageModelTool < IParameters > {
12+ export class DocsAggregatorTool
13+ implements vscode . LanguageModelTool < IParameters >
14+ {
1315 constructor ( private client : LanguageClient ) { }
1416
1517 async prepareInvocation (
1618 options : vscode . LanguageModelToolInvocationPrepareOptions < IParameters > ,
17- _token : vscode . CancellationToken
19+ _token : vscode . CancellationToken ,
1820 ) : Promise < vscode . PreparedToolInvocation > {
1921 return {
2022 invocationMessage : `Getting documentation for: ${ options . input . modules . join ( ", " ) } ` ,
@@ -23,21 +25,21 @@ export class DocsAggregatorTool implements vscode.LanguageModelTool<IParameters>
2325
2426 async invoke (
2527 options : vscode . LanguageModelToolInvocationOptions < IParameters > ,
26- token : vscode . CancellationToken
28+ token : vscode . CancellationToken ,
2729 ) : Promise < vscode . LanguageModelToolResult > {
2830 const { modules } = options . input ;
2931
3032 try {
3133 // Find the llmDocsAggregator command from server capabilities
32- const command = this . client . initializeResult ?. capabilities
33- . executeCommandProvider ?. commands . find ( ( c ) =>
34- c . startsWith ( "llmDocsAggregator:" )
34+ const command =
35+ this . client . initializeResult ?. capabilities . executeCommandProvider ?. commands . find (
36+ ( c ) => c . startsWith ( "llmDocsAggregator:" ) ,
3537 ) ;
3638
3739 if ( ! command ) {
3840 return new vscode . LanguageModelToolResult ( [
3941 new vscode . LanguageModelTextPart (
40- "ElixirLS language server is not ready or does not support the llmDocsAggregator command"
42+ "ElixirLS language server is not ready or does not support the llmDocsAggregator command" ,
4143 ) ,
4244 ] ) ;
4345 }
@@ -58,158 +60,166 @@ export class DocsAggregatorTool implements vscode.LanguageModelTool<IParameters>
5860 callbacks ?: string [ ] ;
5961 macrocallbacks ?: string [ ] ;
6062 behaviours ?: string [ ] ;
61-
63+
6264 // Function/callback/type documentation fields
6365 function ?: string ;
6466 callback ?: string ;
6567 type ?: string ;
6668 arity ?: number ;
6769 documentation ?: string ;
68-
70+
6971 // Attribute documentation fields
7072 attribute ?: string ;
71-
73+
7274 // Error field
7375 error ?: string ;
7476 } > ;
7577 error ?: string ;
76- } > (
77- ExecuteCommandRequest . method ,
78- params ,
79- token
80- ) ;
78+ } > ( ExecuteCommandRequest . method , params , token ) ;
8179
8280 if ( result ?. error ) {
8381 return new vscode . LanguageModelToolResult ( [
8482 new vscode . LanguageModelTextPart (
85- `Error getting documentation: ${ result . error } `
83+ `Error getting documentation: ${ result . error } ` ,
8684 ) ,
8785 ] ) ;
8886 }
8987
9088 if ( result ?. results ) {
9189 const parts : vscode . LanguageModelTextPart [ ] = [ ] ;
92-
90+
9391 for ( const item of result . results ) {
9492 if ( item . error ) {
95- const name = item . module || item . function || item . callback || item . type || item . attribute || "Unknown" ;
93+ const name =
94+ item . module ||
95+ item . function ||
96+ item . callback ||
97+ item . type ||
98+ item . attribute ||
99+ "Unknown" ;
96100 parts . push (
97101 new vscode . LanguageModelTextPart (
98- `## ${ name } \nError: ${ item . error } \n\n`
99- )
102+ `## ${ name } \nError: ${ item . error } \n\n` ,
103+ ) ,
100104 ) ;
101105 } else if ( item . module && item . moduledoc !== undefined ) {
102106 // Module documentation
103107 parts . push (
104- new vscode . LanguageModelTextPart (
105- `# Module: ${ item . module } \n\n`
106- )
108+ new vscode . LanguageModelTextPart ( `# Module: ${ item . module } \n\n` ) ,
107109 ) ;
108-
110+
109111 if ( item . moduledoc ) {
110112 parts . push (
111- new vscode . LanguageModelTextPart (
112- `${ item . moduledoc } \n\n`
113- )
113+ new vscode . LanguageModelTextPart ( `${ item . moduledoc } \n\n` ) ,
114114 ) ;
115115 }
116-
116+
117117 if ( item . functions && item . functions . length > 0 ) {
118118 parts . push (
119119 new vscode . LanguageModelTextPart (
120- `## Functions\n${ item . functions . join ( ", " ) } \n\n`
121- )
120+ `## Functions\n${ item . functions . join ( ", " ) } \n\n` ,
121+ ) ,
122122 ) ;
123123 }
124-
124+
125125 if ( item . macros && item . macros . length > 0 ) {
126126 parts . push (
127127 new vscode . LanguageModelTextPart (
128- `## Macros\n${ item . macros . join ( ", " ) } \n\n`
129- )
128+ `## Macros\n${ item . macros . join ( ", " ) } \n\n` ,
129+ ) ,
130130 ) ;
131131 }
132-
132+
133133 if ( item . types && item . types . length > 0 ) {
134134 parts . push (
135135 new vscode . LanguageModelTextPart (
136- `## Types\n${ item . types . join ( ", " ) } \n\n`
137- )
136+ `## Types\n${ item . types . join ( ", " ) } \n\n` ,
137+ ) ,
138138 ) ;
139139 }
140-
140+
141141 if ( item . callbacks && item . callbacks . length > 0 ) {
142142 parts . push (
143143 new vscode . LanguageModelTextPart (
144- `## Callbacks\n${ item . callbacks . join ( ", " ) } \n\n`
145- )
144+ `## Callbacks\n${ item . callbacks . join ( ", " ) } \n\n` ,
145+ ) ,
146146 ) ;
147147 }
148-
148+
149149 if ( item . macrocallbacks && item . macrocallbacks . length > 0 ) {
150150 parts . push (
151151 new vscode . LanguageModelTextPart (
152- `## Macro Callbacks\n${ item . macrocallbacks . join ( ", " ) } \n\n`
153- )
152+ `## Macro Callbacks\n${ item . macrocallbacks . join ( ", " ) } \n\n` ,
153+ ) ,
154154 ) ;
155155 }
156-
156+
157157 if ( item . behaviours && item . behaviours . length > 0 ) {
158158 parts . push (
159159 new vscode . LanguageModelTextPart (
160- `## Behaviours\n${ item . behaviours . join ( ", " ) } \n\n`
161- )
160+ `## Behaviours\n${ item . behaviours . join ( ", " ) } \n\n` ,
161+ ) ,
162162 ) ;
163163 }
164164 } else if ( item . function ) {
165165 // Function documentation
166- const title = item . arity !== undefined ? `${ item . function } /${ item . arity } ` : item . function ;
166+ const title =
167+ item . arity !== undefined
168+ ? `${ item . function } /${ item . arity } `
169+ : item . function ;
167170 parts . push (
168171 new vscode . LanguageModelTextPart (
169- `# Function: ${ item . module } .${ title } \n\n${ item . documentation || "No documentation available" } \n\n`
170- )
172+ `# Function: ${ item . module } .${ title } \n\n${ item . documentation || "No documentation available" } \n\n` ,
173+ ) ,
171174 ) ;
172175 } else if ( item . callback ) {
173176 // Callback documentation
174- const title = item . arity !== undefined ? `${ item . callback } /${ item . arity } ` : item . callback ;
177+ const title =
178+ item . arity !== undefined
179+ ? `${ item . callback } /${ item . arity } `
180+ : item . callback ;
175181 parts . push (
176182 new vscode . LanguageModelTextPart (
177- `# Callback: ${ item . module } .${ title } \n\n${ item . documentation || "No documentation available" } \n\n`
178- )
183+ `# Callback: ${ item . module } .${ title } \n\n${ item . documentation || "No documentation available" } \n\n` ,
184+ ) ,
179185 ) ;
180186 } else if ( item . type ) {
181187 // Type documentation
182- const title = item . arity !== undefined ? `${ item . type } /${ item . arity } ` : item . type ;
188+ const title =
189+ item . arity !== undefined
190+ ? `${ item . type } /${ item . arity } `
191+ : item . type ;
183192 parts . push (
184193 new vscode . LanguageModelTextPart (
185- `# Type: ${ item . module } .${ title } \n\n${ item . documentation || "No documentation available" } \n\n`
186- )
194+ `# Type: ${ item . module } .${ title } \n\n${ item . documentation || "No documentation available" } \n\n` ,
195+ ) ,
187196 ) ;
188197 } else if ( item . attribute ) {
189198 // Attribute documentation
190199 parts . push (
191200 new vscode . LanguageModelTextPart (
192- `# Attribute: ${ item . attribute } \n\n${ item . documentation || "No documentation available" } \n\n`
193- )
201+ `# Attribute: ${ item . attribute } \n\n${ item . documentation || "No documentation available" } \n\n` ,
202+ ) ,
194203 ) ;
195204 }
196205 }
197-
206+
198207 return new vscode . LanguageModelToolResult ( parts ) ;
199208 }
200209
201210 return new vscode . LanguageModelToolResult ( [
202211 new vscode . LanguageModelTextPart (
203- `No documentation found for: ${ modules . join ( ", " ) } `
212+ `No documentation found for: ${ modules . join ( ", " ) } ` ,
204213 ) ,
205214 ] ) ;
206215 } catch ( error ) {
207- const errorMessage = error instanceof Error ? error . message : String ( error ) ;
216+ const errorMessage =
217+ error instanceof Error ? error . message : String ( error ) ;
208218 return new vscode . LanguageModelToolResult ( [
209219 new vscode . LanguageModelTextPart (
210- `Failed to get documentation: ${ errorMessage } `
220+ `Failed to get documentation: ${ errorMessage } ` ,
211221 ) ,
212222 ] ) ;
213223 }
214224 }
215- }
225+ }
0 commit comments