Skip to content

Commit 4b53956

Browse files
authored
Merge branch 'master' into fix/diagnostics-panel-crash
2 parents 5fb736d + a7f07c6 commit 4b53956

File tree

7 files changed

+79
-23
lines changed

7 files changed

+79
-23
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,17 @@
88
- completer panel will now always render markdown documentation if available ([#520])
99
- the implementation re-renders the panel as it is the best we can do until [jupyterlab#9663](https://github.com/jupyterlab/jupyterlab/pull/9663) is merged
1010
- the completer now uses `filterText` and `sortText` if available to better filter and sort completions ([#520])
11+
- completer `suppressInvokeIn` setting was removed; `suppressContinuousHintingIn` and `suppressTriggerCharacterIn` settings were added ([#521])
12+
- `suppressContinuousHintingIn` by default includes `def` to improve the experience when writing function names ([#521])
1113

1214
- bug fixes:
15+
- user-invoked completion in strings works again ([#521])
1316
- completer documentation will now consistently show up after filtering the completion items ([#520])
1417
- completions containing HTML-like syntax will be displayed properly (an upstream issue) ([#520])
1518
- diagnostics panel will no longer break when foreign documents (e.g. `%%R` cell magics) are removed ([#522])
1619

1720
[#520]: https://github.com/krassowski/jupyterlab-lsp/pull/520
21+
[#521]: https://github.com/krassowski/jupyterlab-lsp/pull/521
1822
[#522]: https://github.com/krassowski/jupyterlab-lsp/pull/522
1923

2024
### `@krassowski/jupyterlab-lsp 3.3.1` (2020-02-07)

atest/05_Features/Completion.robot

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,11 +102,24 @@ Works After Kernel Restart In New Cells
102102
Works In File Editor
103103
[Setup] Prepare File for Editing Python completion completion.py
104104
Place Cursor In File Editor At 9 2
105-
Capture Page Screenshot 01-editor-ready.png
105+
Wait Until Fully Initialized
106106
Trigger Completer
107107
Completer Should Suggest add
108108
[Teardown] Clean Up After Working With File completion.py
109109

110+
Completes In Strings Or Python Dictionaries
111+
[Setup] Prepare File for Editing Python completion completion.py
112+
Place Cursor In File Editor At 16 0
113+
Wait Until Fully Initialized
114+
Press Keys None test_dict['']
115+
Place Cursor In File Editor At 16 11
116+
Trigger Completer
117+
# note: in jedi-language-server this would be key_a without '
118+
Completer Should Suggest 'key_a
119+
Select Completer Suggestion 'key_a
120+
Wait Until Keyword Succeeds 40x 0.5s File Editor Line Should Equal 15 test_dict['key_a']
121+
[Teardown] Clean Up After Working With File completion.py
122+
110123
Continious Hinting Works
111124
Configure JupyterLab Plugin {"continuousHinting": true} plugin id=${COMPLETION PLUGIN ID}
112125
Prepare File for Editing Python completion completion.py

atest/examples/completion.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,4 +6,10 @@ def add(a: int, b: int):
66
return a, b
77

88

9-
ad
9+
ad
10+
11+
12+
test_dict = {
13+
'key_a': 1,
14+
'key_b': 2
15+
}

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: 32 additions & 7 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);
@@ -343,9 +354,15 @@ export class LSPConnector
343354
this.console.debug('Transformed');
344355
// required to make the repetitive trigger characters like :: or ::: work for R with R languageserver,
345356
// see https://github.com/krassowski/jupyterlab-lsp/issues/436
346-
const prefix_offset = token.value.length;
357+
let prefix_offset = token.value.length;
358+
// completion of dictionaries for Python with jedi-language-server was
359+
// causing an issue for dic['<tab>'] case; to avoid this let's make
360+
// sure that prefix.length >= prefix.offset
361+
if (all_non_prefixed && prefix_offset > prefix.length) {
362+
prefix_offset = prefix.length;
363+
}
347364

348-
return {
365+
let response = {
349366
// note in the ContextCompleter it was:
350367
// start: token.offset,
351368
// end: token.offset + token.value.length,
@@ -359,6 +376,14 @@ export class LSPConnector
359376
end: token.offset + prefix.length,
360377
items: items
361378
};
379+
if (response.start > response.end) {
380+
console.warn(
381+
'Response contains start beyond end; this should not happen!',
382+
response
383+
);
384+
}
385+
386+
return response;
362387
}
363388

364389
protected icon_for(type: string): LabIcon {

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)