Skip to content

investigate escaping jumping to definition (and other features) with spaces #406

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 15 commits into from
Nov 27, 2020
Merged
Show file tree
Hide file tree
Changes from 13 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,23 @@
## CHANGELOG

### `@krassowski/jupyterlab-lsp 2.0.9` (???)

- bug fixes

- handles characters that need escaping (spaces, non-ASCII characters) more
robustly in files and folder names ([#403])

[#403]: https://github.com/krassowski/jupyterlab-lsp/pulls/403

### `@krassowski/jupyterlab_go_to_definition 2.0.0` (???)

- features

- breaking change: renames `uri` to `contents_path` to help avoid programmer issues
with characters requiring URI encoding ([#406])

[#406]: https://github.com/krassowski/jupyterlab-lsp/pulls/406

### `@krassowski/jupyterlab-lsp 2.0.8` (2020-10-25)

- bug fixes
Expand Down
2 changes: 1 addition & 1 deletion atest/00_Smoke.robot
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
*** Settings ***
Suite Setup Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}smoke
Suite Setup Set Screenshot Directory ${SCREENSHOTS DIR}${/}smoke
Resource Keywords.robot

*** Test Cases ***
Expand Down
25 changes: 1 addition & 24 deletions atest/01_Editor.robot
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
*** Settings ***
Suite Setup Setup Suite For Screenshots editor
Force Tags ui:editor
Force Tags ui:editor aspect:ls:features
Resource Keywords.robot
Resource Variables.robot

Expand Down Expand Up @@ -90,29 +90,6 @@ Editor Should Show Diagnostics
Should Be True ${count} >= 1
Close Diagnostics Panel

Editor Should Jump To Definition
[Arguments] ${symbol}
Set Tags feature:jump-to-definition
${sel} = Set Variable If "${symbol}".startswith(("xpath", "css")) ${symbol} xpath:(//span[@role="presentation"][contains(., "${symbol}")])[last()]
Open Context Menu Over ${sel}
${cursor} = Measure Cursor Position
Capture Page Screenshot 02-jump-to-definition-0.png
Mouse Over ${MENU JUMP}
Capture Page Screenshot 02-jump-to-definition-1.png
Click Element ${MENU JUMP}
Wait Until Keyword Succeeds 10 x 1 s Cursor Should Jump ${cursor}
Capture Page Screenshot 02-jump-to-definition-2.png

Cursor Should Jump
[Arguments] ${original}
${current} = Measure Cursor Position
Should Not Be Equal ${original} ${current}

Measure Cursor Position
Wait Until Page Contains Element ${CM CURSORS}
${position} = Wait Until Keyword Succeeds 20 x 0.05s Get Vertical Position ${CM CURSOR}
[Return] ${position}

Editor Content Changed
[Arguments] ${old_content}
${new_content} Get Editor Content
Expand Down
2 changes: 1 addition & 1 deletion atest/03_Notebook.robot
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ Foreign Extractors
Code Overrides
${file} = Set Variable Code overrides.ipynb
Setup Notebook Python ${file}
${virtual_path} = Set Variable ${OUTPUT DIR}${/}home${/}.virtual_documents/Code\ overrides.ipynb
${virtual_path} = Set Variable ${VIRTUALDOCS DIR}${/}Code overrides.ipynb
Wait Until Created ${virtual_path}
${document} = Get File ${virtual_path}
Should Be Equal ${document} get_ipython().run_line_magic("ls", "")\n\n\nget_ipython().run_line_magic("pip", " freeze")\n
1 change: 1 addition & 0 deletions atest/04_Interface/DiagnosticsPanel.robot
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
*** Settings ***
Suite Setup Setup Suite For Screenshots diagnostics_panel
Resource ../Keywords.robot
Force Tags ui:notebook aspect:ls:features
Test Setup Set Up
Test Teardown Clean Up

Expand Down
25 changes: 25 additions & 0 deletions atest/05_Features/Jump.robot
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
*** Settings ***
Suite Setup Setup Suite For Screenshots gh-403
Force Tags feature:jump-to-definition gh:403
Resource ../Keywords.robot

*** Variables ***
${FOLDER WITH SPACE} a földer

*** Test Cases ***
Python Jumps between Files
Copy Files to Folder With Spaces jump_a.py jump_b.py
${def} = Set Variable a_function_definition
Open ${FOLDER WITH SPACE}/jump_b.py in ${MENU EDITOR}
Wait Until Fully Initialized
${sel} = Set Variable xpath:(//span[contains(@class, 'cm-variable')][contains(text(), '${def}')])[last()]
Jump To Definition ${sel}
Wait Until Page Contains ANOTHER_CONSTANT
Capture Page Screenshot 10-jumped.png

*** Keywords ***
Copy Files to Folder With Spaces
[Arguments] @{files}
FOR ${file} IN @{files}
Copy File examples${/}${file} ${NOTEBOOK DIR}${/}${FOLDER WITH SPACE}${/}${file}
END
4 changes: 2 additions & 2 deletions atest/06_Style.robot
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ Screenshot Editor Themes with Lab Theme
[Arguments] ${lab theme} ${file}=style.py ${notebook}=Diagnostic.ipynb
${norm lab theme} = Set Variable ${lab theme.lower().replace(" ", "-")}
Set Tags theme:lab:${norm lab theme}
Set Screenshot Directory ${OUTPUT DIR}${/}style${/}${norm lab theme}
Copy File examples${/}${file} ${OUTPUT DIR}${/}home${/}${file}
Set Screenshot Directory ${SCREENSHOTS DIR}${/}style${/}${norm lab theme}
Copy File examples${/}${file} ${NOTEBOOK DIR}${/}${file}
Run Keyword If "${THEME NAMES}" == "" Wait Until Keyword Succeeds 3x 1s Get Theme Names
Lab Command Use ${lab theme} Theme
Try to Close All Tabs
Expand Down
128 changes: 88 additions & 40 deletions atest/Keywords.robot
Original file line number Diff line number Diff line change
Expand Up @@ -4,59 +4,67 @@ Library SeleniumLibrary
Library OperatingSystem
Library Process
Library String
Library Collections
Library ./logcheck.py
Library ./ports.py
Library ./config.py

*** Keywords ***
Setup Server and Browser
${port} = Get Unused Port
Set Global Variable ${PORT} ${port}
Set Global Variable ${URL} http://localhost:${PORT}${BASE}
Initialize Global Variables
Create Notebok Server Config
Initialize User Settings
${server} = Start Process jupyter-lab
... cwd=${NOTEBOOK DIR}
... stdout=${LAB LOG}
... stderr=STDOUT
... env:HOME=${HOME}
Set Global Variable ${SERVER} ${server}
Open JupyterLab
Read Page Config

Initialize Global Variables
${root} = Normalize Path ${OUTPUT DIR}${/}..${/}..${/}..
Set Global Variable ${ROOT} ${root}
${accel} = Evaluate "COMMAND" if "${OS}" == "Darwin" else "CTRL"
Set Global Variable ${ACCEL} ${accel}
${token} = Generate Random String
Set Global Variable ${TOKEN} ${token}
${home} = Set Variable ${OUTPUT DIR}${/}home
${root} = Normalize Path ${OUTPUT DIR}${/}..${/}..${/}..
Create Directory ${home}
Create Notebok Server Config ${home}
Initialize User Settings
${cmd} = Create Lab Launch Command ${root}
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots
Set Global Variable ${LAB LOG} ${OUTPUT DIR}${/}lab.log
Set Global Variable ${PREVIOUS LAB LOG LENGTH} 0
${server} = Start Process ${cmd} shell=yes env:HOME=${home} cwd=${home} stdout=${LAB LOG}
... stderr=STDOUT
Set Global Variable ${SERVER} ${server}
Open JupyterLab
Set Screenshot Directory ${SCREENSHOTS DIR}

Create Notebok Server Config
[Documentation] Copies in notebook server config file and updates accordingly
${conf} = Set Variable ${NOTEBOOK DIR}${/}${NBSERVER CONF}
${extra_node_roots} = Create List ${ROOT}
${port} = Get Unused Port
Set Global Variable ${PORT} ${port}
Set Global Variable ${URL} http://localhost:${PORT}${BASE URL}
Copy File ${FIXTURES}${/}${NBSERVER CONF} ${conf}
Update Jupyter Config ${conf} LabApp
... base_url=${BASE URL}
... port=${PORT}
... token=${TOKEN}
... user_settings_dir=${SETTINGS DIR}
... workspaces_dir=${WORKSPACES DIR}
Update Jupyter Config ${conf} LanguageServerManager
... extra_node_roots=@{extra_node_roots}

Read Page Config
${script} = Get Element Attribute id:jupyter-config-data innerHTML
${config} = Evaluate __import__("json").loads("""${script}""")
Set Global Variable ${PAGE CONFIG} ${config}
Set Global Variable ${LAB VERSION} ${config["appVersion"]}

Create Lab Launch Command
[Arguments] ${root}
[Documentation] Create a JupyterLab CLI shell string, escaping for traitlets
${WORKSPACES DIR} = Set Variable ${OUTPUT DIR}${/}workspaces
${app args} = Set Variable --no-browser --debug --NotebookApp.base_url\='${BASE}' --port\=${PORT} --NotebookApp.token\='${TOKEN}'
${path args} = Set Variable --LabApp.user_settings_dir='${SETTINGS DIR.replace('\\', '\\\\')}' --LabApp.workspaces_dir\='${WORKSPACES DIR.replace('\\', '\\\\')}'
${ext args} = Set Variable --LanguageServerManager.extra_node_roots\="['${root.replace('\\', '\\\\')}']"
${cmd} = Set Variable jupyter-lab ${app args} ${path args} ${ext args}
[Return] ${cmd}

Create Notebok Server Config
[Arguments] ${home}
[Documentation] Copies in notebook server config file to disables npm/build checks
Copy File ${FIXTURES}${/}${NBSERVER CONF} ${home}${/}${NBSERVER CONF}

Setup Suite For Screenshots
[Arguments] ${folder}
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}${folder}
Set Screenshot Directory ${SCREENSHOTS DIR}${/}${folder}
Set Tags lab:${LAB VERSION}

Initialize User Settings
Set Suite Variable ${SETTINGS DIR} ${OUTPUT DIR}${/}user-settings children=${True}
Create File ${SETTINGS DIR}${/}@jupyterlab${/}codemirror-extension${/}commands.jupyterlab-settings {"styleActiveLine": true}
Create File
... ${SETTINGS DIR}${/}@jupyterlab${/}codemirror-extension${/}commands.jupyterlab-settings
... {"styleActiveLine": true}

Reset Plugin Settings
[Arguments] ${package}=jupyterlab-lsp ${plugin}=plugin
Expand Down Expand Up @@ -91,7 +99,7 @@ Open JupyterLab
Create WebDriver Firefox
... executable_path=${geckodriver}
... firefox_binary=${firefox}
... service_log_path=${OUTPUT DIR}${/}geckodriver.log
... service_log_path=${GECKODRIVER LOG}
... service_args=${service args}
Wait Until Keyword Succeeds 3x 5s Wait For Splash

Expand Down Expand Up @@ -191,7 +199,7 @@ Ensure Sidebar Is Closed
Open Context Menu for File
[Arguments] ${file}
Ensure File Browser is Open
Click Element css:button[title="Refresh File List"]
Click Element ${JLAB CSS REFRESH FILES}
${selector} = Set Variable xpath://span[@class='jp-DirListing-itemText']\[text() = '${file}']
Wait Until Page Contains Element ${selector}
Open Context Menu ${selector}
Expand All @@ -212,7 +220,19 @@ Input Into Dialog
Input Text ${DIALOG INPUT} ${text}
Click Element ${DIALOG ACCEPT}

Open Folder
[Arguments] @{paths}
Click Element ${JLAB CSS REFRESH FILES}
FOR ${path} IN @{paths}
${sel} = Set Variable css:li.jp-DirListing-item\[title^='Name: ${path}']
Wait Until Page Contains Element ${sel}
Double Click Element ${sel}
END

Open ${file} in ${editor}
${paths} = Set Variable ${file.split("/")}
Run Keyword If ${paths.__len__() > 1} Open Folder @{paths[:-1]}
${file} = Set Variable ${paths[-1]}
Open Context Menu for File ${file}
Mouse Over ${MENU OPEN WITH}
Wait Until Page Contains Element ${editor}
Expand All @@ -221,15 +241,15 @@ Open ${file} in ${editor}

Clean Up After Working With File
[Arguments] ${file}
Remove File ${OUTPUT DIR}${/}home${/}${file}
Remove File ${NOTEBOOK DIR}${/}${file}
Reset Application State
Lab Log Should Not Contain Known Error Messages

Setup Notebook
[Arguments] ${Language} ${file} ${isolated}=${True}
Set Tags language:${Language.lower()}
Run Keyword If ${isolated} Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}notebook${/}${TEST NAME.replace(' ', '_')}
Copy File examples${/}${file} ${OUTPUT DIR}${/}home${/}${file}
Run Keyword If ${isolated} Set Screenshot Directory ${SCREENSHOTS DIR}${/}notebook${/}${TEST NAME.replace(' ', '_')}
Copy File examples${/}${file} ${NOTEBOOK DIR}${/}${file}
Run Keyword If ${isolated} Try to Close All Tabs
Open ${file} in ${MENU NOTEBOOK}
Capture Page Screenshot 00-notebook-opened.png
Expand Down Expand Up @@ -284,13 +304,13 @@ Open Context Menu Over
Prepare File for Editing
[Arguments] ${Language} ${Screenshots} ${file}
Set Tags language:${Language.lower()}
Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}${Screenshots}${/}${Language.lower()}
Set Screenshot Directory ${SCREENSHOTS DIR}${/}${Screenshots}${/}${Language.lower()}
Try to Close All Tabs
Open File ${file}

Open File
[Arguments] ${file}
Copy File examples${/}${file} ${OUTPUT DIR}${/}home${/}${file}
Copy File examples${/}${file} ${NOTEBOOK DIR}${/}${file}
Open ${file} in ${MENU EDITOR}
Capture Page Screenshot 00-opened.png

Expand Down Expand Up @@ -323,3 +343,31 @@ Clean Up After Working with File and Settings
[Arguments] ${file}
Clean Up After Working With File ${file}
Reset Plugin Settings

Jump To Definition
[Arguments] ${symbol}
${sel} = Set Variable If "${symbol}".startswith(("xpath", "css")) ${symbol} xpath:(//span[@role="presentation"][contains(., "${symbol}")])[last()]
Open Context Menu Over ${sel}
${cursor} = Measure Cursor Position
Capture Page Screenshot 02-jump-to-definition-0.png
Mouse Over ${MENU JUMP}
Capture Page Screenshot 02-jump-to-definition-1.png
Click Element ${MENU JUMP}
[Return] ${cursor}

Editor Should Jump To Definition
[Arguments] ${symbol}
Set Tags feature:jump-to-definition
${cursor} = Jump To Definition ${symbol}
Wait Until Keyword Succeeds 10 x 1 s Cursor Should Jump ${cursor}
Capture Page Screenshot 02-jump-to-definition-2.png

Cursor Should Jump
[Arguments] ${original}
${current} = Measure Cursor Position
Should Not Be Equal ${original} ${current}

Measure Cursor Position
Wait Until Page Contains Element ${CM CURSORS}
${position} = Wait Until Keyword Succeeds 20 x 0.05s Get Vertical Position ${CM CURSOR}
[Return] ${position}
17 changes: 14 additions & 3 deletions atest/Variables.robot
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,18 @@
${FIXTURES} ${CURDIR}${/}fixtures
${NBSERVER CONF} jupyter_notebook_config.json
${SPLASH} id:jupyterlab-splash
# to help catch hard-coded paths
${BASE} /@est/
# to help catch hard-coded paths and encoding issues
${BASE URL} /@est/
${NOTEBOOK DIR NAME} nöte bòóks
# core paths
${HOME} ${OUTPUT DIR}${/}home
${LAB LOG} ${OUTPUT DIR}${/}lab.log
${GECKODRIVER LOG} ${OUTPUT DIR}${/}geckodriver.log
${SETTINGS DIR} ${OUTPUT DIR}${/}user-settings
${WORKSPACES DIR} ${OUTPUT DIR}${/}workspaces
${NOTEBOOK DIR} ${HOME}${/}${NOTEBOOK DIR NAME}
${VIRTUALDOCS DIR} ${NOTEBOOK DIR}${/}.virtual_documents
${SCREENSHOTS DIR} ${OUTPUT DIR}${/}screenshots
# override with `python scripts/atest.py --variable HEADLESS:0`
${HEADLESS} 1
${CMD PALETTE INPUT} css:#command-palette .lm-CommandPalette-input
Expand All @@ -13,6 +23,7 @@ ${JLAB XP MENU ITEM LABEL} //div[@class='lm-Menu-itemLabel']
${JLAB XP MENU LABEL} //div[@class='lm-MenuBar-itemLabel']
${JLAB XP DOCK TAB} xpath://div[contains(@class, 'lm-DockPanel-tabBar')]//li[contains(@class, 'lm-TabBar-tab')]
${JLAB CSS VERSION} css:.jp-About-version
${JLAB CSS REFRESH FILES} css:button[title="Refresh File List"]
${CSS DIALOG OK} css:.jp-Dialog .jp-mod-accept
${MENU OPEN WITH} xpath://div[contains(@class, 'lm-Menu-itemLabel')][contains(text(), "Open With")]
# R is missing on purpose (may need to use .)
Expand All @@ -30,7 +41,7 @@ ${MENU JUMP} xpath://div[contains(@class, 'lm-Menu-itemLabel')][contains(te
${MENU SETTINGS} xpath://div[contains(@class, 'lm-MenuBar-itemLabel')][contains(text(), "Settings")]
${MENU EDITOR THEME} xpath://div[contains(@class, 'lm-Menu-itemLabel')][contains(text(), "Text Editor Theme")]
${CM CURSOR} css:.CodeMirror-cursor
${CM CURSORS} css:.CodeMirror-cursors:not([style='visibility: hidden'])
${CM CURSORS} css:.jp-MainAreaWidget:not(.lm-mod-hidden) .CodeMirror-cursors:not([style='visibility: hidden'])
# settings
${LSP PLUGIN ID} @krassowski/jupyterlab-lsp:plugin
${COMPLETION PLUGIN ID} @krassowski/jupyterlab-lsp:completion
Expand Down
17 changes: 17 additions & 0 deletions atest/config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
"""work with jupyter config"""

import json
from pathlib import Path

ENC = dict(encoding="utf-8")


def update_jupyter_config(path, has_traits, **key_values):
"""update an existing jupyter_notebook_config.json"""
p = Path(path)
conf = json.loads(p.read_text(**ENC))

for key, value in key_values.items():
conf.setdefault(has_traits, {})[key] = value

p.write_text(json.dumps(conf, indent=2, sort_keys=True), **ENC)
5 changes: 5 additions & 0 deletions atest/examples/jump_a.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
A_CONSTANT = "constant"
ANOTHER_CONSTANT = "another constant"

def a_function_definition(n: int=1) -> str:
return A_CONSTANT * n
4 changes: 4 additions & 0 deletions atest/examples/jump_b.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
from jump_a import a_function_definition, A_CONSTANT


assert a_function_definition() == A_CONSTANT
Loading