@@ -135,6 +135,56 @@ export default class BashServer {
135
135
)
136
136
}
137
137
138
+ private getDocumentationForSymbol ( {
139
+ currentUri,
140
+ symbol,
141
+ } : {
142
+ symbol : LSP . SymbolInformation
143
+ currentUri : string
144
+ } ) : string {
145
+ const getCommentsAbove = ( uri : string , line : number ) : string => {
146
+ const comment = this . analyzer . commentsAbove ( uri , line )
147
+ return comment ? `\n\n${ comment } ` : ''
148
+ }
149
+
150
+ return symbol . location . uri !== currentUri
151
+ ? `${ symbolKindToDescription ( symbol . kind ) } defined in ${ path . relative (
152
+ currentUri ,
153
+ symbol . location . uri ,
154
+ ) } ${ getCommentsAbove ( symbol . location . uri , symbol . location . range . start . line ) } `
155
+ : `${ symbolKindToDescription ( symbol . kind ) } defined on line ${ symbol . location . range
156
+ . start . line + 1 } ${ getCommentsAbove (
157
+ currentUri ,
158
+ symbol . location . range . start . line ,
159
+ ) } `
160
+ }
161
+
162
+ private getCompletionItemsForSymbols ( {
163
+ symbols,
164
+ currentUri,
165
+ } : {
166
+ symbols : LSP . SymbolInformation [ ]
167
+ currentUri : string
168
+ } ) : BashCompletionItem [ ] {
169
+ return deduplicateSymbols ( { symbols, currentUri } ) . map (
170
+ ( symbol : LSP . SymbolInformation ) => ( {
171
+ label : symbol . name ,
172
+ kind : symbolKindToCompletionKind ( symbol . kind ) ,
173
+ data : {
174
+ name : symbol . name ,
175
+ type : CompletionItemDataType . Symbol ,
176
+ } ,
177
+ documentation :
178
+ symbol . location . uri !== currentUri
179
+ ? this . getDocumentationForSymbol ( {
180
+ currentUri,
181
+ symbol,
182
+ } )
183
+ : undefined ,
184
+ } ) ,
185
+ )
186
+ }
187
+
138
188
private async onHover (
139
189
params : LSP . TextDocumentPositionParams ,
140
190
) : Promise < LSP . Hover | null > {
@@ -180,11 +230,6 @@ export default class BashServer {
180
230
return { contents : getMarkdownContent ( shellDocumentation ) }
181
231
}
182
232
} else {
183
- const getCommentsAbove = ( uri : string , line : number ) : string => {
184
- const comment = this . analyzer . commentsAbove ( uri , line )
185
- return comment ? `\n\n${ comment } ` : ''
186
- }
187
-
188
233
const symbolDocumentation = deduplicateSymbols ( {
189
234
symbols : this . analyzer . findSymbolsMatchingWord ( {
190
235
exactMatch : true ,
@@ -195,19 +240,7 @@ export default class BashServer {
195
240
// do not return hover referencing for the current line
196
241
. filter ( symbol => symbol . location . range . start . line !== params . position . line )
197
242
. map ( ( symbol : LSP . SymbolInformation ) =>
198
- symbol . location . uri !== currentUri
199
- ? `${ symbolKindToDescription ( symbol . kind ) } defined in ${ path . relative (
200
- currentUri ,
201
- symbol . location . uri ,
202
- ) } ${ getCommentsAbove (
203
- symbol . location . uri ,
204
- symbol . location . range . start . line ,
205
- ) } `
206
- : `${ symbolKindToDescription ( symbol . kind ) } defined on line ${ symbol . location
207
- . range . start . line + 1 } ${ getCommentsAbove (
208
- params . textDocument . uri ,
209
- symbol . location . range . start . line ,
210
- ) } `,
243
+ this . getDocumentationForSymbol ( { currentUri, symbol } ) ,
211
244
)
212
245
213
246
if ( symbolDocumentation . length === 1 ) {
@@ -268,7 +301,7 @@ export default class BashServer {
268
301
const symbolCompletions =
269
302
word === null
270
303
? [ ]
271
- : getCompletionItemsForSymbols ( {
304
+ : this . getCompletionItemsForSymbols ( {
272
305
symbols : this . analyzer . findSymbolsMatchingWord ( {
273
306
exactMatch : false ,
274
307
word,
@@ -391,32 +424,6 @@ function deduplicateSymbols({
391
424
return uniqueBasedOnHash ( [ ...symbolsCurrentFile , ...symbolsOtherFiles ] , getSymbolId )
392
425
}
393
426
394
- function getCompletionItemsForSymbols ( {
395
- symbols,
396
- currentUri,
397
- } : {
398
- symbols : LSP . SymbolInformation [ ]
399
- currentUri : string
400
- } ) : BashCompletionItem [ ] {
401
- return deduplicateSymbols ( { symbols, currentUri } ) . map (
402
- ( symbol : LSP . SymbolInformation ) => ( {
403
- label : symbol . name ,
404
- kind : symbolKindToCompletionKind ( symbol . kind ) ,
405
- data : {
406
- name : symbol . name ,
407
- type : CompletionItemDataType . Symbol ,
408
- } ,
409
- documentation :
410
- symbol . location . uri !== currentUri
411
- ? `${ symbolKindToDescription ( symbol . kind ) } defined in ${ path . relative (
412
- currentUri ,
413
- symbol . location . uri ,
414
- ) } `
415
- : undefined ,
416
- } ) ,
417
- )
418
- }
419
-
420
427
function symbolKindToCompletionKind ( s : LSP . SymbolKind ) : LSP . CompletionItemKind {
421
428
switch ( s ) {
422
429
case LSP . SymbolKind . File :
0 commit comments