Skip to content

Remove npm install step from VS Code extension #149

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 5 commits into from
Sep 25, 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: 1 addition & 2 deletions docs/development-guide.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ There are two moving parts.
- **Server**: A node server written in Typescript that implements the
[Language Server Protocol (LSP)][LSP].

- **Client**: A super tiny Visual Studio Code (vscode) extension which basically
just tells vscode how to launch the LSP server.
**Client**: A Visual Studio Code (vscode) extension which wraps the LSP server.

The project has a root `package.json` file which is really just there for
convenience - it proxies to the `package.json` files in the `vscode-client` and
Expand Down
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
"devDependencies": {
"@types/jest": "^22.2.2",
"@types/node": "^9.6.2",
"electron-rebuild": "^1.7.3",
"jest": "^22.4.3",
"prettier": "^1.11.1",
"ts-jest": "^22.4.2",
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"license": "MIT",
"version": "1.6.1",
"publisher": "mads-hartmann",
"main": "out/server.js",
"main": "./out/server.js",
"typings": "./out/server.d.ts",
"bin": {
"bash-language-server": "./bin/main.js"
Expand Down
6 changes: 3 additions & 3 deletions vscode-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
# Bash IDE

## 1.3.4
## 1.4.0

* Add additional error logging when LSP process cannot be started.
* Remove additional installation step by integrating the `bash-language-server` (versuib 1.6.1)

## 1.3.3

Expand All @@ -24,7 +24,7 @@

## 1.3.0

The client will now prompt to upgrade the Bash Language Server if you're running
* The client will now prompt to upgrade the Bash Language Server if you're running
an old version.

## 1.2.1
Expand Down
13 changes: 2 additions & 11 deletions vscode-client/README.md
Original file line number Diff line number Diff line change
@@ -1,16 +1,6 @@
# Bash IDE

Bash language server. Uses [Tree Sitter][tree-sitter] and its
[grammar for Bash][tree-sitter-bash] with [explainshell][explainshell] integration.

## System Requirements

You need to install that language server separately as it depends on native node
modules.

```bash
npm i -g bash-language-server
```
Visual Studio Code extension utilizing the [bash language server](bash-lsp), that is based on [Tree Sitter][tree-sitter] and its [grammar for Bash][tree-sitter-bash] and supports [explainshell][explainshell] integration.

## Features

Expand Down Expand Up @@ -41,6 +31,7 @@ For security reasons, it defaults to `""`, which disables explainshell integrati

Once https://github.com/idank/explainshell/pull/125 is merged, it would be possible to set this to `"https://explainshell.com"`, however doing this is **not recommended** as it will leak *all your shell scripts* to a third party — do this at your own risk, or better always use a locally running Docker image.

[bash-lsp]: https://github.com/mads-hartmann/bash-language-server
[tree-sitter]: https://github.com/tree-sitter/tree-sitter
[tree-sitter-bash]: https://github.com/tree-sitter/tree-sitter-bash
[explainshell]: https://explainshell.com/
Expand Down
14 changes: 8 additions & 6 deletions vscode-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@
"description": "A language server for Bash",
"author": "Mads Hartmann",
"license": "MIT",
"version": "1.3.4",
"version": "1.4.0",
"publisher": "mads-hartmann",
"repository": {
"type": "git",
"url": "https://github.com/mads-hartmann/bash-language-server"
},
"engines": {
"vscode": "^1.18.x"
"vscode": "^1.30.0"
},
"icon": "assets/bash-logo.png",
"categories": [
Expand Down Expand Up @@ -57,9 +57,11 @@
"postinstall": "vscode-install"
},
"dependencies": {
"@types/semver-compare": "^1.0.0",
"semver-compare": "^1.0.0",
"vscode": "^1.1.14",
"vscode-languageclient": "^4.1.3"
"bash-language-server": "1.6.1",
"vscode-languageclient": "^5.2.1",
"vscode-languageserver": "^5.2.1"
},
"devDependencies": {
"vscode": "^1.1.34"
}
}
87 changes: 24 additions & 63 deletions vscode-client/src/extension.ts
Original file line number Diff line number Diff line change
@@ -1,67 +1,43 @@
'use strict'
import * as path from 'path'

import semverCompare = require('semver-compare')
import { ExtensionContext, window, workspace } from 'vscode'
// tslint:disable-next-line:no-implicit-dependencies
import { ExtensionContext, workspace } from 'vscode'
import {
LanguageClient,
LanguageClientOptions,
ServerOptions,
TransportKind,
} from 'vscode-languageclient'

import { getServerInfo } from './util'

const MINIMUM_SERVER_VERSION = '1.5.2'

export async function activate(context: ExtensionContext) {
try {
const { command, version } = await getServerInfo()
if (semverCompare(version, MINIMUM_SERVER_VERSION) === -1) {
return handleOutdatedExecutable()
}

const explainshellEndpoint = workspace
.getConfiguration('bashIde')
.get('explainshellEndpoint', '')
const explainshellEndpoint = workspace
.getConfiguration('bashIde')
.get('explainshellEndpoint', '')

const highlightParsingErrors = workspace
.getConfiguration('bashIde')
.get('highlightParsingErrors', false)
const highlightParsingErrors = workspace
.getConfiguration('bashIde')
.get('highlightParsingErrors', false)

start(context, command, explainshellEndpoint, highlightParsingErrors)
} catch (error) {
handleStartError(error)
}
}

function start(
context: ExtensionContext,
command: string,
explainshellEndpoint: string,
highlightParsingErrors: boolean,
) {
const env: any = {
...process.env,
EXPLAINSHELL_ENDPOINT: explainshellEndpoint,
HIGHLIGHT_PARSING_ERRORS: highlightParsingErrors,
}

const serverOptions: ServerOptions = {
run: {
command,
args: ['start'],
options: {
env,
},
},
debug: {
command,
args: ['start'],
options: {
env,
},
const serverExecutable = {
module: context.asAbsolutePath(path.join('out', 'src', 'server.js')),
transport: TransportKind.ipc,
options: {
env,
},
}

const serverOptions: ServerOptions = {
run: serverExecutable,
debug: serverExecutable,
}

const clientOptions: LanguageClientOptions = {
documentSelector: [
{
Expand All @@ -76,26 +52,11 @@ function start(
},
}

const disposable = new LanguageClient(
'Bash IDE',
'Bash IDE',
serverOptions,
clientOptions,
).start()
const client = new LanguageClient('Bash IDE', 'Bash IDE', serverOptions, clientOptions)

// client.registerProposedFeatures();

// Push the disposable to the context's subscriptions so that the
// client can be deactivated on extension deactivation
context.subscriptions.push(disposable)
}

function handleOutdatedExecutable() {
const message = `Outdated bash server. Please upgrade by running "npm i -g bash-language-server".`
window.showErrorMessage(message, { modal: false })
}

function handleStartError(error: Error) {
const message =
'Unable to start bash-language-server, did you install it by running "npm i -g bash-language-server"? Open DevTools for additional details.'
console.error(error)
window.showErrorMessage(message, { modal: false })
context.subscriptions.push(client.start())
}
36 changes: 36 additions & 0 deletions vscode-client/src/server.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import {
createConnection,
IConnection,
InitializeParams,
InitializeResult,
ProposedFeatures,
} from 'vscode-languageserver'

import BashLanguageServer from 'bash-language-server'

const connection: IConnection = createConnection(ProposedFeatures.all)

connection.onInitialize(async (params: InitializeParams): Promise<InitializeResult> => {
connection.console.info('BashLanguageServer initializing...')

const server = await BashLanguageServer.initialize(connection, params)
server.register(connection)

connection.console.info('BashLanguageServer initialized')

return {
capabilities: server.capabilities(),
}
})

connection.listen()

// Don't die on unhandled Promise rejections
process.on('unhandledRejection', (reason, p) => {
connection.console.error(`Unhandled Rejection at promise: ${p}, reason: ${reason}`)
})

process.on('SIGPIPE', () => {
// Don't die when attempting to pipe stdin to a bad spawn
// https://github.com/electron/electron/issues/13254
})
42 changes: 0 additions & 42 deletions vscode-client/src/util.ts

This file was deleted.

Loading