1
1
import * as vscode from "vscode" ;
2
2
import {
3
- ExecuteCommandParams ,
3
+ type ExecuteCommandParams ,
4
4
ExecuteCommandRequest ,
5
- LanguageClient ,
5
+ type LanguageClient ,
6
6
} from "vscode-languageclient/node" ;
7
7
8
8
interface IParameters {
9
9
modules : string [ ] ;
10
10
}
11
11
12
- export class DocsAggregatorTool implements vscode . LanguageModelTool < IParameters > {
12
+ export class DocsAggregatorTool
13
+ implements vscode . LanguageModelTool < IParameters >
14
+ {
13
15
constructor ( private client : LanguageClient ) { }
14
16
15
17
async prepareInvocation (
16
18
options : vscode . LanguageModelToolInvocationPrepareOptions < IParameters > ,
17
- _token : vscode . CancellationToken
19
+ _token : vscode . CancellationToken ,
18
20
) : Promise < vscode . PreparedToolInvocation > {
19
21
return {
20
22
invocationMessage : `Getting documentation for: ${ options . input . modules . join ( ", " ) } ` ,
@@ -23,21 +25,21 @@ export class DocsAggregatorTool implements vscode.LanguageModelTool<IParameters>
23
25
24
26
async invoke (
25
27
options : vscode . LanguageModelToolInvocationOptions < IParameters > ,
26
- token : vscode . CancellationToken
28
+ token : vscode . CancellationToken ,
27
29
) : Promise < vscode . LanguageModelToolResult > {
28
30
const { modules } = options . input ;
29
31
30
32
try {
31
33
// 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:" ) ,
35
37
) ;
36
38
37
39
if ( ! command ) {
38
40
return new vscode . LanguageModelToolResult ( [
39
41
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" ,
41
43
) ,
42
44
] ) ;
43
45
}
@@ -58,158 +60,166 @@ export class DocsAggregatorTool implements vscode.LanguageModelTool<IParameters>
58
60
callbacks ?: string [ ] ;
59
61
macrocallbacks ?: string [ ] ;
60
62
behaviours ?: string [ ] ;
61
-
63
+
62
64
// Function/callback/type documentation fields
63
65
function ?: string ;
64
66
callback ?: string ;
65
67
type ?: string ;
66
68
arity ?: number ;
67
69
documentation ?: string ;
68
-
70
+
69
71
// Attribute documentation fields
70
72
attribute ?: string ;
71
-
73
+
72
74
// Error field
73
75
error ?: string ;
74
76
} > ;
75
77
error ?: string ;
76
- } > (
77
- ExecuteCommandRequest . method ,
78
- params ,
79
- token
80
- ) ;
78
+ } > ( ExecuteCommandRequest . method , params , token ) ;
81
79
82
80
if ( result ?. error ) {
83
81
return new vscode . LanguageModelToolResult ( [
84
82
new vscode . LanguageModelTextPart (
85
- `Error getting documentation: ${ result . error } `
83
+ `Error getting documentation: ${ result . error } ` ,
86
84
) ,
87
85
] ) ;
88
86
}
89
87
90
88
if ( result ?. results ) {
91
89
const parts : vscode . LanguageModelTextPart [ ] = [ ] ;
92
-
90
+
93
91
for ( const item of result . results ) {
94
92
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" ;
96
100
parts . push (
97
101
new vscode . LanguageModelTextPart (
98
- `## ${ name } \nError: ${ item . error } \n\n`
99
- )
102
+ `## ${ name } \nError: ${ item . error } \n\n` ,
103
+ ) ,
100
104
) ;
101
105
} else if ( item . module && item . moduledoc !== undefined ) {
102
106
// Module documentation
103
107
parts . push (
104
- new vscode . LanguageModelTextPart (
105
- `# Module: ${ item . module } \n\n`
106
- )
108
+ new vscode . LanguageModelTextPart ( `# Module: ${ item . module } \n\n` ) ,
107
109
) ;
108
-
110
+
109
111
if ( item . moduledoc ) {
110
112
parts . push (
111
- new vscode . LanguageModelTextPart (
112
- `${ item . moduledoc } \n\n`
113
- )
113
+ new vscode . LanguageModelTextPart ( `${ item . moduledoc } \n\n` ) ,
114
114
) ;
115
115
}
116
-
116
+
117
117
if ( item . functions && item . functions . length > 0 ) {
118
118
parts . push (
119
119
new vscode . LanguageModelTextPart (
120
- `## Functions\n${ item . functions . join ( ", " ) } \n\n`
121
- )
120
+ `## Functions\n${ item . functions . join ( ", " ) } \n\n` ,
121
+ ) ,
122
122
) ;
123
123
}
124
-
124
+
125
125
if ( item . macros && item . macros . length > 0 ) {
126
126
parts . push (
127
127
new vscode . LanguageModelTextPart (
128
- `## Macros\n${ item . macros . join ( ", " ) } \n\n`
129
- )
128
+ `## Macros\n${ item . macros . join ( ", " ) } \n\n` ,
129
+ ) ,
130
130
) ;
131
131
}
132
-
132
+
133
133
if ( item . types && item . types . length > 0 ) {
134
134
parts . push (
135
135
new vscode . LanguageModelTextPart (
136
- `## Types\n${ item . types . join ( ", " ) } \n\n`
137
- )
136
+ `## Types\n${ item . types . join ( ", " ) } \n\n` ,
137
+ ) ,
138
138
) ;
139
139
}
140
-
140
+
141
141
if ( item . callbacks && item . callbacks . length > 0 ) {
142
142
parts . push (
143
143
new vscode . LanguageModelTextPart (
144
- `## Callbacks\n${ item . callbacks . join ( ", " ) } \n\n`
145
- )
144
+ `## Callbacks\n${ item . callbacks . join ( ", " ) } \n\n` ,
145
+ ) ,
146
146
) ;
147
147
}
148
-
148
+
149
149
if ( item . macrocallbacks && item . macrocallbacks . length > 0 ) {
150
150
parts . push (
151
151
new vscode . LanguageModelTextPart (
152
- `## Macro Callbacks\n${ item . macrocallbacks . join ( ", " ) } \n\n`
153
- )
152
+ `## Macro Callbacks\n${ item . macrocallbacks . join ( ", " ) } \n\n` ,
153
+ ) ,
154
154
) ;
155
155
}
156
-
156
+
157
157
if ( item . behaviours && item . behaviours . length > 0 ) {
158
158
parts . push (
159
159
new vscode . LanguageModelTextPart (
160
- `## Behaviours\n${ item . behaviours . join ( ", " ) } \n\n`
161
- )
160
+ `## Behaviours\n${ item . behaviours . join ( ", " ) } \n\n` ,
161
+ ) ,
162
162
) ;
163
163
}
164
164
} else if ( item . function ) {
165
165
// 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 ;
167
170
parts . push (
168
171
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
+ ) ,
171
174
) ;
172
175
} else if ( item . callback ) {
173
176
// 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 ;
175
181
parts . push (
176
182
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
+ ) ,
179
185
) ;
180
186
} else if ( item . type ) {
181
187
// 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 ;
183
192
parts . push (
184
193
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
+ ) ,
187
196
) ;
188
197
} else if ( item . attribute ) {
189
198
// Attribute documentation
190
199
parts . push (
191
200
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
+ ) ,
194
203
) ;
195
204
}
196
205
}
197
-
206
+
198
207
return new vscode . LanguageModelToolResult ( parts ) ;
199
208
}
200
209
201
210
return new vscode . LanguageModelToolResult ( [
202
211
new vscode . LanguageModelTextPart (
203
- `No documentation found for: ${ modules . join ( ", " ) } `
212
+ `No documentation found for: ${ modules . join ( ", " ) } ` ,
204
213
) ,
205
214
] ) ;
206
215
} catch ( error ) {
207
- const errorMessage = error instanceof Error ? error . message : String ( error ) ;
216
+ const errorMessage =
217
+ error instanceof Error ? error . message : String ( error ) ;
208
218
return new vscode . LanguageModelToolResult ( [
209
219
new vscode . LanguageModelTextPart (
210
- `Failed to get documentation: ${ errorMessage } `
220
+ `Failed to get documentation: ${ errorMessage } ` ,
211
221
) ,
212
222
] ) ;
213
223
}
214
224
}
215
- }
225
+ }
0 commit comments