@@ -22,18 +22,17 @@ import * as ac from "atom/autocomplete-plus"
22
22
import { Suggestion , TextSuggestion , SnippetSuggestion } from "../types/autocomplete-extended"
23
23
24
24
/**
25
- * Defines the behavior of suggestion acceptance.
26
- * Assume you have "cons|ole" in the editor (`|` is the cursor position)
25
+ * Defines the behavior of suggestion acceptance. Assume you have "cons|ole" in the editor ( `|` is the cursor position)
27
26
* and the autocomplete suggestion is `const`.
28
- * - if `false` -> the edits are inserted : const|ole
29
- * - if `true`` -> the edits are replaced: const|
27
+ *
28
+ * - If `false` -> the edits are inserted : const|ole
29
+ * - If `true`` -> the edits are replaced: const|
30
30
*/
31
31
type ShouldReplace = boolean
32
32
33
33
/**
34
- * Holds a list of suggestions generated from the CompletionItem[]
35
- * list sent by the server, as well as metadata about the context
36
- * it was collected in
34
+ * Holds a list of suggestions generated from the CompletionItem[] list sent by the server, as well as metadata about
35
+ * the context it was collected in
37
36
*/
38
37
interface SuggestionCacheEntry {
39
38
/** If `true`, the server will send a list of suggestions to replace this one */
@@ -57,10 +56,7 @@ class PossiblyResolvedCompletionItem {
57
56
constructor ( public completionItem : CompletionItem , public isResolved : boolean ) { }
58
57
}
59
58
60
- /**
61
- * Public: Adapts the language server protocol "textDocument/completion" to the Atom
62
- * AutoComplete+ package.
63
- */
59
+ /** Public: Adapts the language server protocol "textDocument/completion" to the Atom AutoComplete+ package. */
64
60
export default class AutocompleteAdapter {
65
61
public static canAdapt ( serverCapabilities : ServerCapabilities ) : boolean {
66
62
return serverCapabilities . completionProvider != null
@@ -76,17 +72,14 @@ export default class AutocompleteAdapter {
76
72
private _cancellationTokens : WeakMap < LanguageClientConnection , CancellationTokenSource > = new WeakMap ( )
77
73
78
74
/**
79
- * Public: Obtain suggestion list for AutoComplete+ by querying the language server using
80
- * the `textDocument/completion` request.
75
+ * Public: Obtain suggestion list for AutoComplete+ by querying the language server using the `textDocument/completion` request.
81
76
*
82
77
* @param server An {ActiveServer} pointing to the language server to query.
83
78
* @param request The {atom$AutocompleteRequest} to satisfy.
84
- * @param onDidConvertCompletionItem An optional function that takes a {CompletionItem},
85
- * an {atom$AutocompleteSuggestion} and a {atom$AutocompleteRequest}
86
- * allowing you to adjust converted items.
79
+ * @param onDidConvertCompletionItem An optional function that takes a {CompletionItem}, an
80
+ * {atom$AutocompleteSuggestion} and a {atom$AutocompleteRequest} allowing you to adjust converted items.
87
81
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
88
- * @returns A {Promise} of an {Array} of {atom$AutocompleteSuggestion}s containing the
89
- * AutoComplete+ suggestions to display.
82
+ * @returns A {Promise} of an {Array} of {atom$AutocompleteSuggestion}s containing the AutoComplete+ suggestions to display.
90
83
*/
91
84
public async getSuggestions (
92
85
server : ActiveServer ,
@@ -211,8 +204,8 @@ export default class AutocompleteAdapter {
211
204
}
212
205
213
206
/**
214
- * Public: Obtain a complete version of a suggestion with additional information
215
- * the language server can provide by way of the `completionItem/resolve` request.
207
+ * Public: Obtain a complete version of a suggestion with additional information the language server can provide by
208
+ * way of the `completionItem/resolve` request.
216
209
*
217
210
* @param server An {ActiveServer} pointing to the language server to query.
218
211
* @param suggestion An {atom$AutocompleteSuggestion} suggestion that should be resolved.
@@ -257,16 +250,15 @@ export default class AutocompleteAdapter {
257
250
}
258
251
259
252
/**
260
- * Public: Get the trigger character that caused the autocomplete (if any). This is required because
261
- * AutoComplete-plus does not have trigger characters. Although the terminology is 'character' we treat
262
- * them as variable length strings as this will almost certainly change in the future to support '->' etc.
253
+ * Public: Get the trigger character that caused the autocomplete (if any). This is required because AutoComplete-plus
254
+ * does not have trigger characters. Although the terminology is 'character' we treat them as variable length strings
255
+ * as this will almost certainly change in the future to support '->' etc.
263
256
*
264
257
* @param request An {Array} of {atom$AutocompleteSuggestion}s to locate the prefix, editor, bufferPosition etc.
265
258
* @param triggerChars The {Array} of {string}s that can be trigger characters.
266
- * @returns A [{string}, boolean] where the string is the matching trigger character or an empty string
267
- * if one was not matched, and the boolean is true if the trigger character is in request.prefix, and false
268
- * if it is in the word before request.prefix. The boolean return value has no meaning if the string return
269
- * value is an empty string.
259
+ * @returns A [{string}, boolean] where the string is the matching trigger character or an empty string if one was not
260
+ * matched, and the boolean is true if the trigger character is in request.prefix, and false if it is in the word
261
+ * before request.prefix. The boolean return value has no meaning if the string return value is an empty string.
270
262
*/
271
263
public static getTriggerCharacter ( request : ac . SuggestionsRequestedEvent , triggerChars : string [ ] ) : [ string , boolean ] {
272
264
// AutoComplete-Plus considers text after a symbol to be a new trigger. So we should look backward
@@ -294,8 +286,8 @@ export default class AutocompleteAdapter {
294
286
}
295
287
296
288
/**
297
- * Public: Create TextDocumentPositionParams to be sent to the language server
298
- * based on the editor and position from the AutoCompleteRequest.
289
+ * Public: Create TextDocumentPositionParams to be sent to the language server based on the editor and position from
290
+ * the AutoCompleteRequest.
299
291
*
300
292
* @param request The {atom$AutocompleteRequest} to obtain the editor from.
301
293
* @param triggerPoint The {atom$Point} where the trigger started.
@@ -306,16 +298,17 @@ export default class AutocompleteAdapter {
306
298
}
307
299
308
300
/**
309
- * Public: Create {CompletionParams} to be sent to the language server
310
- * based on the editor and position from the Autocomplete request etc.
301
+ * Public: Create {CompletionParams} to be sent to the language server based on the editor and position from the
302
+ * Autocomplete request etc.
311
303
*
312
304
* @param request The {atom$AutocompleteRequest} containing the request details.
313
305
* @param triggerCharacter The {string} containing the trigger character (empty if none).
314
306
* @param triggerOnly A {boolean} representing whether this completion is triggered right after a trigger character.
315
307
* @returns A {CompletionParams} with the keys:
316
- * * `textDocument` the language server protocol textDocument identification.
317
- * * `position` the position within the text document to display completion request for.
318
- * * `context` containing the trigger character and kind.
308
+ *
309
+ * - `textDocument` the language server protocol textDocument identification.
310
+ * - `position` the position within the text document to display completion request for.
311
+ * - `context` containing the trigger character and kind.
319
312
*/
320
313
public static createCompletionParams (
321
314
request : ac . SuggestionsRequestedEvent ,
@@ -330,13 +323,11 @@ export default class AutocompleteAdapter {
330
323
}
331
324
332
325
/**
333
- * Public: Create {CompletionContext} to be sent to the language server
334
- * based on the trigger character.
326
+ * Public: Create {CompletionContext} to be sent to the language server based on the trigger character.
335
327
*
336
328
* @param triggerCharacter The {string} containing the trigger character or '' if none.
337
329
* @param triggerOnly A {boolean} representing whether this completion is triggered right after a trigger character.
338
- * @returns An {CompletionContext} that specifies the triggerKind and the triggerCharacter
339
- * if there is one.
330
+ * @returns An {CompletionContext} that specifies the triggerKind and the triggerCharacter if there is one.
340
331
*/
341
332
public static createCompletionContext ( triggerCharacter : string , triggerOnly : boolean ) : CompletionContext {
342
333
if ( triggerCharacter === "" ) {
@@ -349,15 +340,15 @@ export default class AutocompleteAdapter {
349
340
}
350
341
351
342
/**
352
- * Public: Convert a language server protocol CompletionItem array or CompletionList to
353
- * an array of ordered AutoComplete+ suggestions.
343
+ * Public: Convert a language server protocol CompletionItem array or CompletionList to an array of ordered
344
+ * AutoComplete+ suggestions.
354
345
*
355
- * @param completionItems An {Array} of {CompletionItem} objects or a {CompletionList} containing completion
356
- * items to be converted.
346
+ * @param completionItems An {Array} of {CompletionItem} objects or a {CompletionList} containing completion items to
347
+ * be converted.
357
348
* @param request The {atom$AutocompleteRequest} to satisfy.
358
349
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
359
- * @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion}
360
- * and a {atom$AutocompleteRequest} allowing you to adjust converted items.
350
+ * @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion} and a
351
+ * {atom$AutocompleteRequest} allowing you to adjust converted items.
361
352
* @returns A {Map} of AutoComplete+ suggestions ordered by the CompletionItems sortText.
362
353
*/
363
354
public completionItemsToSuggestions (
@@ -394,8 +385,8 @@ export default class AutocompleteAdapter {
394
385
* @param suggestion A {atom$AutocompleteSuggestion} to have the conversion applied to.
395
386
* @param request The {atom$AutocompleteRequest} to satisfy.
396
387
* @param shouldReplace The behavior of suggestion acceptance (see {ShouldReplace}).
397
- * @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion}
398
- * and a {atom$AutocompleteRequest} allowing you to adjust converted items.
388
+ * @param onDidConvertCompletionItem A function that takes a {CompletionItem}, an {atom$AutocompleteSuggestion} and a
389
+ * {atom$AutocompleteRequest} allowing you to adjust converted items.
399
390
* @returns The {atom$AutocompleteSuggestion} passed in as suggestion with the conversion applied.
400
391
*/
401
392
public static completionItemToSuggestion (
@@ -458,8 +449,8 @@ export default class AutocompleteAdapter {
458
449
}
459
450
460
451
/**
461
- * Public: Applies the textEdit part of a language server protocol CompletionItem to an
462
- * AutoComplete+ Suggestion via the replacementPrefix and text properties.
452
+ * Public: Applies the textEdit part of a language server protocol CompletionItem to an AutoComplete+ Suggestion via
453
+ * the replacementPrefix and text properties.
463
454
*
464
455
* @param textEdit A {TextEdit} from a CompletionItem to apply.
465
456
* @param editor An Atom {TextEditor} used to obtain the necessary text replacement.
@@ -494,8 +485,7 @@ export default class AutocompleteAdapter {
494
485
}
495
486
496
487
/**
497
- * Public: Adds a snippet to the suggestion if the CompletionItem contains
498
- * snippet-formatted text
488
+ * Public: Adds a snippet to the suggestion if the CompletionItem contains snippet-formatted text
499
489
*
500
490
* @param item An {CompletionItem} containing the completion items to be merged into.
501
491
* @param suggestion The {atom$AutocompleteSuggestion} to merge the conversion into.
@@ -507,12 +497,11 @@ export default class AutocompleteAdapter {
507
497
}
508
498
509
499
/**
510
- * Public: Obtain the textual suggestion type required by AutoComplete+ that
511
- * most closely maps to the numeric completion kind supplies by the language server.
500
+ * Public: Obtain the textual suggestion type required by AutoComplete+ that most closely maps to the numeric
501
+ * completion kind supplies by the language server.
512
502
*
513
503
* @param kind A {Number} that represents the suggestion kind to be converted.
514
- * @returns A {String} containing the AutoComplete+ suggestion type equivalent
515
- * to the given completion kind.
504
+ * @returns A {String} containing the AutoComplete+ suggestion type equivalent to the given completion kind.
516
505
*/
517
506
public static completionKindToSuggestionType ( kind : number | undefined ) : string {
518
507
switch ( kind ) {
@@ -560,10 +549,11 @@ export default class AutocompleteAdapter {
560
549
}
561
550
562
551
/**
563
- * Normalizes the given grammar scope for autoComplete package so it always starts with `.`
564
- * Based on https://github.com/atom/autocomplete-plus/wiki/Autocomplete-Providers
565
- * @param grammarScope such as 'source.python' or '.source.python'
566
- * @returns the normalized grammarScope such as `.source.python`
552
+ * Normalizes the given grammar scope for autoComplete package so it always starts with `.` Based on
553
+ * https://github.com/atom/autocomplete-plus/wiki/Autocomplete-Providers
554
+ *
555
+ * @param grammarScope Such as 'source.python' or '.source.python'
556
+ * @returns The normalized grammarScope such as `.source.python`
567
557
*/
568
558
export function grammarScopeToAutoCompleteSelector ( grammarScope : string ) : string {
569
559
return grammarScope . includes ( "." ) && grammarScope [ 0 ] !== "." ? `.${ grammarScope } ` : grammarScope
0 commit comments