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

Add lsp-ws-connection to repo #107

Merged
1 change: 1 addition & 0 deletions .gitignore
Expand Up @@ -112,3 +112,4 @@ node_modules
atest/output/
junit.xml
coverage/
.vscode/
3 changes: 3 additions & 0 deletions .travis.yml
Expand Up @@ -26,6 +26,9 @@ install:
- python3 -m pip install dist/jupyter_lsp*.whl --no-deps -vv
- jlpm

before_script:
- jlpm build

script:
- jlpm test
- python3 -m jupyter serverextension list
Expand Down
11 changes: 11 additions & 0 deletions CHANGELOG.md
@@ -1,5 +1,16 @@
# CHANGELOG

## `lsp-ws-connection` (unreleased)

- infrastructure
- brought into monorepo
- dev
- allows `initializeParams` to be overloaded by subclasses
- adopts
- typescript 3.7
- prettier
- tslint

## `jupyter-lsp` (unreleased)

- features
Expand Down
16 changes: 14 additions & 2 deletions CONTRIBUTING.md
Expand Up @@ -41,6 +41,18 @@ pip install -r requirements-dev.txt # in a virtualenv, probably
# ... and install nodejs, somehow
```

### The Easy Way

Once your environment is created and activated, on Linux/OSX you can run:

```bash
bash postBuild
```

This performs all of the basic setup steps, and is used for the binder demo.

### The Hard Way

Install `jupyter-lsp` from source in your virtual environment:

```bash
Expand Down Expand Up @@ -74,7 +86,7 @@ jupyter lab build
To watch the files and build continuously:

```bash
jlpm build --watch # leave this running...
jlpm watch # leave this running...
jupyter lab --watch # ...in another terminal
```

Expand All @@ -84,7 +96,7 @@ To check and fix code style:
jlpm lint
```

To run test the suite:
To run test the suite (after running `jlpm build` or `watch`):

```bash
jlpm test
Expand Down
2 changes: 1 addition & 1 deletion LICENSE
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2018,
Copyright (c) 2019, jupyter-lsp contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
18 changes: 9 additions & 9 deletions atest/00_Smoke.robot
Expand Up @@ -2,14 +2,14 @@
Suite Setup Set Screenshot Directory ${OUTPUT DIR}${/}screenshots${/}smoke
Resource Keywords.robot

*** Variables ***
${CSS CLOSE} css:.jp-Dialog-button.jp-About-button

*** Test Cases ***
Lab Version
Open With JupyterLab Menu Help About JupyterLab
Wait Until Page Contains Element ${JLAB CSS VERSION}
${version} = Get WebElement ${JLAB CSS VERSION}
Set Global Variable ${LAB VERSION} ${version.text.split(" ")[-1]}
Capture Page Screenshot 00-version.png
Click Element ${CSS CLOSE}
Capture Page Screenshot 00-smoke.png
${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"]}

Root URI
[Documentation] the rootUri should be set in the page config
Should Not Be Empty ${PAGE CONFIG["rootUri"]}
22 changes: 17 additions & 5 deletions package.json
Expand Up @@ -2,7 +2,6 @@
"dependencies": {
},
"devDependencies": {
"@types/mocha": "^5.2.6",
"bash-language-server": "^1.6.1",
"dockerfile-language-server-nodejs": "^0.0.21",
"eslint": "^5.16.0",
Expand Down Expand Up @@ -32,21 +31,34 @@
"private": true,
"scripts": {
"bootstrap": "jlpm --no-optional --prefer-offline && lerna bootstrap && jlpm lint && jlpm clean && jlpm build",
"build": "cd packages/metapackage && jlpm build",
"bundle": "lerna run bundle",
"clean": "lerna run clean",
"build": "jlpm build:meta && jlpm build:ws",
"build:meta": "lerna run build --stream --scope @krassowski/jupyterlab-lsp-metapackage",
"build:ws": "lerna run build --stream --scope lsp-ws-connection",
"watch": "lerna run --parallel watch",
"bundle": "lerna run --parallel bundle",
"clean": "lerna run --parallel clean",
"lab:link": "lerna run lab:link",
"lint:check": "jlpm prettier:check && jlpm tslint:check",
"lint": "jlpm prettier && jlpm tslint",
"prettier:check": "prettier --check '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md,.yml}'",
"test": "lerna run --stream --concurrency=1 test",
"prettier": "prettier --write '**/*{.ts,.tsx,.js,.jsx,.css,.json,.md,.yml}'",
"test": "lerna run test",
"tslint": "tslint --fix -c tslint.json --project tsconfigbase.json 'packages/**/*{.ts,.tsx}'",
"tslint:check": "tslint -c tslint.json --project tsconfigbase.json 'packages/**/*{.ts,.tsx}'"
},
"workspaces": {
"packages": [
"packages/*"
],
"nohoist": [
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

might be able to clean these up, now that they are no longer fighting...

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

still didn't look at these yet...

"**/@types/jest",
"**/@types/jest/**",
"**/@types/mocha/",
"**/@types/mocha/**",
"**/@types/expect/",
"**/@types/expect/**",
"**/@types/sinon/",
"**/@types/sinon/**"
]
}
}
2 changes: 1 addition & 1 deletion packages/jupyterlab-lsp/LICENSE
@@ -1,6 +1,6 @@
BSD 3-Clause License

Copyright (c) 2018,
Copyright (c) 2019, jupyter-lsp contributors
All rights reserved.

Redistribution and use in source and binary forms, with or without
Expand Down
7 changes: 6 additions & 1 deletion packages/jupyterlab-lsp/tsconfig.json
Expand Up @@ -6,5 +6,10 @@
"types": ["jest"],
"tsBuildInfoFile": "lib/.tsbuildinfo"
},
"include": ["src/**/*"]
"include": ["src/**/*"],
"references": [
{
"path": "../lsp-ws-connection"
}
]
}
46 changes: 46 additions & 0 deletions packages/lsp-ws-connection/LICENSE
@@ -0,0 +1,46 @@
BSD 3-Clause License

