Skip to content

Commit 4def87c

Browse files
committed
Allow tab-invoked completion in strings, suppress autoinvoke in def
1 parent 9dc9f81 commit 4def87c

File tree

4 files changed

+38
-19
lines changed

4 files changed

+38
-19
lines changed

packages/jupyterlab-lsp/schema/completion.json

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,23 @@
1717
"default": false,
1818
"description": "Whether to enable continuous hinting (Hinterland mode)."
1919
},
20-
"suppressInvokeIn": {
21-
"title": "Suppress invoke in specific code fragments",
20+
"suppressContinuousHintingIn": {
21+
"title": "Suppress invoke continuous hinting in specific code fragments",
22+
"type": "array",
23+
"items": {
24+
"type": "string"
25+
},
26+
"default": ["comment", "string", "def"],
27+
"description": "An array of CodeMirror tokens for which the continuous hinting should be suppressed. The token names vary between languages (modes)."
28+
},
29+
"suppressTriggerCharacterIn": {
30+
"title": "Suppress invoke via trigger character in specific code fragments",
2231
"type": "array",
2332
"items": {
2433
"type": "string"
2534
},
2635
"default": ["comment", "string"],
27-
"description": "An array of CodeMirror tokens for which the auto-invoke should be suppressed. Adding 'def' will prevent continuous hinting when writing a function name in Python, Julia, JavaScript and other languages. The token names vary between languages (modes)."
36+
"description": "An array of CodeMirror tokens for which the auto-invoke after entering a trigger (e.g. `.` in Python or `::` in R) character should be suppressed. The token names vary between languages (modes)."
2837
},
2938
"kernelResponseTimeout": {
3039
"title": "Kernel completion response timeout",

packages/jupyterlab-lsp/src/features/completion/completion.ts

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export class CompletionCM extends CodeMirrorIntegration {
6363
);
6464
(this.feature.labIntegration as CompletionLabIntegration)
6565
.invoke_completer(CompletionTriggerKind.TriggerCharacter)
66-
.catch(console.warn);
66+
.catch(this.console.warn);
6767
return;
6868
}
6969

@@ -74,7 +74,7 @@ export class CompletionCM extends CodeMirrorIntegration {
7474
) {
7575
(this.feature.labIntegration as CompletionLabIntegration)
7676
.invoke_completer(AdditionalCompletionTriggerKinds.AutoInvoked)
77-
.catch(console.warn);
77+
.catch(this.console.warn);
7878
}
7979
}
8080
}
@@ -198,13 +198,18 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
198198
completer.model = new LSPCompleterModel();
199199
}
200200

201-
get completer() {
201+
protected get completer() {
202+
// TODO upstream: make completer public?
202203
return this.current_completion_handler.completer;
203204
}
204205

206+
protected get model(): LSPCompleterModel {
207+
return this.completer.model as LSPCompleterModel;
208+
}
209+
205210
invoke_completer(kind: ExtendedCompletionTriggerKind) {
211+
// TODO: ideally this would not re-trigger if list of items not isIncomplete
206212
let command: string;
207-
208213
this.current_completion_connector.trigger_kind = kind;
209214

210215
if (this.adapterManager.currentAdapter instanceof NotebookAdapter) {
@@ -234,12 +239,9 @@ export class CompletionLabIntegration implements IFeatureLabIntegration {
234239
}
235240

236241
private get current_items() {
237-
// TODO upstream: make completer public?
238-
let completer = this.current_completion_handler.completer;
239-
240242
// TODO upstream: allow to get completionItems() without markup
241243
// (note: not trivial as _markup() does filtering too)
242-
return completer.model.completionItems();
244+
return this.model.completionItems();
243245
}
244246

245247
private get current_index() {

packages/jupyterlab-lsp/src/features/completion/completion_handler.ts

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -61,8 +61,12 @@ export class LSPConnector
6161
return this.options.settings.composite.kernelCompletionsFirst;
6262
}
6363

64-
protected get suppress_auto_invoke_in(): string[] {
65-
return this.options.settings.composite.suppressInvokeIn;
64+
protected get suppress_continuous_hinting_in(): string[] {
65+
return this.options.settings.composite.suppressContinuousHintingIn;
66+
}
67+
68+
protected get suppress_trigger_character_in(): string[] {
69+
return this.options.settings.composite.suppressTriggerCharacterIn;
6670
}
6771

6872
get should_show_documentation(): boolean {
@@ -155,9 +159,16 @@ export class LSPConnector
155159
const cursor = editor.getCursorPosition();
156160
const token = editor.getTokenForPosition(cursor);
157161

158-
if (this.suppress_auto_invoke_in.indexOf(token.type) !== -1) {
159-
this.console.log('Suppressing completer auto-invoke in', token.type);
160-
return;
162+
if (this.trigger_kind == AdditionalCompletionTriggerKinds.AutoInvoked) {
163+
if (this.suppress_continuous_hinting_in.indexOf(token.type) !== -1) {
164+
this.console.debug('Suppressing completer auto-invoke in', token.type);
165+
return;
166+
}
167+
} else if (this.trigger_kind == CompletionTriggerKind.TriggerCharacter) {
168+
if (this.suppress_trigger_character_in.indexOf(token.type) !== -1) {
169+
this.console.debug('Suppressing completer auto-invoke in', token.type);
170+
return;
171+
}
161172
}
162173

163174
const start = editor.getPositionAt(token.offset);

packages/jupyterlab-lsp/src/features/completion/model.ts

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@ export class GenericCompleterModel<
3535
let unfilteredItems = super.completionItems() as T[];
3636
this.query = query;
3737

38-
//if (query) {
3938
// always want to sort
4039
// TODO does this behave strangely with %%<tab> if always sorting?
4140
return this._sortAndFilter(query, unfilteredItems);
42-
//}
43-
//return unfilteredItems;
4441
}
4542

4643
setCompletionItems(newValue: T[]) {

0 commit comments

Comments
 (0)