Skip to content

Commit 1ce22df

Browse files
authored
Allow to disable LSP toolbar item in Notebook view (#1139)
* Allow to disable LSP toolbar item in Notebook view * Update expectation * Try without dragging diagnostics panel * Try to fix mac os job * Fix venv usage * Try to fix test * Try to make R check more robust * Use aabsolute path * Fix typo * Drop `pypy` from testing for now * Fix spurious period * More fixes
1 parent acc679b commit 1ce22df

File tree

8 files changed

+58
-25
lines changed

8 files changed

+58
-25
lines changed

.github/workflows/job.test.yml

Lines changed: 19 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -337,7 +337,7 @@ jobs:
337337
max-parallel: 3
338338
matrix:
339339
os: ['ubuntu', 'macos', 'windows']
340-
python: ['3.9', '3.12', 'pypy-3.9']
340+
python: ['3.9', '3.12']
341341
include:
342342
- python: '3.9'
343343
dist: 'jupyter*lsp*.whl'
@@ -348,9 +348,6 @@ jobs:
348348
- python: '3.12'
349349
dist: 'jupyter*lsp*.whl'
350350
lab: '>=4.1.0,<5'
351-
- python: 'pypy-3.9'
352-
dist: 'jupyter*lsp*.tar.gz'
353-
lab: '>=4.1.0,<5'
354351
- os: 'windows'
355352
py_cmd: python
356353
- os: 'macos'
@@ -362,8 +359,6 @@ jobs:
362359
# see https://github.com/actions/setup-python/issues/906
363360
- os: macos
364361
python: '3.9'
365-
- os: macos
366-
python: 'pypy-3.9'
367362
steps:
368363
- name: Install Python
369364
uses: actions/setup-python@v5
@@ -374,22 +369,32 @@ jobs:
374369
with:
375370
name: jupyterlab-lsp dist ${{ github.run_number }}
376371
path: ./dist
372+
- name: Create testing environment
373+
run: |
374+
set -eux
375+
${{ matrix.py_cmd }} -m venv .venv
376+
if [[ "$RUNNER_OS" == "Windows" ]]; then
377+
VENV_PYTHON="$(pwd -W)\\\.venv\\Scripts\\python.exe"
378+
else
379+
VENV_PYTHON="$(pwd)/.venv/bin/python"
380+
fi
381+
echo "VENV_PYTHON=$VENV_PYTHON" >> "$GITHUB_ENV"
377382
- name: Install the prerequisites
378-
run: ${{ matrix.py_cmd }} -m pip install pip wheel
383+
run: $VENV_PYTHON -m pip install pip wheel
379384
- name: Install the package
380-
run: cd dist && ${{ matrix.py_cmd }} -m pip install -vv ${{ matrix.dist }} 'jupyterlab${{ matrix.lab }}'
385+
run: cd dist && "$VENV_PYTHON" -m pip install -vv ${{ matrix.dist }} 'jupyterlab${{ matrix.lab }}'
381386
- name: Validate environment
382387
run: |
383388
set -eux
384-
${{ matrix.py_cmd }} -m pip freeze
385-
${{ matrix.py_cmd }} -m pip check
389+
"$VENV_PYTHON" -m pip freeze
390+
"$VENV_PYTHON" -m pip check
386391
- name: Validate the install
387392
run: |
388393
set -eux
389-
${{ matrix.py_cmd }} -m jupyter labextension list
390-
${{ matrix.py_cmd }} -m jupyter server extension list
391-
${{ matrix.py_cmd }} -m jupyter labextension list 2>&1 | grep -ie "jupyterlab-lsp.*enabled.*ok" -
392-
${{ matrix.py_cmd }} -m jupyter server extension list 2>&1 | grep -ie "jupyter_lsp.*enabled" -
394+
"$VENV_PYTHON" -m jupyter labextension list
395+
"$VENV_PYTHON" -m jupyter server extension list
396+
"$VENV_PYTHON" -m jupyter labextension list 2>&1 | grep -ie "jupyterlab-lsp.*enabled.*ok" -
397+
"$VENV_PYTHON" -m jupyter server extension list 2>&1 | grep -ie "jupyter_lsp.*enabled" -
393398
394399
source:
395400
name: smoke source install ${{ matrix.os }} py${{ matrix.python }} lab${{ matrix.lab }}

atest/suites/03_Notebook.robot

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ Foreign Extractors
5656
@{diagnostics} = Create List
5757
... Double quote to prevent globbing and word splitting # bash, configured by spec.env
5858
... ame 'valid' # python, mypy and pyflakes will fight over `(N|n)ame 'valid'`, just hope for the best
59-
... Remove trailing whitespace. # r
59+
... (lintr) # r
6060
... `frob` is misspelt # markdown
6161
... Command terminated with space # latex
6262
FOR ${diagnostic} IN @{diagnostics}

atest/suites/05_Features/Highlights.robot

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ Highlights are changed when moving cursor between cells
4040
Press Keys None DOWN # cursor to next cell, which is empty
4141
Should Not Highlight Any Tokens
4242
Press Keys None DOWN # cursor to third cell (`|gist = 1`)
43+
Press Keys None RIGHT # (`g|ist = 1`)
4344
Should Highlight Token gist
4445
Press Keys None DOWN # cursor to third cell, second line (`|test `)
4546
Should Highlight Token test

atest/suites/07_Configuration.robot

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,14 @@ Python Nested
1515
Settings Should Change Editor Diagnostics Python style.py pylsp
1616
... {"pylsp": {"plugins": {"flake8": {"enabled": true},"pyflakes": {"enabled": false}}}}
1717
... undefined name 'foo' (pyflakes)
18-
... undefined name 'foo' (flake8)
18+
... W291 trailing whitespace (flake8)
1919

2020
Python Dotted
2121
[Documentation] pyflakes is enabled by default, but flake8 is not
2222
Settings Should Change Editor Diagnostics Python style.py pylsp
2323
... {"pylsp.plugins.flake8.enabled": true, "pylsp.plugins.pyflakes.enabled": false}
2424
... undefined name 'foo' (pyflakes)
25-
... undefined name 'foo' (flake8)
25+
... W291 trailing whitespace (flake8)
2626

2727
Python (server-side via overrides JSON)
2828
[Documentation] same as "Python" but changing the defaults in server specification via `overrides.json`
@@ -92,7 +92,6 @@ Settings Should Change Editor Diagnostics
9292
Drag and Drop By Offset ${tab} 0 100
9393
Wait Until Fully Initialized
9494
Open Diagnostics Panel
95-
Drag and Drop By Offset ${JLAB XP DOCK TAB}\[contains(., 'Diagnostics Panel')] 600 -200
9695
Click Element ${JLAB XP DOCK TAB}\[contains(., 'Launcher')]/${close icon}
9796
IF "${before}"
9897
Wait Until Page Contains Diagnostic ${before diagnostic} timeout=30s

packages/jupyterlab-lsp/schema/plugin.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,5 +82,13 @@
8282
"description": "Whether to ask server to send logs with execution trace (for debugging). To see these messages, set loggingLevel to debug or log. Accepted values are: \"off\", \"messages\", \"verbose\". Servers are allowed to ignore this request."
8383
}
8484
},
85+
"jupyter.lab.toolbars": {
86+
"Notebook": [
87+
{
88+
"name": "lsp-status",
89+
"rank": 900
90+
}
91+
]
92+
},
8593
"jupyter.lab.shortcuts": []
8694
}