Copyright (c) 2019, jupyter-lsp contributors
Copy link
Member

Choose a reason for hiding this comment

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

I guess we should not stop at the fork mention, but also add "Copyright (c) 2018, William Conlon, ISC" in here.

Legalities aside I would like to credit @wylieconlon as it would not be possible to start this project without the leading work of @wylieconlon (and obviously lots of code in this PR is @wylieconlon code with slight modifications). @wylieconlon would you like any specific backlinks or mentions? Are you ok with the current mentions?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Sure, happy to give credit where due!

I think we may end up moving further and further from what remains of the code from upstream: for example, using tsee would let us keep the full event typing information, and remove the conflicts we're seeing between @types/node and @types/event. Or, as mentioned, just use MessageConnection more directly.

Of course, because we don't control the end-user jupyterlab webpack.config.js, we'll need to keep webpacking the part that interacts with fs, so this package (and its special needs) will continue to exist.

All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

* Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.

* Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

* Neither the name of the copyright holder nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

Portions of this code derived from:

ISC License (ISC)
Copyright 2019 William Conlon

Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.

THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER
RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT,
NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE
USE OR PERFORMANCE OF THIS SOFTWARE.
12 changes: 12 additions & 0 deletions packages/lsp-ws-connection/README.md
@@ -0,0 +1,12 @@
# lsp-ws-connection
bollwyvl marked this conversation as resolved.
Show resolved Hide resolved

