Skip to content

Commit 44539cb

Browse files
authored
Merge pull request #555 from bash-lsp/fix-shellcheck
shellcheck: fix vscode config and default to executable found on path
2 parents 7e68f14 + c1dac4f commit 44539cb

File tree

8 files changed

+45
-9
lines changed

8 files changed

+45
-9
lines changed

server/CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
# Bash Language Server
22

3+
## 3.2.0
4+
5+
- Dependency upgrades
6+
- Default to shellcheck binary found on path https://github.com/bash-lsp/bash-language-server/pull/555
7+
38
## 3.1.1
49

510
- Dependency upgrades

server/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
"description": "A language server for Bash",
44
"author": "Mads Hartmann",
55
"license": "MIT",
6-
"version": "3.1.1",
6+
"version": "3.2.0",
77
"publisher": "mads-hartmann",
88
"main": "./out/server.js",
99
"typings": "./out/server.d.ts",

server/src/__tests__/linter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as path from 'path'
22
import * as LSP from 'vscode-languageserver'
33

44
import { FIXTURE_DOCUMENT, FIXTURE_FOLDER } from '../../../testing/fixtures'
5-
import Linter, { assertShellcheckResult } from '../linter'
5+
import { assertShellcheckResult, Linter } from '../linter'
66

77
function textToDoc(txt: string) {
88
return LSP.TextDocument.create('foo', 'bar', 0, txt)

server/src/linter.ts

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
import { spawn } from 'child_process'
22
import * as LSP from 'vscode-languageserver'
33

4+
import * as config from './config'
5+
import { execShellScript } from './util/sh'
6+
47
function formatMessage(comment: ShellcheckComment): string {
58
return (comment.code ? `SC${comment.code}: ` : '') + comment.message
69
}
@@ -10,8 +13,23 @@ type LinterOptions = {
1013
cwd?: string
1114
}
1215

13-
export default class Linter {
14-
private executablePath: string | null
16+
export async function getLinterExecutablePath(): Promise<string | null> {
17+
const pathFromConfig = config.getShellcheckPath()
18+
19+
if (pathFromConfig) {
20+
return pathFromConfig
21+
}
22+
23+
try {
24+
const path = (await execShellScript('which shellcheck')).trim()
25+
return path === '' ? null : path
26+
} catch (e) {
27+
return null
28+
}
29+
}
30+
31+
export class Linter {
32+
public executablePath: string | null
1533
private cwd: string
1634
_canLint: boolean
1735

server/src/server.ts

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import Analyzer from './analyser'
88
import * as Builtins from './builtins'
99
import * as config from './config'
1010
import Executables from './executables'
11-
import Linter from './linter'
11+
import { getLinterExecutablePath, Linter } from './linter'
1212
import { initializeParser } from './parser'
1313
import * as ReservedWords from './reservedWords'
1414
import { BashCompletionItem, CompletionItemDataType } from './types'
@@ -41,8 +41,9 @@ export default class BashServer {
4141
return Promise.all([
4242
Executables.fromPath(PATH),
4343
Analyzer.fromRoot({ connection, rootPath, parser }),
44-
new Linter({ executablePath: config.getShellcheckPath() }),
45-
]).then(([executables, analyzer, linter]) => {
44+
getLinterExecutablePath(),
45+
]).then(([executables, analyzer, linterExecutablePath]) => {
46+
const linter = new Linter({ executablePath: linterExecutablePath })
4647
return new BashServer(connection, executables, analyzer, linter, capabilities)
4748
})
4849
}

server/src/util/sh.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export function execShellScript(body: string, cmd = 'bash'): Promise<string> {
2929

3030
// Currently only reserved words where documentation doesn't make sense.
3131
// At least on OS X these just return the builtin man. On ubuntu there
32-
// are no documentaiton for them.
32+
// are no documentation for them.
3333
const WORDS_WITHOUT_DOCUMENTATION = new Set([
3434
'else',
3535
'fi',

vscode-client/README.md

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

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.
3+
[![VS Marketplace installs](https://badgen.net/vs-marketplace/i/mads-hartmann.bash-ide-vscode?label=VS%20Marketplace%20installs)](https://marketplace.visualstudio.com/items?itemName=mads-hartmann.bash-ide-vscode)
4+
[![VS Marketplace downloads](https://badgen.net/vs-marketplace/d/mads-hartmann.bash-ide-vscode?label=VS%20Marketplace%20downloads)](https://marketplace.visualstudio.com/items?itemName=mads-hartmann.bash-ide-vscode)
5+
[![Open VSX downloads](https://badgen.net/open-vsx/d/mads-hartmann/bash-ide-vscode?color=purple&label=Open%20VSX%20downloads)](https://open-vsx.org/extension/mads-hartmann/bash-ide-vscode)
6+
7+
Visual Studio Code extension utilizing the [Bash Language Server](bash-lsp) and integrates with [explainshell][explainshell] and [shellcheck][shellcheck].
8+
9+
We strongly recommend that you install [shellcheck][shellcheck] to enable linting: https://github.com/koalaman/shellcheck#installing
410

511
## Features
612

@@ -28,3 +34,4 @@ For security reasons, it defaults to `""`, which disables explainshell integrati
2834
[tree-sitter]: https://github.com/tree-sitter/tree-sitter
2935
[tree-sitter-bash]: https://github.com/tree-sitter/tree-sitter-bash
3036
[explainshell]: https://explainshell.com/
37+
[shellcheck]: https://www.shellcheck.net/

vscode-client/package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,11 @@
4545
"type": "string",
4646
"default": "",
4747
"description": "Configure explainshell server in order to get hover documentation on flags and options."
48+
},
49+
"bashIde.shellcheckPath": {
50+
"type": "string",
51+
"default": "",
52+
"description": "Configure a custom path for the Shellcheck executable in order to get linting information."
4853
}
4954
}
5055
}

0 commit comments

Comments
 (0)