Skip to content

Commit b9799e6

Browse files
authored
Merge pull request #322 from krassowski/completer-icons
Implement completer icons and add a stub for themes system
2 parents 4b1c47a + a60ee5b commit b9799e6

File tree

117 files changed

+2010
-131
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

117 files changed

+2010
-131
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
- support for JupyterLab 2.2 ([#301][])
88
- completer now displays server-provided documentation,
99
and a kernel icon for kernel suggestions without type information ([#301][])
10+
- add two icons themes for the completer (material and vscode) ([#322])
1011
- the documentation by the completer can be turned on or off ([#315])
1112
- continuous hinting (Hinterland mode) can be enabled in settings ([#315])
1213
- tokens in which the completer should not be triggered can be changed ([#315])
@@ -32,6 +33,7 @@
3233
[#301]: https://github.com/krassowski/jupyterlab-lsp/pull/301
3334
[#315]: https://github.com/krassowski/jupyterlab-lsp/pull/315
3435
[#318]: https://github.com/krassowski/jupyterlab-lsp/pull/318
36+
[#322]: https://github.com/krassowski/jupyterlab-lsp/pull/322
3537
[00448d0]: https://github.com/krassowski/jupyterlab-lsp/pull/318/commits/00448d0c55e7f9a1e7e0a5322f17610daac47dfe
3638
[bacc006]: https://github.com/krassowski/jupyterlab-lsp/pull/318/commits/bacc0066da0727ff7397574914bf0401e4d8f7cb
3739
[4e5b2ad]: https://github.com/krassowski/jupyterlab-lsp/pull/318/commits/4e5b2adf655120458cc8be4b453fe9a78c98e061

atest/05_Features/Completion.robot

Lines changed: 68 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,14 @@ Works When Kernel Is Shut Down
3939
# this comes from kernel:
4040
Completer Should Not Suggest %%timeit
4141

42+
Works In File Editor
43+
Prepare File for Editing Python completion completion.py
44+
Place Cursor In File Editor At 9 2
45+
Capture Page Screenshot 01-editor-ready.png
46+
Trigger Completer
47+
Completer Should Suggest add
48+
[Teardown] Clean Up After Working With File completion.py
49+
4250
Autocompletes If Only One Option
4351
Enter Cell Editor 3 line=1
4452
Press Keys None cle
@@ -113,6 +121,61 @@ Triggers Completer On Dot
113121
Wait Until Page Contains Element ${COMPLETER_BOX} timeout=35s
114122
Completer Should Suggest append
115123

124+
Material Theme Works
125+
Configure JupyterLab Plugin {"theme": "material"} plugin id=${COMPLETION PLUGIN ID}
126+
Capture Page Screenshot 01-configured.png
127+
Enter Cell Editor 1 line=2
128+
Trigger Completer
129+
Capture Page Screenshot 02-completions-shown.png
130+
# TabError is a builtin exception which is a class in Python,
131+
# so we should get lsp:material-class-light icon:
132+
Completer Should Suggest TabError
133+
Completer Should Include Icon lsp:material-class-light
134+
135+
VSCode Theme Works
136+
Configure JupyterLab Plugin {"theme": "vscode"} plugin id=${COMPLETION PLUGIN ID}
137+
Capture Page Screenshot 01-configured.png
138+
Enter Cell Editor 1 line=2
139+
Trigger Completer
140+
Capture Page Screenshot 02-completions-shown.png
141+
Completer Should Suggest TabError
142+
Completer Should Include Icon lsp:vscode-class-light
143+
144+
VSCode Dark Theme Works
145+
${file} = Set Variable Completion.ipynb
146+
Lab Command Use JupyterLab Dark Theme
147+
Wait For Splash
148+
Capture Page Screenshot 00-theme-changed.png
149+
Configure JupyterLab Plugin {"theme": "vscode"} plugin id=${COMPLETION PLUGIN ID}
150+
Capture Page Screenshot 01-configured.png
151+
Open ${file} in ${MENU NOTEBOOK}
152+
Enter Cell Editor 1 line=2
153+
Wait Until Fully Initialized
154+
Trigger Completer
155+
Capture Page Screenshot 02-completions-shown.png
156+
Completer Should Suggest TabError
157+
Completer Should Include Icon lsp:vscode-class-dark
158+
Lab Command Use JupyterLab Light Theme
159+
Wait For Splash
160+
161+
Works Without A Theme
162+
Configure JupyterLab Plugin {"theme": null} plugin id=${COMPLETION PLUGIN ID}
163+
Capture Page Screenshot 01-configured.png
164+
Enter Cell Editor 1 line=2
165+
Trigger Completer
166+
Capture Page Screenshot 02-completions-shown.png
167+
Completer Should Suggest TabError
168+
Wait Until Page Contains Element ${COMPLETER_BOX} .jp-Completer-monogram
169+
170+
Works With Incorrect Theme
171+
Configure JupyterLab Plugin {"theme": "a-non-existing-theme"} plugin id=${COMPLETION PLUGIN ID}
172+
Capture Page Screenshot 01-configured.png
173+
Enter Cell Editor 1 line=2
174+
Trigger Completer
175+
Capture Page Screenshot 02-completions-shown.png
176+
Completer Should Suggest TabError
177+
Wait Until Page Contains Element ${COMPLETER_BOX} .jp-Completer-monogram
178+
116179
*** Keywords ***
117180
Setup Completion Test
118181
Setup Notebook Python Completion.ipynb
@@ -130,7 +193,7 @@ Cell Editor Should Equal
130193
Select Completer Suggestion
131194
[Arguments] ${text}
132195
${suggestion} = Set Variable css:.jp-Completer-item[data-value="${text}"]
133-
Wait Until Element Is Visible ${suggestion} timeout=10s
196+
Wait Until Element Is Visible ${suggestion} timeout=10s
134197
Mouse Over ${suggestion}
135198
Click Element ${suggestion} code
136199

@@ -139,6 +202,10 @@ Completer Should Suggest
139202
Wait Until Page Contains Element ${COMPLETER_BOX} .jp-Completer-item[data-value="${text}"]
140203
Capture Page Screenshot ${text.replace(' ', '_')}.png
141204

205+
Completer Should Include Icon
206+
[Arguments] ${icon}
207+
Wait Until Page Contains Element ${COMPLETER_BOX} svg[data-icon="${icon}"]
208+
142209
Completer Should Not Suggest
143210
[Arguments] ${text}
144211
Wait Until Page Does Not Contain Element ${COMPLETER_BOX} .jp-Completer-item[data-value="${text}"]

atest/Keywords.robot

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ Place Cursor In Cell Editor At
263263
Enter Cell Editor ${cell_nr} ${line}
264264
Execute JavaScript return document.querySelector('.jp-Cell:nth-child(${cell_nr}) .CodeMirror').CodeMirror.setCursor({line: ${line} - 1, ch: ${character}})
265265

266+
Enter File Editor
267+
Click Element css:.jp-FileEditor .CodeMirror
268+
Wait Until Page Contains Element css:.jp-FileEditor .CodeMirror-focused
269+
270+
Place Cursor In File Editor At
271+
[Arguments] ${line} ${character}
272+
Enter File Editor
273+
Execute JavaScript return document.querySelector('.jp-FileEditor .CodeMirror').CodeMirror.setCursor({line: ${line} - 1, ch: ${character}})
274+
266275
Wait Until Fully Initialized
267276
Wait Until Element Contains ${STATUSBAR} Fully initialized timeout=60s
268277

atest/Variables.robot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@ ${CM CURSOR} css:.CodeMirror-cursor
3333
${CM CURSORS} css:.CodeMirror-cursors:not([style='visibility: hidden'])
3434
# settings
3535
${LSP PLUGIN ID} @krassowski/jupyterlab-lsp:plugin
36+
${COMPLETION PLUGIN ID} @krassowski/jupyterlab-lsp:completion
3637
${LSP PLUGIN SETTINGS FILE} @krassowski${/}jupyterlab-lsp${/}plugin.jupyterlab-settings
3738
${CSS USER SETTINGS} .jp-SettingsRawEditor-user
3839
${JLAB XP CLOSE SETTINGS} ${JLAB XP DOCK TAB}\[contains(., 'Settings')]/*[contains(@class, 'm-TabBar-tabCloseIcon')]

atest/examples/completion.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
addition = ''
2+
3+
4+
def add(a: int, b: int):
5+
"""Adds a and b together"""
6+
return a, b
7+
8+
9+
ad

azure-pipelines.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ variables:
2525
LINKED_EXTENSIONS: >-
2626
packages/lsp-ws-connection
2727
packages/jupyterlab-go-to-definition
28+
packages/completion-theme
29+
packages/theme-vscode
30+
packages/theme-material
2831
2932
jobs:
3033
- template: ci/job.lint.yml

docs/Extending.ipynb

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,45 @@
112112
"a work-in-progress."
113113
]
114114
},
115+
{
116+
"cell_type": "markdown",
117+
"metadata": {},
118+
"source": [
119+
"### How to add custom icons for the completer?\n",
120+
"\n",
121+
"1. Prepare the icons in the SVG format (we use 16 x 16 pixels, but you should be\n",
122+
" fine with up to 24 x 24). You can load them for webpack in typescript using\n",
123+
" imports if you include a `typings.d.ts` file with the following content:\n",
124+
"\n",
125+
" ```typescript\n",
126+
" declare module '*.svg' {\n",
127+
" const script: string;\n",
128+
" export default script;\n",
129+
" }\n",
130+
" ```\n",
131+
"\n",
132+
" in your `src/`. You should probably keep the icons in your `style/`\n",
133+
" directory.\n",
134+
"\n",
135+
"2. Prepare `CompletionKind` → `IconSvgString` mapping for the light (and\n",
136+
" optionally dark) theme, implementing the `ICompletionIconSet` interface. We\n",
137+
" have an additional `Kernel` completion kind that is used for completions\n",
138+
" provided by kernel that had no recognisable type provided.\n",
139+
"\n",
140+
"3. Provide all other metadata required by the `ICompletionTheme` interface and\n",
141+
" register it on `ILSPCompletionThemeManager` instance using `register_theme()`\n",
142+
" method.\n",
143+
"\n",
144+
"4. Provide any additional CSS styling targeting the JupyterLab completer\n",
145+
" elements inside of `.lsp-completer-theme-{id}`, e.g.\n",
146+
" `.lsp-completer-theme-material .jp-Completer-icon svg` for the material\n",
147+
" theme. Rememmber to include the styles by importing the in one of the source\n",
148+
" files.\n",
149+
"\n",
150+
"For an example of a complete theme see\n",
151+
"[theme-vscode](https://github.com/krassowski/jupyterlab-lsp/tree/master/packages/theme-vscode)."
152+
]
153+
},
115154
{
116155
"cell_type": "markdown",
117156
"metadata": {},

package.json

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
"dockerfile-language-server-nodejs": "^0.0.22",
99
"eslint": "^6.8.0",
1010
"eslint-config-prettier": "^6.7.0",
11+
"eslint-plugin-import": "^2.22.0",
1112
"eslint-plugin-jest": "^23.8.2",
1213
"eslint-plugin-prettier": "^3.1.1",
1314
"eslint-plugin-react": "^7.19.0",
@@ -24,8 +25,7 @@
2425
"yaml-language-server": "~0.4.0"
2526
},
2627
"husky": {
27-
"hooks": {
28-
}
28+
"hooks": {}
2929
},
3030
"prettier": {
3131
"arrowParens": "avoid",
@@ -35,9 +35,12 @@
3535
"private": true,
3636
"scripts": {
3737
"bootstrap": "jlpm --no-optional --prefer-offline && lerna bootstrap && jlpm lint && jlpm clean && jlpm build",
38-
"build": "jlpm build:schema && jlpm build:meta && jlpm build:ws",
38+
"build": "jlpm build:schema && jlpm build:completion-theme && jlpm build:theme-material && jlpm build:theme-vscode && jlpm build:meta && jlpm build:ws",
3939
"build:schema": "lerna run build:schema --stream",
4040
"build:meta": "lerna run build --stream --scope @krassowski/jupyterlab-lsp-metapackage",
41+
"build:completion-theme": "lerna run build --stream --scope @krassowski/completion-theme",
42+
"build:theme-vscode": "lerna run build --stream --scope @krassowski/theme-vscode",
43+
"build:theme-material": "lerna run build --stream --scope @krassowski/theme-material",
4144
"build:ws": "lerna run build --stream --scope lsp-ws-connection",
4245
"watch": "lerna run --parallel watch",
4346
"bundle": "lerna run --parallel bundle",

packages/.eslintrc.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ module.exports = {
2727
parserOptions: {
2828
project: 'packages/tsconfig.eslint.json'
2929
},
30-
plugins: ['@typescript-eslint', 'jest'],
30+
plugins: ['@typescript-eslint', 'jest', 'import'],
3131
rules: {
3232
'@typescript-eslint/ban-ts-ignore': 'warn',
3333
'@typescript-eslint/camelcase': 'off',
@@ -56,6 +56,11 @@ module.exports = {
5656
'no-undef': 'warn',
5757
'no-useless-escape': 'off',
5858
'prefer-const': 'off',
59+
// deviations from jupyterlab, should not be changed
60+
// a pitfall of enums is that they do not work correctly
61+
// when circular dependencies are present
62+
// (see https://stackoverflow.com/a/59665223/)
63+
'import/no-cycle': 'error',
5964
// deviations from jupyterlab, should probably be fixed
6065
'@typescript-eslint/triple-slash-reference': 'off',
6166
'jest/no-test-callback': 'off',
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
{
2+
"name": "@krassowski/completion-theme",
3+
"version": "2.0.0",
4+
"description": "Completion theme manager for JupyterLab-LSP",
5+
"keywords": [
6+
"jupyter",
7+
"jupyterlab",
8+
"jupyterlab-extension",
9+
"lsp",
10+
"language-server-protocol",
11+
"theme",
12+
"completer"
13+
],
14+
"homepage": "https://github.com/krassowski/jupyterlab-lsp",
15+
"bugs": {
16+
"url": "https://github.com/krassowski/jupyterlab-lsp/issues"
17+
},
18+
"license": "BSD-3-Clause",
19+
"author": "JupyterLab-LSP Developement Team",
20+
"files": [
21+
"{lib,style,schema,src}/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,css,json,ts,tsx,txt,md}"
22+
],
23+
"main": "lib/index.js",
24+
"types": "lib/index.d.ts",
25+
"repository": {
26+
"type": "git",
27+
"url": "https://github.com/krassowski/jupyterlab-lsp.git"
28+
},
29+
"scripts": {
30+
"build": "tsc -b",
31+
"bundle": "npm pack .",
32+
"clean": "rimraf lib",
33+
"lab:link": "jupyter labextension link . --no-build"
34+
},
35+
"devDependencies": {
36+
"react": "*",
37+
"@jupyterlab/ui-components": "~2.2.0"
38+
},
39+
"peerDependencies": {},
40+
"jupyterlab": {
41+
"extension": true,
42+
"schemaDir": "schema"
43+
}
44+
}

0 commit comments

Comments
 (0)