@@ -33,147 +33,9 @@ import {
33
33
import { LabIcon } from '@jupyterlab/ui-components' ;
34
34
import { ILSPLogConsole } from '../../tokens' ;
35
35
import { CompletionLabIntegration } from './completion' ;
36
+ import { LazyCompletionItem } from './item' ;
36
37
import ICompletionItemsResponseType = CompletionHandler . ICompletionItemsResponseType ;
37
38
38
- export class LazyCompletionItem implements CompletionHandler . ICompletionItem {
39
- private _documentation : string ;
40
- private _is_documentation_markdown : boolean ;
41
- private _requested_resolution : boolean ;
42
- private _resolved : boolean ;
43
- /**
44
- * Self-reference to make sure that the instance for will remain accessible
45
- * after any copy operation (whether via spread syntax or Object.assign)
46
- * performed by the JupyterLab completer internals.
47
- */
48
- public self : LazyCompletionItem ;
49
-
50
- get isDocumentationMarkdown ( ) : boolean {
51
- return this . _is_documentation_markdown ;
52
- }
53
-
54
- constructor (
55
- /**
56
- * User facing completion.
57
- * If insertText is not set, this will be inserted.
58
- */
59
- public label : string ,
60
- /**
61
- * Type of this completion item.
62
- */
63
- public type : string ,
64
- /**
65
- * LabIcon object for icon to be rendered with completion type.
66
- */
67
- public icon : LabIcon ,
68
- private match : lsProtocol . CompletionItem ,
69
- private connector : LSPConnector ,
70
- private uri : string
71
- ) {
72
- this . _setDocumentation ( match . documentation ) ;
73
- this . _requested_resolution = false ;
74
- this . _resolved = false ;
75
- this . self = this ;
76
- }
77
-
78
- private _setDocumentation ( documentation : string | lsProtocol . MarkupContent ) {
79
- if ( lsProtocol . MarkupContent . is ( documentation ) ) {
80
- this . _documentation = documentation . value ;
81
- this . _is_documentation_markdown = documentation . kind === 'markdown' ;
82
- } else {
83
- this . _documentation = documentation ;
84
- this . _is_documentation_markdown = false ;
85
- }
86
- }
87
-
88
- /**
89
- * Completion to be inserted.
90
- */
91
- get insertText ( ) : string {
92
- return this . match . insertText || this . match . label ;
93
- }
94
-
95
- public supportsResolution ( ) {
96
- const connection = this . connector . get_connection ( this . uri ) ;
97
-
98
- return connection . isCompletionResolveProvider ( ) ;
99
- }
100
-
101
- public needsResolution ( ) : boolean {
102
- if ( this . documentation ) {
103
- return false ;
104
- }
105
-
106
- if ( this . _resolved ) {
107
- return false ;
108
- }
109
-
110
- if ( this . _requested_resolution ) {
111
- return false ;
112
- }
113
-
114
- return this . supportsResolution ( ) ;
115
- }
116
-
117
- public isResolved ( ) {
118
- return this . _resolved ;
119
- }
120
-
121
- public fetchDocumentation ( ) : void {
122
- if ( ! this . needsResolution ( ) ) {
123
- return ;
124
- }
125
-
126
- const connection = this . connector . get_connection ( this . uri ) ;
127
-
128
- this . _requested_resolution = true ;
129
-
130
- connection
131
- . getCompletionResolve ( this . match )
132
- . then ( resolvedCompletionItem => {
133
- this . connector . lab_integration . set_doc_panel_placeholder ( false ) ;
134
- if ( resolvedCompletionItem === null ) {
135
- return ;
136
- }
137
- this . _setDocumentation ( resolvedCompletionItem . documentation ) ;
138
- this . _resolved = true ;
139
- this . connector . lab_integration . refresh_doc_panel ( this ) ;
140
- } )
141
- . catch ( e => {
142
- this . connector . lab_integration . set_doc_panel_placeholder ( false ) ;
143
- console . warn ( e ) ;
144
- } ) ;
145
- }
146
-
147
- /**
148
- * A human-readable string with additional information
149
- * about this item, like type or symbol information.
150
- */
151
- get documentation ( ) : string {
152
- if ( ! this . connector . should_show_documentation ) {
153
- return null ;
154
- }
155
- if ( this . _documentation ) {
156
- return this . _documentation ;
157
- }
158
- return null ;
159
- }
160
-
161
- /**
162
- * Indicates if the item is deprecated.
163
- */
164
- get deprecated ( ) : boolean {
165
- if ( this . match . deprecated ) {
166
- return this . match . deprecated ;
167
- }
168
- return (
169
- this . match . tags &&
170
- this . match . tags . some (
171
- tag => tag == lsProtocol . CompletionItemTag . Deprecated
172
- )
173
- ) ;
174
- }
175
- }
176
-
177
39
/**
178
40
* A LSP connector for completion handlers.
179
41
*/
@@ -195,6 +57,11 @@ export class LSPConnector
195
57
lab_integration : CompletionLabIntegration ;
196
58
items : CompletionHandler . ICompletionItems ;
197
59
60
+ get kernel_completions_first ( ) : boolean {
61
+ // TODO: test this in acceptance tests!
62
+ return this . options . settings . composite . kernelCompletionsFirst ;
63
+ }
64
+
198
65
protected get suppress_auto_invoke_in ( ) : string [ ] {
199
66
return this . options . settings . composite . suppressInvokeIn ;
200
67
}
@@ -449,7 +316,6 @@ export class LSPConnector
449
316
lspCompletionItems . forEach ( match => {
450
317
let kind = match . kind ? CompletionItemKind [ match . kind ] : '' ;
451
318
let completionItem = new LazyCompletionItem (
452
- match . label ,
453
319
kind ,
454
320
this . icon_for ( kind ) ,
455
321
match ,
@@ -520,15 +386,17 @@ export class LSPConnector
520
386
label : item . text as string ,
521
387
insertText : item . text as string ,
522
388
type : item . type as string ,
523
- icon : this . icon_for ( item . type as string )
389
+ icon : this . icon_for ( item . type as string ) ,
390
+ sortText : this . kernel_completions_first ? 'a' : 'z'
524
391
} ;
525
392
} ) ;
526
393
} else {
527
394
items = reply . matches . map ( match => {
528
395
return {
529
396
label : match ,
530
397
insertText : match ,
531
- icon : this . icon_for ( 'Kernel' )
398
+ icon : this . icon_for ( 'Kernel' ) ,
399
+ sortText : this . kernel_completions_first ? 'a' : 'z'
532
400
} ;
533
401
} ) ;
534
402
}
0 commit comments