Skip to content

Commit

Permalink
Merge branch 'master' into jupyter-lspgh-299-no-throw
Browse files Browse the repository at this point in the history
  • Loading branch information
krassowski authored Jul 28, 2020
2 parents 2b8f8b0 + acf17ab commit cd8783f
Show file tree
Hide file tree
Showing 28 changed files with 334 additions and 47 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,14 @@
[#299]: https://github.com/krassowski/jupyterlab-lsp/pull/299
[#300]: https://github.com/krassowski/jupyterlab-lsp/pull/300

### `jupyter-lsp 0.9.x` (unreleased)

- autodetects the `texlab` language server for `.tex` files ([#288][])
- diagnostics _should_ be provided by `chktex` on save, but don't yet appear,
but can be configured through the Advanced Settings Editor to appear on save or change

[#288]: https://github.com/krassowski/jupyterlab-lsp/issues/288

### `@krassowski/jupyterlab-lsp 1.1.0` (2020-07-20)

- features
Expand Down
6 changes: 6 additions & 0 deletions atest/01_Editor.robot
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ JSX
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), 'hello')])[last()]
Editor Shows Features for Language JSX example.jsx Diagnostics=Expression expected Jump to Definition=${def} Rename=${def}

LaTeX
[Tags] language:latex
${def} = Set Variable xpath:(//span[contains(@class, 'cm-atom')][contains(text(), 'foo')])[last()]
Editor Shows Features for Language LaTeX example.tex Jump to Definition=${def} Rename=${def}

Less
${def} = Set Variable xpath:(//span[contains(@class, 'cm-variable-2')][contains(text(), '@width')])[last()]
Editor Shows Features for Language Less example.less Diagnostics=Do not use empty rulesets Jump to Definition=${def}
Expand Down Expand Up @@ -62,6 +67,7 @@ YAML
Editor Shows Features for Language
[Arguments] ${Language} ${file} &{features}
Prepare File for Editing ${Language} editor ${file}
Wait Until Fully Initialized
FOR ${f} IN @{features}
Run Keyword If "${f}" == "Diagnostics" Editor Should Show Diagnostics ${features["${f}"]}
... ELSE IF "${f}" == "Jump to Definition" Editor Should Jump To Definition ${features["${f}"]}
Expand Down
28 changes: 18 additions & 10 deletions atest/03_Notebook.robot
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,27 @@ Resource Keywords.robot

*** Test Cases ***
Python
Setup Notebook Python Python.ipynb
Capture Page Screenshot 01-python.png
[Setup] Setup Notebook Python Python.ipynb
${diagnostic} = Set Variable W291 trailing whitespace (pycodestyle)
Wait Until Page Contains Element css:.cm-lsp-diagnostic[title="${diagnostic}"] timeout=35s
Capture Page Screenshot 02-python.png
Clean Up After Working With File Python.ipynb
Capture Page Screenshot 01-python.png
[Teardown] Clean Up After Working With File Python.ipynb

Foregin Extractors
Setup Notebook Python Foreign extractors.ipynb
# if mypy and pyflakes will fight over `(N|n)ame 'valid'`, just hope for the best
@{diagnostics} = Create List Failed to parse expression ame 'valid' Trailing whitespace is superfluous.
Foreign Extractors
${file} = Set Variable Foreign extractors.ipynb
Configure JupyterLab Plugin
... {"language_servers": {"texlab": {"serverSettings": {"latex.lint.onChange": true}}}}
Capture Page Screenshot 10-configured.png
Reset Application State
Setup Notebook Python ${file}
@{diagnostics} = Create List
... Failed to parse expression # bash
... ame 'valid' # python, mypy and pyflakes will fight over `(N|n)ame 'valid'`, just hope for the best
... Trailing whitespace is superfluous. # r
... `frob` is misspelt # markdown
... Command terminated with space # latex
FOR ${diagnostic} IN @{diagnostics}
Wait Until Page Contains Element css:.cm-lsp-diagnostic[title*\="${diagnostic}"] timeout=35s
Capture Page Screenshot 0x-${diagnostic}.png
END
Clean Up After Working With File Foreign Extractors.ipynb
Capture Page Screenshot 11-extracted.png
[Teardown] Clean Up After Working with File and Settings ${file}
43 changes: 31 additions & 12 deletions atest/07_Configuration.robot
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ Python

YAML
[Documentation] EXPECT FAIL Composer YAML files don't allow a "greetings" key
[Tags] expect:fail
Settings Should Change Editor Diagnostics YAML example.yaml yaml-language-server
... {"yaml.schemas": {"http://json.schemastore.org/composer": "*"}}
... duplicate key
Expand All @@ -26,37 +27,55 @@ Markdown
... `Color` is misspelt
... `Colour` is misspelt

*** Keywords ***
Clean Up After Working with File and Settings
[Arguments] ${file}
Clean Up After Working With File ${file}
Reset Plugin Settings
LaTeX
[Documentation] diagnostics only appear if configured
[Tags] language:latex
${needs reload} = Set Variable "${OS}" == "Windows"
Settings Should Change Editor Diagnostics LaTeX example.tex texlab
... {"latex.lint.onChange": true}
... ${EMPTY}
... Command terminated with space. (chktex)
... Save File
... ${needs reload}

*** Keywords ***
Settings Should Change Editor Diagnostics
[Arguments] ${language} ${file} ${server} ${settings} ${before} ${after}
[Arguments] ${language} ${file} ${server} ${settings} ${before} ${after} ${save command}=${EMPTY} ${needs reload}=${False}
${before diagnostic} = Set Variable ${CSS DIAGNOSTIC}\[title^="${before}"]
${after diagnostic} = Set Variable ${CSS DIAGNOSTIC}\[title^="${after}"]
${tab} = Set Variable ${JLAB XP DOCK TAB}\[contains(., '${file}')]
${close icon} = Set Variable *[contains(@class, 'm-TabBar-tabCloseIcon')]
${save command} = Set Variable If "${save command}" ${save command} Save ${language} File
Prepare File for Editing ${language} config ${file}
Open in Advanced Settings ${LSP PLUGIN ID}
Drag and Drop By Offset ${tab} 0 100
Wait Until Fully Initialized
Open Diagnostics Panel
Drag and Drop By Offset ${JLAB XP DOCK TAB}\[contains(., 'Diagnostics Panel')] 600 -200
Click Element ${JLAB XP DOCK TAB}\[contains(., 'Launcher')]/${close icon}
Wait Until Page Contains Element ${before diagnostic} timeout=30s
Run Keyword If "${before}" Wait Until Page Contains Element ${before diagnostic} timeout=30s
Page Should Not Contain ${after diagnostic}
Capture Page Screenshot 01-default-diagnostics-and-settings.png
Set Editor Content {"language_servers": {"${server}": {"serverSettings": ${settings}}}} ${CSS USER SETTINGS}
Wait Until Page Contains No errors found
Capture Page Screenshot 01-default-diagnostics-and-settings.png
Capture Page Screenshot 02-default-diagnostics-and-unsaved-settings.png
Click Element css:button[title\='Save User Settings']
Click Element ${JLAB XP DOCK TAB}\[contains(., 'Settings')]/${close icon}
Click Element ${JLAB XP CLOSE SETTINGS}
Drag and Drop By Offset ${tab} 0 100
Lab Command Save ${language} File
Lab Command ${save command}
Ensure Sidebar Is Closed
Capture Page Screenshot 02-settings-changed.png
Capture Page Screenshot 03-settings-changed.png
Run Keyword If ${needs reload} Reload After Configuration ${language} ${file}
Wait Until Page Contains Element ${after diagnostic} timeout=30s
Capture Page Screenshot 03-configured-diagnostic-found.png
Capture Page Screenshot 04-configured-diagnostic-found.png
[Teardown] Clean Up After Working with File and Settings ${file}

Reload After Configuration
[Arguments] ${language} ${file}
Reload Page
Wait Until Keyword Succeeds 3x 5s Wait For Splash
Reset Application State
Prepare File for Editing ${language} config ${file}
Wait Until Fully Initialized
Open Diagnostics Panel
Ensure Sidebar Is Closed
13 changes: 13 additions & 0 deletions atest/Keywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,16 @@ Get Editor Content
[Arguments] ${css}=${EMPTY}
${content} = Execute JavaScript return document.querySelector('${css} .CodeMirror').CodeMirror.getValue()
[Return] ${content}

Configure JupyterLab Plugin
[Arguments] ${settings json} ${plugin id}=${LSP PLUGIN ID}
Open in Advanced Settings ${plugin id}
Set Editor Content ${settings json} ${CSS USER SETTINGS}
Wait Until Page Contains No errors found
Click Element css:button[title\='Save User Settings']
Click Element ${JLAB XP CLOSE SETTINGS}

Clean Up After Working with File and Settings
[Arguments] ${file}
Clean Up After Working With File ${file}
Reset Plugin Settings
1 change: 1 addition & 0 deletions atest/Variables.robot
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ ${CM CURSORS} css:.CodeMirror-cursors:not([style='visibility: hidden'])
${LSP PLUGIN ID} @krassowski/jupyterlab-lsp:plugin
${LSP PLUGIN SETTINGS FILE} @krassowski${/}jupyterlab-lsp${/}plugin.jupyterlab-settings
${CSS USER SETTINGS} .jp-SettingsRawEditor-user
${JLAB XP CLOSE SETTINGS} ${JLAB XP DOCK TAB}\[contains(., 'Settings')]/*[contains(@class, 'm-TabBar-tabCloseIcon')]
# diagnostics
${CSS DIAGNOSTIC} css:.cm-lsp-diagnostic
# log messages
Expand Down
37 changes: 36 additions & 1 deletion atest/examples/Foreign extractors.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,41 @@
"%%bash\n",
"echo $"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### $\\LaTeX$"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%latex\n",
"\n",
"\\foo bar"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Markdown"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": [
"%%markdown\n",
"frob"
]
}
],
"metadata": {
Expand All @@ -84,7 +119,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.0"
"version": "3.7.6"
}
},
"nbformat": 4,
Expand Down
7 changes: 7 additions & 0 deletions atest/examples/example.tex
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
\documentclass{article}

\begin{document}
\foo this is an error
\label{foo}
\ref{foo}
\end{document}
4 changes: 4 additions & 0 deletions binder/environment.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,7 @@ dependencies:
- r-irkernel
- r-languageserver
- rpy2
# for tex
- tectonic
- texlab
- chktex
4 changes: 4 additions & 0 deletions ci/env-test.yml.in
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,10 @@ dependencies:
- r-languageserver
- r-stringi >=1.4.6
- rpy2
# tex
- tectonic
- texlab
- chktex
# test tools
- pytest-asyncio
- pytest-azurepipelines
Expand Down
5 changes: 4 additions & 1 deletion ci/job.test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,9 @@ jobs:
- script: ${{ platform.activate }} && python scripts/jedi_cache.py
displayName: warm up jedi cache

- script: ${{ platform.activate }} && python scripts/tectonic_cache.py
displayName: warm up tectonic cache

- script: ${{ platform.activate }} && jlpm test
displayName: run frontend unit tests

Expand Down Expand Up @@ -109,7 +112,7 @@ jobs:
- script: ${{ platform.activate }} && jupyter labextension list
displayName: list labextensions after build

- script: ${{ platform.activate }} && python scripts/atest.py
- script: ${{ platform.activate }} && python scripts/atest.py --exclude expect:fail
displayName: run browser tests

- task: PublishTestResults@2
Expand Down
8 changes: 5 additions & 3 deletions docs/Installation.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
"#### conda (minimal python)\n",
"\n",
"```bash\n",
"conda create -c conda-forge -n lsp 'python >=3.7,<3.8' 'jupyterlab={JUPYTERLAB_VERSION}' 'nodejs>8' python-language-server\n",
"conda create -c conda-forge -n lsp 'python >=3.7,<3.8' 'jupyterlab={JUPYTERLAB_VERSION}' 'nodejs>10' python-language-server\n",
"# Also consider: r-languageserver [*]\n",
"source activate lsp\n",
"python -m pip install 'jupyter-lsp={JUPYTER_LSP_VERSION}' --no-deps\n",
Expand Down Expand Up @@ -137,13 +137,15 @@
"##### `Dockerfile`\n",
"\n",
"```dockerfile\n",
"# This already contains the python, r, julia, and nodejs runtimes\n",
"# This already contains the python, r, julia, latex, and nodejs runtimes\n",
"FROM jupyter/datascience-notebook@sha256:73a577b006b496e1a1c02f5be432f4aab969c456881c4789e0df77c89a0a60c2\n",
"\n",
"RUN conda install --quiet --yes --freeze-installed \\\n",
"RUN conda install --quiet --yes --freeze-installed -c conda-forge \\\n",
" 'python-language-server' \\\n",
" 'jupyterlab={JUPYTERLAB_VERSION}' \\\n",
" 'r-languageserver' \\\n",
" 'texlab' \\\n",
" 'chktex' \\\n",
" && python3 -m pip install --no-cache-dir --no-deps \\\n",
" 'jupyter-lsp={JUPYTER_LSP_VERSION}' \\\n",
" && jupyter labextension install --no-build \\\n",
Expand Down
42 changes: 42 additions & 0 deletions docs/Language Servers.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,48 @@
"install them with [extra_node_roots](./Configuring.ipynb#extra_node_roots)."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Other Scientific Languages\n",
"\n",
"These servers have been mostly tested with file editor."
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {
"hide_input": true
},
"outputs": [],
"source": [
"sci_langs = [\"texlab\"]\n",
"lang_server_table(\n",
" {key: spec for key, spec in mgr.language_servers.items() if key in sci_langs}\n",
")"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"#### Example: Getting a $\\LaTeX$ stack\n",
"\n",
"```bash\n",
"conda install -y conda-forge tectonic texlab chktex\n",
"```\n",
"\n",
"This will install:\n",
"\n",
"- `tectonic`, a cross-platform $\\LaTeX$ processing tool\n",
" - note, it will download a large number of packages when first executed\n",
"- `texlab`, a Language Server for `.tex` files that supports completion and\n",
" refernce navigation\n",
"- `chktex`, a `.tex` style checker"
]
},
{
"cell_type": "code",
"execution_count": null,
Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@
"lab:link": "lerna run lab:link",
"lint:check": "jlpm prettier:check && jlpm eslint:check",
"lint": "jlpm prettier && jlpm eslint",
"prettier:check": "prettier --check '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md,.yml}'",
"prettier": "prettier --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md,.yml}'",
"prettier:check": "prettier --check \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md,.yml}\"",
"prettier": "prettier --write \"**/*{.ts,.tsx,.js,.jsx,.css,.json,.md,.yml}\"",
"eslint": "eslint --config packages/.eslintrc.js --ext .js,.jsx,.ts,.tsx --fix packages",
"eslint:check": "eslint --config packages/.eslintrc.js --ext .js,.jsx,.ts,.tsx packages",
"test": "lerna run --stream --concurrency=1 test"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { Menu } from '@lumino/widgets';
import { PositionConverter } from '../../../converter';
import { IVirtualPosition, IEditorPosition } from '../../../positioning';
import { diagnosticSeverityNames } from '../../../lsp';
import { DefaultMap } from '../../../utils';
import { DefaultMap, uris_equal } from '../../../utils';
import { CodeMirrorLSPFeature, IFeatureCommand } from '../feature';
import { MainAreaWidget } from '@jupyterlab/apputils';
import {
Expand Down Expand Up @@ -217,7 +217,7 @@ export class Diagnostics extends CodeMirrorLSPFeature {
}

public handleDiagnostic = (response: lsProtocol.PublishDiagnosticsParams) => {
if (response.uri !== this.virtual_document.document_info.uri) {
if (!uris_equal(response.uri, this.virtual_document.document_info.uri)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { documentHighlightKindNames } from '../../../lsp';
import { VirtualDocument } from '../../../virtual/document';
import { IRootPosition } from '../../../positioning';
import { CodeMirrorLSPFeature, IFeatureCommand } from '../feature';
import { uris_equal } from '../../../utils';

export class Highlights extends CodeMirrorLSPFeature {
name = 'Highlights';
Expand Down Expand Up @@ -49,7 +50,7 @@ export class Highlights extends CodeMirrorLSPFeature {
items: lsProtocol.DocumentHighlight[],
documentUri: string
) => {
if (documentUri !== this.virtual_document.document_info.uri) {
if (!uris_equal(documentUri, this.virtual_document.document_info.uri)) {
return;
}
this.clear_markers();
Expand Down
Loading

0 comments on commit cd8783f

Please sign in to comment.