Skip to content
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

💭 streamline server starting, binder, architectural musings #22

Merged
merged 5 commits into from
Sep 15, 2019
Merged
Show file tree
Hide file tree
Changes from all 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
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ celerybeat-schedule
.env
.venv
env/
envs/
venv/
ENV/
env.bak/
Expand All @@ -102,3 +103,5 @@ venv.bak/

# mypy
.mypy_cache/

node_modules
24 changes: 24 additions & 0 deletions .prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
node_modules
**/node_modules
**/lib
**/build
**/static
jupyterlab/schemas
jupyterlab/themes
jupyterlab/geckodriver
jupyterlab/staging/yarn.js
jupyterlab/staging/index.js
dev_mode/index.js
dev_mode/schemas
dev_mode/static
dev_mode/themes
dev_mode/workspaces
examples/app/build
examples/app/themes
examples/app/schemas
tests/**/coverage
docs/_build
docs/api
**/package.json
.eggs
envs
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
language: node_js
node_js:
- "11"
- '11'
before_install:
- npm i -g [email protected]
install:
Expand Down
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Language Server Protocol integration for JupyterLab

[![Build Status](https://travis-ci.org/krassowski/jupyterlab-lsp.svg?branch=master)](https://travis-ci.org/krassowski/jupyterlab-lsp) [![codebeat badge](https://codebeat.co/badges/f55d0f28-8a84-4199-bc88-f2c306a9ce65)](https://codebeat.co/projects/github-com-krassowski-jupyterlab-lsp-master)

<!--[![Binder](https://beta.mybinder.org/badge.svg)](https://mybinder.org/v2/gh/krassowski/jupyterlab-lsp/master?urlpath=lab/tree/examples/demo.ipynb)-->

_This extension is in its early days, but you are welcome to check it out, leave feedback and/or a PR_
Expand Down Expand Up @@ -51,7 +52,7 @@ New in 0.5.0:
- system of settings, including options:
- to enable aggressive autocompletion (like in hinterland)
- to change the verbosity of signature hints (whether to show documentation, number of lines to be shown)

### Planned:

- "rename" action (PR welcome, but please mind issue #23)
Expand All @@ -66,7 +67,7 @@ If a feature you need is not on the lists above, please feel free to suggest it
#### Hints

- just like in old notebooks, you can still use the built-in <kbd>Shift</kbd> + <kbd>Tab</kbd> to get a signature in JupyterLab.
This extension behaves well with this feature.
This extension behaves well with this feature.

## Under the hood

Expand Down
20 changes: 20 additions & 0 deletions binder/environment.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: jupyterlab-lsp

channels:
- conda-forge
- defaults

dependencies:
- black
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

black and isort are not use at this time, but will come in handy soon (this is the plan ;)) so we can keep those here.

- isort
- jupyter-server-proxy
- jupyterlab >=1.1,<1.2
- mypy
- nodejs
- pip
- python >=3.7,<3.8.0a0
- python-language-server
- pip:
- pyls-black
- pyls-isort
- pyls-mypy
15 changes: 15 additions & 0 deletions binder/jupyter_notebook_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path
from jupyterlab.commands import get_app_dir

# TODO: also check env_vars, previous config, or just on path
node_modules = Path(get_app_dir()) / "staging" / "node_modules"
proxy = node_modules / "jsonrpc-ws-proxy" / "dist" / "server.js"
servers_yml = Path(__file__).parent / "servers.yml"


c.ServerProxy.servers = {
"lsp": {
"command": [str(proxy), "--port", "{port}", "--languageServers", str(servers_yml)],
"absolute_url": False
}
}
3 changes: 3 additions & 0 deletions binder/postBuild
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/usr/bin/env bash
jlpm bootstrap
jupyter labextension install . @krassowski/jupyterlab_go_to_definition
3 changes: 3 additions & 0 deletions binder/servers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
langservers:
python:
- pyls
15 changes: 15 additions & 0 deletions jupyter_notebook_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
from pathlib import Path
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does this file need to be in root and in binder?

from jupyterlab.commands import get_app_dir

# TODO: also check env_vars, previous config, or just on path
node_modules = Path(get_app_dir()) / "staging" / "node_modules"
proxy = node_modules / "jsonrpc-ws-proxy" / "dist" / "server.js"
servers_yml = Path(__file__).parent / "servers.yml"


c.ServerProxy.servers = {
"lsp": {
"command": [str(proxy), "--port", "{port}", "--languageServers", str(servers_yml)],
"absolute_url": False
}
}
73 changes: 45 additions & 28 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@
"license": "BSD-3-Clause",
"author": "Michał Krassowski",
"files": [
"lib/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf}",
"style/**/*.{css,eot,gif,html,jpg,json,png,svg,woff2,ttf}",
"schema/*.json"
"{lib,style,schema}/**/*.{d.ts,eot,gif,html,jpg,js,js.map,json,png,svg,woff2,ttf,css}"
],
"main": "lib/index.js",
"types": "lib/index.d.ts",
Expand All @@ -31,40 +29,23 @@
},
"scripts": {
"build": "tsc",
"bootstrap": "jlpm && jlpm build",
"clean": "rimraf lib",
"prepare": "npm run clean && npm run build",
"watch": "tsc -w",
"lint": "npm run prettier && npm run tslint",
"lint:check": "npm run prettier:check && npm run tslint:check",
"prettier": "prettier --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",
"prettier:check": "prettier --list-different '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md}'",
"lint": "jlpm prettier && jlpm tslint",
"lint:check": "jlpm prettier:check && jlpm tslint:check",
"prettier": "prettier --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md,.yml}'",
"prettier:check": "prettier --list-different '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md,.yml}'",
"tslint": "tslint --fix -c tslint.json --project tsconfig.json '**/*{.ts,.tsx}'",
"tslint:check": "tslint -c tslint.json --project tsconfig.json '**/*{.ts,.tsx}'",
"test": "npx jest"
},
"dependencies": {
"@jupyterlab/application": "^1.0.9",
"@jupyterlab/apputils": "^1.0.9",
"@jupyterlab/cells": "^1.0.9",
"@jupyterlab/codeeditor": "^1.0.9",
"@jupyterlab/codemirror": "^1.0.9",
"@jupyterlab/completer": "^1.0.9",
"@jupyterlab/coreutils": "^3.0.0",
"@jupyterlab/docmanager": "^1.0.9",
"@jupyterlab/docregistry": "^1.0.9",
"@jupyterlab/fileeditor": "^1.0.9",
"@jupyterlab/notebook": "^1.0.9",
"@jupyterlab/rendermime": "^1.0.9",
"@jupyterlab/services": "^4.0.0",
"@jupyterlab/tooltip": "^1.0.9",
"@krassowski/jupyterlab_go_to_definition": "^0.7.1",
"@phosphor/algorithm": "^1.1.2",
"@types/events": "^3.0.0",
"codemirror": "^5.47.0",
"events": "^3.0.0",
"jsonrpc-ws-proxy": "0.0.5",
"lsp-editor-adapter": "0.0.10",
"react": "^16.8.4"
"lsp-editor-adapter": "0.0.10"
},
"devDependencies": {
"@babel/preset-env": "^7.4.3",
Expand All @@ -75,12 +56,48 @@
"chai": "^4.2.0",
"jest": "^24.7.1",
"prettier": "^1.18.2",
"rimraf": "^2.6.1",
"rimraf": "~2.6.2",
"typescript": "~3.5.1",
"ts-jest": "^24.0.2",
"tslint": "^5.19.0",
"tslint-config-prettier": "^1.18.0",
"tslint-plugin-prettier": "^2.0.1",
"typescript": "~3.4.5"
"@jupyterlab/application": "^1.1.0",
"@jupyterlab/apputils": "^1.1.0",
"@jupyterlab/cells": "^1.1.0",
"@jupyterlab/codeeditor": "^1.1.0",
"@jupyterlab/codemirror": "^1.1.0",
"@jupyterlab/completer": "^1.1.0",
"@jupyterlab/coreutils": "^3.0.0",
"@jupyterlab/docmanager": "^1.1.0",
"@jupyterlab/docregistry": "^1.1.0",
"@jupyterlab/fileeditor": "^1.1.0",
"@jupyterlab/notebook": "^1.1.0",
"@jupyterlab/rendermime": "^1.1.0",
"@jupyterlab/services": "^4.1.0",
"@jupyterlab/tooltip": "^1.1.0",
"@phosphor/algorithm": "^1.1.3",
"codemirror": "*",
"react": "*"
},
"peerDependencies": {
"@jupyterlab/application": "^1.1.0",
"@jupyterlab/apputils": "^1.1.0",
"@jupyterlab/cells": "^1.1.0",
"@jupyterlab/codeeditor": "^1.1.0",
"@jupyterlab/codemirror": "^1.1.0",
"@jupyterlab/completer": "^1.1.0",
"@jupyterlab/coreutils": "^3.0.0",
"@jupyterlab/docmanager": "^1.1.0",
"@jupyterlab/docregistry": "^1.1.0",
"@jupyterlab/fileeditor": "^1.1.0",
"@jupyterlab/notebook": "^1.1.0",
"@jupyterlab/rendermime": "^1.1.0",
"@jupyterlab/services": "^4.1.0",
"@jupyterlab/tooltip": "^1.1.0",
"@phosphor/algorithm": "^1.1.3",
"codemirror": "*",
"react": "*"
},
"jupyterlab": {
"extension": true,
Expand Down
5 changes: 5 additions & 0 deletions schema/plugin.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"title": "Language Server Protocol",
"description": "Language Server Protocol settings.",
"type": "object"
}
3 changes: 3 additions & 0 deletions servers.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
langservers:
python:
- pyls
2 changes: 2 additions & 0 deletions src/adapters/codemirror.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,5 +84,7 @@ describe('CodeMirrorAdapterExtension', () => {
let marks = ce_editor.editor.getDoc().getAllMarks();
expect(marks.length).to.equal(1);
});

it('updates on change', () => {});
});
});
10 changes: 7 additions & 3 deletions src/adapters/jupyterlab.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { PathExt } from '@jupyterlab/coreutils';
import { PathExt, PageConfig } from '@jupyterlab/coreutils';
import { CodeMirror, CodeMirrorAdapterExtension } from './codemirror';
import { JupyterFrontEnd } from '@jupyterlab/application';
import { CodeJumper } from '@krassowski/jupyterlab_go_to_definition/lib/jumpers/jumper';
Expand Down Expand Up @@ -260,10 +260,14 @@ export abstract class JupyterLabWidgetAdapter {
console.log(
`LSP: will connect using root path: ${this.root_path} and language: ${language}`
);
let socket = new WebSocket('ws://localhost:3000/' + language);

// capture just the s?://*
const wsBase = PageConfig.getBaseUrl().replace(/^http/, '');
const wsUrl = `ws${wsBase}lsp/${language}`;
let socket = new WebSocket(wsUrl);

let connection = new LSPConnection({
serverUri: 'ws://localhost/' + language,
serverUri: 'ws://jupyter-lsp/' + language,
languageId: language,
// paths handling needs testing on Windows and with other language servers
rootUri: 'file:///' + this.root_path,
Expand Down
11 changes: 9 additions & 2 deletions src/virtual/document.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,18 @@
import { IForeignCodeExtractor, IForeignCodeExtractorsRegistry } from '../extractors/types';
import {
IForeignCodeExtractor,
IForeignCodeExtractorsRegistry
} from '../extractors/types';
import { CellMagicsMap, LineMagicsMap } from '../magics/maps';
import { IOverridesRegistry } from '../magics/overrides';
import { DefaultMap } from '../utils';
import { Signal } from '@phosphor/signaling';
import { CodeEditor } from '@jupyterlab/codeeditor';
import { CodeMirror } from '../adapters/codemirror';
import { IEditorPosition, ISourcePosition, IVirtualPosition } from '../positioning';
import {
IEditorPosition,
ISourcePosition,
IVirtualPosition
} from '../positioning';
import IRange = CodeEditor.IRange;

type language = string;
Expand Down
4 changes: 3 additions & 1 deletion src/virtual/editors/notebook.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ class DocDispatcher implements CodeMirror.Doc {
options?: CodeMirror.TextMarkerOptions
): CodeMirror.TextMarker {
// TODO: edgecase: from and to in different cells
let editor = this.virtual_editor.virtual_document.get_editor_at_source_line(from);
let editor = this.virtual_editor.virtual_document.get_editor_at_source_line(
from
);
let notebook_map = this.virtual_editor;
return editor
.getDoc()
Expand Down
Loading