Skip to content

Commit 5bf7584

Browse files
authored
Merge pull request #487 from krassowski/completer-improvements
Completer improvements: kernel type mapping and dynamic documentation
2 parents b99c323 + 0097bbf commit 5bf7584

File tree

13 files changed

+496
-43
lines changed

13 files changed

+496
-43
lines changed

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
11
## CHANGELOG
22

3-
### `@krassowski/jupyterlab-lsp 3.1.1` (unreleased)
3+
### `@krassowski/jupyterlab-lsp 3.2.0` (unreleased)
4+
5+
- features:
6+
7+
- documentation panel in completer now works for R language too: implemented `completionItem/resolve` ([#487])
8+
- kernel types returned by IPython and IJulia are now mapped to LSP types; you can customize the mappings in settings ([#487])
49

510
- bug fixes:
611

@@ -14,6 +19,7 @@
1419
- `PythonModuleSpec` no longer raises exception when the server module does not exist ([#485])
1520

1621
[#485]: https://github.com/krassowski/jupyterlab-lsp/pull/485
22+
[#487]: https://github.com/krassowski/jupyterlab-lsp/pull/487
1723

1824
### `@krassowski/jupyterlab-lsp 3.1.0` (2021-01-17)
1925

atest/05_Features/Completion.robot

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Resource ../Keywords.robot
77

88
*** Variables ***
99
${COMPLETER_BOX} css:.jp-Completer.jp-HoverBox
10+
${DOCUMENTATION_PANEL} css:.jp-Completer-docpanel
1011

1112
*** Test Cases ***
1213
Works With Kernel Running
@@ -227,6 +228,15 @@ Completes Large Namespaces
227228
Completer Should Suggest abs timeout=30s
228229
[Teardown] Clean Up After Working With File completion.R
229230

231+
Shows Documentation With CompletionItem Resolve
232+
[Setup] Prepare File for Editing R completion completion.R
233+
Place Cursor In File Editor At 8 12
234+
Wait Until Fully Initialized
235+
Trigger Completer
236+
Completer Should Suggest print.default
237+
Completer Should Include Documentation the default method of the
238+
[Teardown] Clean Up After Working With File completion.R
239+
230240
*** Keywords ***
231241
Setup Completion Test
232242
Setup Notebook Python Completion.ipynb
@@ -275,3 +285,8 @@ Trigger Completer
275285
[Arguments] ${timeout}=35s
276286
Press Keys None TAB
277287
Wait Until Page Contains Element ${COMPLETER_BOX} timeout=${timeout}
288+
289+
Completer Should Include Documentation
290+
[Arguments] ${text}
291+
Wait Until Page Contains Element ${DOCUMENTATION_PANEL} timeout=10s
292+
Element Should Contain ${DOCUMENTATION_PANEL} ${text}

atest/examples/completion.R

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,3 +4,5 @@ tools::
44
datasets:::
55
# `base:::<tab>` → works
66
base:::
7+
# `print.defaul<tab>` → shows documentation for `print.default`
8+
print.defaul

packages/completion-theme/src/index.ts

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@ import {
1212
ILSPCompletionThemeManager,
1313
PLUGIN_ID,
1414
COMPLETER_THEME_PREFIX,
15-
KernelKind
15+
KernelKind,
16+
CompletionItemKindStrings
1617
} from './types';
1718
import { render_themes_list } from './about';
1819
import '../style/index.css';
@@ -22,10 +23,12 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
2223
protected themes: Map<string, ICompletionTheme>;
2324
private current_theme_id: string;
2425
private icons_cache: Map<string, LabIcon>;
26+
private icon_overrides: Record<string, CompletionItemKindStrings>;
2527

2628
constructor(protected themeManager: IThemeManager) {
2729
this.themes = new Map();
2830
this.icons_cache = new Map();
31+
this.icon_overrides = {};
2932
themeManager.themeChanged.connect(this.update_icons_set, this);
3033
}
3134

@@ -78,12 +81,16 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
7881
}
7982
let options = this.current_theme.icons.options || {};
8083
if (type) {
84+
if (type in this.icon_overrides) {
85+
type = this.icon_overrides[type];
86+
}
8187
type =
8288
type.substring(0, 1).toUpperCase() + type.substring(1).toLowerCase();
8389
}
8490
if (this.current_icons.has(type)) {
8591
return this.current_icons.get(type).bindprops(options);
8692
}
93+
8794
if (type === KernelKind) {
8895
return kernelIcon;
8996
}
@@ -144,6 +151,12 @@ export class CompletionThemeManager implements ILSPCompletionThemeManager {
144151
buttons: [Dialog.okButton()]
145152
}).catch(console.warn);
146153
}
154+
155+
set_icons_overrides(
156+
iconOverrides: Record<string, CompletionItemKindStrings>
157+
) {
158+
this.icon_overrides = iconOverrides;
159+
}
147160
}
148161

149162
const LSP_CATEGORY = 'Language server protocol';

packages/completion-theme/src/types.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -116,6 +116,10 @@ export interface ILSPCompletionThemeManager {
116116
get_iconset(
117117
theme: ICompletionTheme
118118
): Map<keyof ICompletionIconSet, LabIcon.ILabIcon>;
119+
120+
set_icons_overrides(
121+
map: Record<string, CompletionItemKindStrings | 'Kernel'>
122+
): void;
119123
}
120124

121125
export const ILSPCompletionThemeManager = new Token<ILSPCompletionThemeManager>(

packages/completion-theme/style/index.css

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,3 +23,8 @@
2323
.jp-Completer-docpanel {
2424
overflow: auto;
2525
}
26+
27+
.lsp-completer-placeholder:after {
28+
content: 'Loading...';
29+
color: #7f7f7f;
30+
}

packages/jupyterlab-lsp/schema/completion.json

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,54 @@
3131
"type": ["string", "null"],
3232
"default": "vscode",
3333
"description": "The identifier of a completer theme with icons which indicate the kind of completion. Set to null to disable icons."
34+
},
35+
"typesMap": {
36+
"title": "Mapping of custom kernel types to valid completion kind names",
37+
"description": "Mapping used for icon selection. Accepted values are the names of CompletionItemKind and 'Kernel' literal. The defaults aim to provide good initial experience for Julia, Python and R kernels.",
38+
"type": "object",
39+
"default": {
40+
"<unknown>": "Kernel",
41+
"instance": "Value",
42+
"path": "File",
43+
"param": "Variable",
44+
"missing": "Constant",
45+
"nothing": "Constant",
46+
"undefinitializer": "Constant",
47+
"base.devnull": "Constant"
48+
},
49+
"patternProperties": {
50+
"^.*$": {
51+
"type": "string",
52+
"enum": [
53+
"Kernel",
54+
"Text",
55+
"Method",
56+
"Function",
57+
"Constructor",
58+
"Field",
59+
"Variable",
60+
"Class",
61+
"Interface",
62+
"Module",
63+
"Property",
64+
"Unit",
65+
"Value",
66+
"Enum",
67+
"Keyword",
68+
"Snippet",
69+
"Color",
70+
"File",
71+
"Reference",
72+
"Folder",
73+
"EnumMember",
74+
"Constant",
75+
"Struct",
76+
"Event",
77+
"Operator",
78+
"TypeParameter"
79+
]
80+
}
81+
}
3482
}
3583
},
3684
"jupyter.lab.shortcuts": []

packages/jupyterlab-lsp/src/connection.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
// Introduced modifications are BSD licenced, copyright JupyterLab development team.
55
import * as lsProtocol from 'vscode-languageserver-protocol';
66
import {
7+
IDocumentInfo,
78
ILspOptions,
89
IPosition,
9-
LspWsConnection,
10-
IDocumentInfo
10+
LspWsConnection
1111
} from 'lsp-ws-connection';
1212
import { until_ready } from './utils';
1313

@@ -138,4 +138,21 @@ export class LSPConnection extends LspWsConnection {
138138
);
139139
documentInfo.version++;
140140
}
141+
142+
async getCompletionResolve(completionItem: lsProtocol.CompletionItem) {
143+
if (!this.isReady || !this.isCompletionResolveProvider()) {
144+
return;
145+
}
146+
return this.connection.sendRequest<lsProtocol.CompletionItem>(
147+
'completionItem/resolve',
148+
completionItem
149+
);
150+
}
151+
152+
/**
153+
* Does support completionItem/resolve?.
154+
*/
155+
public isCompletionResolveProvider(): boolean {
156+
return this.serverCapabilities?.completionProvider?.resolveProvider;
157+
}
141158
}

0 commit comments

Comments
 (0)