Skip to content

shellcheck: fix vscode config and default to executable found on path #555

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 4 commits into from
Nov 25, 2022
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
5 changes: 5 additions & 0 deletions server/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
# Bash Language Server

## 3.2.0

- Dependency upgrades
- Default to shellcheck binary found on path https://github.com/bash-lsp/bash-language-server/pull/555

## 3.1.1

- Dependency upgrades
Expand Down
2 changes: 1 addition & 1 deletion server/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"description": "A language server for Bash",
"author": "Mads Hartmann",
"license": "MIT",
"version": "3.1.1",
"version": "3.2.0",
"publisher": "mads-hartmann",
"main": "./out/server.js",
"typings": "./out/server.d.ts",
Expand Down
2 changes: 1 addition & 1 deletion server/src/__tests__/linter.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import * as path from 'path'
import * as LSP from 'vscode-languageserver'

import { FIXTURE_DOCUMENT, FIXTURE_FOLDER } from '../../../testing/fixtures'
import Linter, { assertShellcheckResult } from '../linter'
import { assertShellcheckResult, Linter } from '../linter'

function textToDoc(txt: string) {
return LSP.TextDocument.create('foo', 'bar', 0, txt)
Expand Down
22 changes: 20 additions & 2 deletions server/src/linter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import { spawn } from 'child_process'
import * as LSP from 'vscode-languageserver'

import * as config from './config'
import { execShellScript } from './util/sh'

function formatMessage(comment: ShellcheckComment): string {
return (comment.code ? `SC${comment.code}: ` : '') + comment.message
}
Expand All @@ -10,8 +13,23 @@ type LinterOptions = {
cwd?: string
}

export default class Linter {
private executablePath: string | null
export async function getLinterExecutablePath(): Promise<string | null> {
const pathFromConfig = config.getShellcheckPath()

if (pathFromConfig) {
return pathFromConfig
}

try {
const path = (await execShellScript('which shellcheck')).trim()
return path === '' ? null : path
} catch (e) {
return null
}
}

export class Linter {
public executablePath: string | null
private cwd: string
_canLint: boolean

Expand Down
7 changes: 4 additions & 3 deletions server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import Analyzer from './analyser'
import * as Builtins from './builtins'
import * as config from './config'
import Executables from './executables'
import Linter from './linter'
import { getLinterExecutablePath, Linter } from './linter'
import { initializeParser } from './parser'
import * as ReservedWords from './reservedWords'
import { BashCompletionItem, CompletionItemDataType } from './types'
Expand Down Expand Up @@ -41,8 +41,9 @@ export default class BashServer {
return Promise.all([
Executables.fromPath(PATH),
Analyzer.fromRoot({ connection, rootPath, parser }),
new Linter({ executablePath: config.getShellcheckPath() }),
]).then(([executables, analyzer, linter]) => {
getLinterExecutablePath(),
]).then(([executables, analyzer, linterExecutablePath]) => {
const linter = new Linter({ executablePath: linterExecutablePath })
return new BashServer(connection, executables, analyzer, linter, capabilities)
})
}
Expand Down
2 changes: 1 addition & 1 deletion server/src/util/sh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export function execShellScript(body: string, cmd = 'bash'): Promise<string> {

// Currently only reserved words where documentation doesn't make sense.
// At least on OS X these just return the builtin man. On ubuntu there
// are no documentaiton for them.
// are no documentation for them.
const WORDS_WITHOUT_DOCUMENTATION = new Set([
'else',
'fi',
Expand Down
9 changes: 8 additions & 1 deletion vscode-client/README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
# Bash IDE

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.
[![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)
[![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)
[![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)

Visual Studio Code extension utilizing the [Bash Language Server](bash-lsp) and integrates with [explainshell][explainshell] and [shellcheck][shellcheck].

We strongly recommend that you install [shellcheck][shellcheck] to enable linting: https://github.com/koalaman/shellcheck#installing

## Features

Expand Down Expand Up @@ -28,3 +34,4 @@ For security reasons, it defaults to `""`, which disables explainshell integrati
[tree-sitter]: https://github.com/tree-sitter/tree-sitter
[tree-sitter-bash]: https://github.com/tree-sitter/tree-sitter-bash
[explainshell]: https://explainshell.com/
[shellcheck]: https://www.shellcheck.net/
5 changes: 5 additions & 0 deletions vscode-client/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,11 @@
"type": "string",
"default": "",
"description": "Configure explainshell server in order to get hover documentation on flags and options."
},
"bashIde.shellcheckPath": {
"type": "string",
"default": "",
"description": "Configure a custom path for the Shellcheck executable in order to get linting information."
}
}
}
Expand Down