Skip to content

Commit 2488754

Browse files
authored
Merge pull request #149 from mads-hartmann/remove-install-step
Remove npm install step from VS Code extension
2 parents 787da9e + df87dac commit 2488754

File tree

11 files changed

+654
-1676
lines changed

11 files changed

+654
-1676
lines changed

docs/development-guide.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,7 @@ There are two moving parts.
55
- **Server**: A node server written in Typescript that implements the
66
[Language Server Protocol (LSP)][LSP].
77

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

1110
The project has a root `package.json` file which is really just there for
1211
convenience - it proxies to the `package.json` files in the `vscode-client` and

package.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@
1818
"devDependencies": {
1919
"@types/jest": "^22.2.2",
2020
"@types/node": "^9.6.2",
21-
"electron-rebuild": "^1.7.3",
2221
"jest": "^22.4.3",
2322
"prettier": "^1.11.1",
2423
"ts-jest": "^22.4.2",

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
"license": "MIT",
66
"version": "1.6.1",
77
"publisher": "mads-hartmann",
8-
"main": "out/server.js",
8+
"main": "./out/server.js",
99
"typings": "./out/server.d.ts",
1010
"bin": {
1111
"bash-language-server": "./bin/main.js"

vscode-client/CHANGELOG.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# Bash IDE
22

3-
## 1.3.4
3+
## 1.4.0
44

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

77
## 1.3.3
88

@@ -24,7 +24,7 @@
2424

2525
## 1.3.0
2626

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

3030
## 1.2.1

vscode-client/README.md

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,6 @@
11
# Bash IDE
22

3-
Bash language server. Uses [Tree Sitter][tree-sitter] and its
4-
[grammar for Bash][tree-sitter-bash] with [explainshell][explainshell] integration.
5-
6-
## System Requirements
7-
8-
You need to install that language server separately as it depends on native node
9-
modules.
10-
11-
```bash
12-
npm i -g bash-language-server
13-
```
3+
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.
144

155
## Features
166

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

4232
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.
4333

34+
[bash-lsp]: https://github.com/mads-hartmann/bash-language-server
4435
[tree-sitter]: https://github.com/tree-sitter/tree-sitter
4536
[tree-sitter-bash]: https://github.com/tree-sitter/tree-sitter-bash
4637
[explainshell]: https://explainshell.com/

vscode-client/package.json

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
"description": "A language server for Bash",
55
"author": "Mads Hartmann",
66
"license": "MIT",
7-
"version": "1.3.4",
7+
"version": "1.4.0",
88
"publisher": "mads-hartmann",
99
"repository": {
1010
"type": "git",
1111
"url": "https://github.com/mads-hartmann/bash-language-server"
1212
},
1313
"engines": {
14-
"vscode": "^1.18.x"
14+
"vscode": "^1.30.0"
1515
},
1616
"icon": "assets/bash-logo.png",
1717
"categories": [
@@ -57,9 +57,11 @@
5757
"postinstall": "vscode-install"
5858
},
5959
"dependencies": {
60-
"@types/semver-compare": "^1.0.0",
61-
"semver-compare": "^1.0.0",
62-
"vscode": "^1.1.14",
63-
"vscode-languageclient": "^4.1.3"
60+
"bash-language-server": "1.6.1",
61+
"vscode-languageclient": "^5.2.1",
62+
"vscode-languageserver": "^5.2.1"
63+
},
64+
"devDependencies": {
65+
"vscode": "^1.1.34"
6466
}
6567
}

vscode-client/src/extension.ts

Lines changed: 24 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -1,67 +1,43 @@
11
'use strict'
2+
import * as path from 'path'
23

3-
import semverCompare = require('semver-compare')
4-
import { ExtensionContext, window, workspace } from 'vscode'
4+
// tslint:disable-next-line:no-implicit-dependencies
5+
import { ExtensionContext, workspace } from 'vscode'
56
import {
67
LanguageClient,
78
LanguageClientOptions,
89
ServerOptions,
10+
TransportKind,
911
} from 'vscode-languageclient'
1012

11-
import { getServerInfo } from './util'
12-
13-
const MINIMUM_SERVER_VERSION = '1.5.2'
14-
1513
export async function activate(context: ExtensionContext) {
16-
try {
17-
const { command, version } = await getServerInfo()
18-
if (semverCompare(version, MINIMUM_SERVER_VERSION) === -1) {
19-
return handleOutdatedExecutable()
20-
}
21-
22-
const explainshellEndpoint = workspace
23-
.getConfiguration('bashIde')
24-
.get('explainshellEndpoint', '')
14+
const explainshellEndpoint = workspace
15+
.getConfiguration('bashIde')
16+
.get('explainshellEndpoint', '')
2517

26-
const highlightParsingErrors = workspace
27-
.getConfiguration('bashIde')
28-
.get('highlightParsingErrors', false)
18+
const highlightParsingErrors = workspace
19+
.getConfiguration('bashIde')
20+
.get('highlightParsingErrors', false)
2921

30-
start(context, command, explainshellEndpoint, highlightParsingErrors)
31-
} catch (error) {
32-
handleStartError(error)
33-
}
34-
}
35-
36-
function start(
37-
context: ExtensionContext,
38-
command: string,
39-
explainshellEndpoint: string,
40-
highlightParsingErrors: boolean,
41-
) {
4222
const env: any = {
4323
...process.env,
4424
EXPLAINSHELL_ENDPOINT: explainshellEndpoint,
4525
HIGHLIGHT_PARSING_ERRORS: highlightParsingErrors,
4626
}
4727

48-
const serverOptions: ServerOptions = {
49-
run: {
50-
command,
51-
args: ['start'],
52-
options: {
53-
env,
54-
},
55-
},
56-
debug: {
57-
command,
58-
args: ['start'],
59-
options: {
60-
env,
61-
},
28+
const serverExecutable = {
29+
module: context.asAbsolutePath(path.join('out', 'src', 'server.js')),
30+
transport: TransportKind.ipc,
31+
options: {
32+
env,
6233
},
6334
}
6435

36+
const serverOptions: ServerOptions = {
37+
run: serverExecutable,
38+
debug: serverExecutable,
39+
}
40+
6541
const clientOptions: LanguageClientOptions = {
6642
documentSelector: [
6743
{
@@ -76,26 +52,11 @@ function start(
7652
},
7753
}
7854

79-
const disposable = new LanguageClient(
80-
'Bash IDE',
81-
'Bash IDE',
82-
serverOptions,
83-
clientOptions,
84-
).start()
55+
const client = new LanguageClient('Bash IDE', 'Bash IDE', serverOptions, clientOptions)
56+
57+
// client.registerProposedFeatures();
8558

8659
// Push the disposable to the context's subscriptions so that the
8760
// client can be deactivated on extension deactivation
88-
context.subscriptions.push(disposable)
89-
}
90-
91-
function handleOutdatedExecutable() {
92-
const message = `Outdated bash server. Please upgrade by running "npm i -g bash-language-server".`
93-
window.showErrorMessage(message, { modal: false })
94-
}
95-
96-
function handleStartError(error: Error) {
97-
const message =
98-
'Unable to start bash-language-server, did you install it by running "npm i -g bash-language-server"? Open DevTools for additional details.'
99-
console.error(error)
100-
window.showErrorMessage(message, { modal: false })
61+
context.subscriptions.push(client.start())
10162
}

vscode-client/src/server.ts

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import {
2+
createConnection,
3+
IConnection,
4+
InitializeParams,
5+
InitializeResult,
6+
ProposedFeatures,
7+
} from 'vscode-languageserver'
8+
9+
import BashLanguageServer from 'bash-language-server'
10+
11+
const connection: IConnection = createConnection(ProposedFeatures.all)
12+
13+
connection.onInitialize(async (params: InitializeParams): Promise<InitializeResult> => {
14+
connection.console.info('BashLanguageServer initializing...')
15+
16+
const server = await BashLanguageServer.initialize(connection, params)
17+
server.register(connection)
18+
19+
connection.console.info('BashLanguageServer initialized')
20+
21+
return {
22+
capabilities: server.capabilities(),
23+
}
24+
})
25+
26+
connection.listen()
27+
28+
// Don't die on unhandled Promise rejections
29+
process.on('unhandledRejection', (reason, p) => {
30+
connection.console.error(`Unhandled Rejection at promise: ${p}, reason: ${reason}`)
31+
})
32+
33+
process.on('SIGPIPE', () => {
34+
// Don't die when attempting to pipe stdin to a bad spawn
35+
// https://github.com/electron/electron/issues/13254
36+
})

vscode-client/src/util.ts

Lines changed: 0 additions & 42 deletions
This file was deleted.

0 commit comments

Comments
 (0)