> This is a fork of [lsp-editor-adapter](https://github.com/wylieconlon/lsp-editor-adapter), with
> a number of modifications made to make it more easily integrated into [jupyterlab-lsp](https://github.com/krassowski/jupyterlab-lsp)

## Installation

> TBD

## Developing

This library is built and tested as part of the [`jupyterlab-lsp` monorepo](https://github.com/krassowski/jupyterlab-lsp).
51 changes: 51 additions & 0 deletions packages/lsp-ws-connection/karma.conf.js
@@ -0,0 +1,51 @@
process.env.CHROME_BIN = require('puppeteer').executablePath();

module.exports = function(config) {
config.set({
basePath: '',

files: [
// The entry files are processed by webpack
'lib/test/**/*.test.js'
],

browsers: ['ChromeHeadless'],

mime: {
'text/x-typescript': ['ts', 'tsx']
},

module: 'commonjs',

singleRun: true,
autoWatch: false,
colors: true,

frameworks: ['mocha'],

reporters: ['mocha'],

preprocessors: {
'**/*!(.d).ts': 'webpack',
'**/*!(.d).js': 'webpack'
},

plugins: [
'karma-mocha',
'karma-chrome-launcher',
'karma-webpack',
'karma-mocha-reporter'
],

webpack: {
mode: 'development',
resolve: {
extensions: ['.tsx', '.ts', '.js']
},
target: 'web',
node: {
net: 'mock'
}
}
});
};
60 changes: 60 additions & 0 deletions packages/lsp-ws-connection/package.json
@@ -0,0 +1,60 @@
{
"name": "lsp-ws-connection",
"version": "0.2.0",
"description": "Utility for adapting editors to language server protocol",
"main": "dist/index.js",
"module": "dist/index.js",
"files": [
"dist",
"lib"
],
"types": "lib/index.d.ts",
"scripts": {
"lab:link": "jupyter labextension link . --no-build",
"build": "webpack",
"test": "karma start",
"test-dev": "karma start --browsers Chrome --singleRun false --timeout 30000 --autoWatch",
"watch": "webpack --watch",
"bundle": "npm pack .",
"clean": "rimraf lib dist"
},
"author": "Wylie Conlon",
"maintainers": [
"Michał Krassowski"
],
"license": "ISC",
"keywords": [
"lsp",
"languageserver"
],
"homepage": "https://github.com/krassowski/lsp-ws-connection",
"repository": "github:krassowski/lsp-ws-connection",
"dependencies": {
"vscode-jsonrpc": "^4.1.0-next",
"vscode-languageclient": "^5.2.1",
"vscode-languageserver-protocol": "^3.14.1",
"vscode-languageserver-types": "^3.14.0",
"vscode-ws-jsonrpc": "0.1.1"
},
"devDependencies": {
"@types/chai": "^4.1.7",
"@types/mocha": "^5.2.7",
"@types/node": "^12.0.7",
"@types/sinon": "^7.0.12",
"chai": "^4.2.0",
"file-loader": "~3.0.1",
"karma": "^4.1.0",
"karma-chrome-launcher": "^2.2.0",
"karma-mocha": "^1.3.0",
"karma-mocha-reporter": "^2.2.5",
"karma-webpack": "^4.0.0-rc.6",
"mocha": "^6.1.4",
"puppeteer": "^1.17.0",
"rimraf": "^2.6.3",
"sinon": "^7.3.2",
"source-map-loader": "~0.2.1",
"typescript": "^3.7.2",
"webpack": "^4.32.2",
"webpack-cli": "^3.3.0"
}
}
2 changes: 2 additions & 0 deletions packages/lsp-ws-connection/src/index.ts
@@ -0,0 +1,2 @@
export * from './ws-connection';
export * from './types';
51 changes: 51 additions & 0 deletions packages/lsp-ws-connection/src/server-capability-registration.ts
@@ -0,0 +1,51 @@
import {
Registration,
ServerCapabilities,
Unregistration
} from 'vscode-languageserver-protocol';

interface IFlexibleServerCapabilities extends ServerCapabilities {
[key: string]: any;
}

function registerServerCapability(
serverCapabilities: ServerCapabilities,
registration: Registration
): ServerCapabilities {
const serverCapabilitiesCopy = JSON.parse(
JSON.stringify(serverCapabilities)
) as IFlexibleServerCapabilities;
const { method, registerOptions } = registration;
const providerName = method.substring(13) + 'Provider';

if (providerName) {
if (!registerOptions) {
serverCapabilitiesCopy[providerName] = true;
} else {
serverCapabilitiesCopy[providerName] = JSON.parse(
JSON.stringify(registerOptions)
);
}
} else {
throw new Error('Could not register server capability.');
}

return serverCapabilitiesCopy;
}

function unregisterServerCapability(
serverCapabilities: ServerCapabilities,
unregistration: Unregistration
): ServerCapabilities {
const serverCapabilitiesCopy = JSON.parse(
JSON.stringify(serverCapabilities)
) as IFlexibleServerCapabilities;
const { method } = unregistration;
const providerName = method.substring(13) + 'Provider';

delete serverCapabilitiesCopy[providerName];

return serverCapabilitiesCopy;
}

export { registerServerCapability, unregisterServerCapability };