Skip to content

Commit 22fc4b4

Browse files
authored
Merge pull request #604 from bash-lsp/zod-install
Fix missing zod install + add more shebang support
2 parents 5178711 + fada058 commit 22fc4b4

File tree

4 files changed

+21
-16
lines changed

4 files changed

+21
-16
lines changed

server/package.json

Lines changed: 3 additions & 2 deletions
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": "4.0.0-beta.5",
6+
"version": "4.0.0-beta.6",
77
"publisher": "mads-hartmann",
88
"main": "./out/server.js",
99
"typings": "./out/server.d.ts",
@@ -25,7 +25,8 @@
2525
"urijs": "1.19.11",
2626
"vscode-languageserver": "8.0.2",
2727
"vscode-languageserver-textdocument": "1.0.7",
28-
"web-tree-sitter": "0.20.7"
28+
"web-tree-sitter": "0.20.7",
29+
"zod": "3.19.1"
2930
},
3031
"scripts": {
3132
"prepublishOnly": "cd ../ && yarn run compile"

server/src/util/__tests__/shebang.test.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,14 @@ describe('analyzeShebang', () => {
2121

2222
test.each([
2323
['#!/bin/sh -', 'sh'],
24-
['#!/usr/bin/env bash', 'bash'],
2524
['#!/bin/sh', 'sh'],
25+
['#!/bin/env sh', 'sh'],
26+
['#!/usr/bin/env bash', 'bash'],
27+
['#!/bin/env bash', 'bash'],
2628
['#!/bin/bash', 'bash'],
2729
['#!/bin/bash -u', 'bash'],
2830
['#! /bin/bash', 'bash'],
31+
['#! /bin/dash', 'dash'],
2932
['#!/usr/bin/bash', 'bash'],
3033
])('returns a bash dialect for %p', (command, expectedDialect) => {
3134
expect(analyzeShebang(command).shellDialect).toBe(expectedDialect)

server/src/util/shebang.ts

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
const SHEBANG_REGEXP = /^#!(.*)/
2+
const SHELL_REGEXP = /bin[/](?:env )?(\w+)/
23

3-
// TODO: at some point we could let this return all known shells (like dash, ksh, etc)
4-
// and make the call side decide what to support.
5-
type SupportedBashDialect = 'bash' | 'sh'
4+
const BASH_DIALECTS = ['sh', 'bash', 'dash', 'ksh'] as const
5+
type SupportedBashDialect = typeof BASH_DIALECTS[number]
66

77
export function getShebang(fileContent: string): string | null {
88
const match = SHEBANG_REGEXP.exec(fileContent)
@@ -14,16 +14,12 @@ export function getShebang(fileContent: string): string | null {
1414
}
1515

1616
export function getShellDialect(shebang: string): SupportedBashDialect | null {
17-
if (shebang.startsWith('/bin/sh') || shebang.startsWith('/usr/bin/env sh')) {
18-
return 'sh'
19-
}
20-
21-
if (
22-
shebang.startsWith('/bin/bash') ||
23-
shebang.startsWith('/usr/bin/bash') ||
24-
shebang.startsWith('/usr/bin/env bash')
25-
) {
26-
return 'bash'
17+
const match = SHELL_REGEXP.exec(shebang)
18+
if (match && match[1]) {
19+
const bashDialect = match[1].trim() as any
20+
if (BASH_DIALECTS.includes(bashDialect)) {
21+
return bashDialect
22+
}
2723
}
2824

2925
return null

server/yarn.lock

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -268,3 +268,8 @@ whatwg-url@^5.0.0:
268268
dependencies:
269269
tr46 "~0.0.3"
270270
webidl-conversions "^3.0.0"
271+
272+
zod@3.19.1:
273+
version "3.19.1"
274+
resolved "https://registry.yarnpkg.com/zod/-/zod-3.19.1.tgz#112f074a97b50bfc4772d4ad1576814bd8ac4473"
275+
integrity sha512-LYjZsEDhCdYET9ikFu6dVPGp2YH9DegXjdJToSzD9rO6fy4qiRYFoyEYwps88OseJlPyl2NOe2iJuhEhL7IpEA==

0 commit comments

Comments
 (0)