packages/jupyterlab-lsp/src/components/statusbar.tsx

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,16 @@ export class StatusButtonExtension
481481
/**
482482
* For registration on notebook panels.
483483
*/
484+
createNewToolbarItem(): LSPStatus {
485+
const item = this.createItem(false);
486+
item.addClass('jp-ToolbarButton');
487+
return item;
488+
}
489+
490+
/**
491+
* For registration on notebook panels.
492+
* @deprecated use createNewToolbarItem() instead.
493+
*/
484494
createNew(
485495
panel: NotebookPanel,
486496
context: DocumentRegistry.IContext<INotebookModel>

packages/jupyterlab-lsp/src/index.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import {
1616
JupyterFrontEnd,
1717
JupyterFrontEndPlugin
1818
} from '@jupyterlab/application';
19+
import { IToolbarWidgetRegistry } from '@jupyterlab/apputils';
1920
import { ILoggerRegistry } from '@jupyterlab/logconsole';
2021
import {
2122
ILSPDocumentConnectionManager,
@@ -82,7 +83,8 @@ export class LSPExtension {
8283
public translator: ITranslator,
8384
public userConsole: ILoggerRegistry | null,
8485
statusBar: IStatusBar | null,
85-
formRegistry: IFormRendererRegistry | null
86+
formRegistry: IFormRendererRegistry | null,
87+
toolbarRegistry: IToolbarWidgetRegistry | null
8688
) {
8789
const trans = (translator || nullTranslator).load('jupyterlab_lsp');
8890
this.languageServerManager = connectionManager.languageServerManager;
@@ -102,8 +104,10 @@ export class LSPExtension {
102104
rank: 1,
103105
isActive: () => this._isAnyActive()
104106
});
105-
} else {
106-
app.docRegistry.addWidgetExtension('Notebook', statusButtonExtension);
107+
} else if (toolbarRegistry) {
108+
toolbarRegistry.addFactory('Notebook', 'lsp-status', () =>
109+
statusButtonExtension.createNewToolbarItem()
110+
);
107111
}
108112

109113
this._settingsSchemaManager = new SettingsSchemaManager({
@@ -220,7 +224,12 @@ const plugin: JupyterFrontEndPlugin<void> = {
220224
ILSPLogConsole,
221225
ITranslator
222226
],
223-
optional: [ILoggerRegistry, IStatusBar, IFormRendererRegistry],
227+
optional: [
228+
ILoggerRegistry,
229+
IStatusBar,
230+
IFormRendererRegistry,
231+
IToolbarWidgetRegistry
232+
],
224233
activate: (app, ...args) => {
225234
new LSPExtension(
226235
app,
@@ -231,7 +240,8 @@ const plugin: JupyterFrontEndPlugin<void> = {
231240
ITranslator,
232241
ILoggerRegistry | null,
233242
IStatusBar | null,
234-
IFormRendererRegistry | null
243+
IFormRendererRegistry | null,
244+
IToolbarWidgetRegistry | null
235245
])
236246
);
237247
},

python_packages/jupyter_lsp/jupyter_lsp/tests/test_paths.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,8 @@ def test_normalize_windows_path_case(root_dir, expected_root_uri): # pragma: no
8484
try:
8585
normalized = normalized_uri(root_dir)
8686
except FileNotFoundError as err:
87-
if sys.version_info >= (3, 10):
88-
# apparently, this triggers resolving the path on win/py3.10
87+
if sys.version_info < (3, 12) and root_dir == "//VBOXSVR/shared-folder":
88+
# see https://github.com/python/cpython/issues/136755
8989
return
9090
raise err
9191

0 commit comments

Comments
 (0)