Skip to content

Commit ccc3f40

Browse files
authored
Merge branch 'main' into master
2 parents 9d353e7 + a509ab7 commit ccc3f40

19 files changed

+702
-885
lines changed

.github/workflows/deploy.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Deploy server and extension
33
on:
44
push:
55
branches:
6-
- master
6+
- main
77

88
jobs:
99
deploy:

.gitignore

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1-
**/node_modules
2-
1+
# Build output
32
vscode-client/out
43
server/out
4+
5+
# Linter cache
6+
coverage/
7+
.eslintcache/
8+
9+
# OS related
510
.DS_Store
611
*.log
7-
coverage
8-
.eslintcache
12+
13+
# NPM cache
14+
node_modules/
15+
package-lock.json
16+
17+
# YARN cache
18+
.yarn/

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
save-exact = true

README.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@ We strongly recommend that you install [shellcheck][shellcheck] to enable lintin
2222
npm i -g bash-language-server
2323
```
2424

25+
On Fedora based distros:
26+
27+
```bash
28+
dnf install -y nodejs-bash-language-server
29+
```
30+
2531
If you encounter installation errors, ensure you have node version 12 or newer (`node --version`).
2632

2733
### Clients

docs/releasing.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@ To release a new version of the vscode extension
66

77
- Bump the version in `vscode-client/package.json`
88
- Update `vscode-client/CHANGELOG.md`
9-
- Merge to master
9+
- Merge to main branch
1010

1111
## Server
1212

1313
To release a new version of the server
1414

1515
- Bump the version in `server/package.json`
1616
- Update `server/CHANGELOG.md`
17-
- Merge to master
17+
- Merge to main branch

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -16,19 +16,19 @@
1616
"link-server": "npm uninstall -g bash-language-server && yarn compile && yarn unlink bash-language-server && cd server && yarn link && cd ../vscode-client && yarn link bash-language-server"
1717
},
1818
"devDependencies": {
19-
"@types/jest": "27.5.1",
20-
"@types/node": "12.20.52",
21-
"@typescript-eslint/eslint-plugin": "5.26.0",
22-
"@typescript-eslint/parser": "5.26.0",
23-
"eslint": "8.16.0",
19+
"@types/jest": "28.1.7",
20+
"@types/node": "12.20.55",
21+
"@typescript-eslint/eslint-plugin": "5.33.1",
22+
"@typescript-eslint/parser": "5.33.1",
23+
"eslint": "8.22.0",
2424
"eslint-config-prettier": "8.5.0",
25-
"eslint-plugin-jest": "26.2.2",
26-
"eslint-plugin-prettier": "4.0.0",
25+
"eslint-plugin-jest": "26.8.3",
26+
"eslint-plugin-prettier": "4.2.1",
2727
"eslint-plugin-simple-import-sort": "7.0.0",
28-
"jest": "28.1.0",
29-
"prettier": "2.6.2",
30-
"ts-jest": "28.0.2",
31-
"typescript": "4.6.4",
28+
"jest": "28.1.3",
29+
"prettier": "2.7.1",
30+
"ts-jest": "28.0.8",
31+
"typescript": "4.7.4",
3232
"vscode-languageserver": "6.1.1"
3333
},
3434
"dependencies": {},

renovate.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
{
22
"extends": [
33
"config:base"
4+
],
5+
"packageRules": [
6+
{
7+
"matchUpdateTypes": ["minor", "patch", "pin", "digest"],
8+
"automerge": true
9+
}
410
]
511
}

server/CHANGELOG.md

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

3+
## 3.0.5
4+
5+
- Fix Shellcheck issue when using vim-lsp https://github.com/bash-lsp/bash-language-server/pull/443
6+
7+
## 3.0.4
8+
9+
- Fix Windows support for analyzer https://github.com/bash-lsp/bash-language-server/pull/433
10+
311
## 3.0.3
412

513
- Workaround for emscripten node 18 support https://github.com/bash-lsp/bash-language-server/pull/404

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.0.3",
6+
"version": "3.0.5",
77
"publisher": "mads-hartmann",
88
"main": "./out/server.js",
99
"typings": "./out/server.d.ts",

server/src/__tests__/analyzer.test.ts

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -223,19 +223,23 @@ describe('findSymbolCompletions', () => {
223223
describe('commentsAbove', () => {
224224
it('returns a string of a comment block above a line', () => {
225225
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
226-
expect(analyzer.commentsAbove(CURRENT_URI, 22)).toEqual('doc for func_one')
226+
expect(analyzer.commentsAbove(CURRENT_URI, 22)).toEqual(
227+
'```txt\ndoc for func_one\n```',
228+
)
227229
})
228230

229231
it('handles line breaks in comments', () => {
230232
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
231233
expect(analyzer.commentsAbove(CURRENT_URI, 28)).toEqual(
232-
'doc for func_two\nhas two lines',
234+
'```txt\ndoc for func_two\nhas two lines\n```',
233235
)
234236
})
235237

236238
it('only returns connected comments', () => {
237239
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
238-
expect(analyzer.commentsAbove(CURRENT_URI, 36)).toEqual('doc for func_three')
240+
expect(analyzer.commentsAbove(CURRENT_URI, 36)).toEqual(
241+
'```txt\ndoc for func_three\n```',
242+
)
239243
})
240244

241245
it('returns null if no comment found', () => {
@@ -245,13 +249,15 @@ describe('commentsAbove', () => {
245249

246250
it('works for variables', () => {
247251
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
248-
expect(analyzer.commentsAbove(CURRENT_URI, 42)).toEqual('works for variables')
252+
expect(analyzer.commentsAbove(CURRENT_URI, 42)).toEqual(
253+
'```txt\nworks for variables\n```',
254+
)
249255
})
250256

251257
it('returns connected comments with empty comment line', () => {
252258
analyzer.analyze(CURRENT_URI, FIXTURES.COMMENT_DOC)
253259
expect(analyzer.commentsAbove(CURRENT_URI, 51)).toEqual(
254-
'this is also included\n\ndoc for func_four',
260+
'```txt\nthis is also included\n\ndoc for func_four\n```',
255261
)
256262
})
257263
})

server/src/__tests__/linter.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ describe('linter', () => {
1414
})
1515

1616
it('should set canLint to true if executable not empty', () => {
17-
expect(new Linter({ executablePath: null }).canLint).toBe(false)
17+
expect(new Linter({ executablePath: 'foo' }).canLint).toBe(true)
1818
})
1919

2020
it('should set canLint to false when linting fails', async () => {

server/src/__tests__/server.test.ts

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,7 @@ describe('server', () => {
101101
expect(result).toBeDefined()
102102
expect(result).toEqual({
103103
contents:
104-
'Function defined on line 8\n\nthis is a comment\ndescribing the function\nhello_world\nthis function takes two arguments',
104+
'### Function: **hello_world** - *defined on line 8*\n\n```txt\nthis is a comment\ndescribing the function\nhello_world\nthis function takes two arguments\n```',
105105
})
106106
})
107107

@@ -416,7 +416,7 @@ describe('server', () => {
416416
"name": "BLUE",
417417
"type": 3,
418418
},
419-
"documentation": "Variable defined in ../extension.inc",
419+
"documentation": "### Variable: **BLUE** - *defined in ../extension.inc*",
420420
"kind": 6,
421421
"label": "BLUE",
422422
},
@@ -439,20 +439,22 @@ describe('server', () => {
439439
)
440440

441441
expect(resultFunction).toMatchInlineSnapshot(`
442-
Array [
443-
Object {
444-
"data": Object {
445-
"name": "add_a_user",
446-
"type": 3,
447-
},
448-
"documentation": "Function defined in ../issue101.sh
449-
450-
Helper function to add a user",
451-
"kind": 3,
452-
"label": "add_a_user",
453-
},
454-
]
455-
`)
442+
Array [
443+
Object {
444+
"data": Object {
445+
"name": "add_a_user",
446+
"type": 3,
447+
},
448+
"documentation": "### Function: **add_a_user** - *defined in ../issue101.sh*
449+
450+
\`\`\`txt
451+
Helper function to add a user
452+
\`\`\`",
453+
"kind": 3,
454+
"label": "add_a_user",
455+
},
456+
]
457+
`)
456458
})
457459

458460
it('responds to onCompletion with local symbol when word is found in multiple files', async () => {

server/src/analyser.ts

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as fs from 'fs'
22
import * as FuzzySearch from 'fuzzy-search'
33
import * as request from 'request-promise-native'
44
import * as URI from 'urijs'
5+
import * as url from 'url'
56
import { promisify } from 'util'
67
import * as LSP from 'vscode-languageserver'
78
import * as Parser from 'web-tree-sitter'
@@ -72,7 +73,7 @@ export default class Analyzer {
7273
)
7374

7475
for (const filePath of filePaths) {
75-
const uri = `file://${filePath}`
76+
const uri = url.pathToFileURL(filePath).href
7677
connection.console.log(`Analyzing ${uri}`)
7778

7879
try {
@@ -436,9 +437,9 @@ export default class Analyzer {
436437
// is not a comment line
437438
const getComment = (l: string): null | string => {
438439
// this regexp has to be defined within the function
439-
const commentRegExp = /^\s*#\s*(.*)/g
440+
const commentRegExp = /^\s*#\s?(.*)/g
440441
const matches = commentRegExp.exec(l)
441-
return matches ? matches[1].trim() : null
442+
return matches ? matches[1].trimRight() : null
442443
}
443444

444445
let currentLine = doc.getText({
@@ -459,9 +460,12 @@ export default class Analyzer {
459460
}
460461

461462
if (commentBlock.length) {
463+
commentBlock.push('```txt')
462464
// since we searched from bottom up, we then reverse
463465
// the lines so that it reads top down.
464-
return commentBlock.reverse().join('\n')
466+
commentBlock.reverse()
467+
commentBlock.push('```')
468+
return commentBlock.join('\n')
465469
}
466470

467471
// no comments found above line:

server/src/server.ts

Lines changed: 18 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export default class BashServer {
2828
*/
2929
public static async initialize(
3030
connection: LSP.Connection,
31-
{ rootPath }: LSP.InitializeParams,
31+
{ rootPath, capabilities }: LSP.InitializeParams,
3232
): Promise<BashServer> {
3333
const parser = await initializeParser()
3434

@@ -43,7 +43,7 @@ export default class BashServer {
4343
Analyzer.fromRoot({ connection, rootPath, parser }),
4444
new Linter({ executablePath: config.getShellcheckPath() }),
4545
]).then(([executables, analyzer, linter]) => {
46-
return new BashServer(connection, executables, analyzer, linter)
46+
return new BashServer(connection, executables, analyzer, linter, capabilities)
4747
})
4848
}
4949

@@ -53,17 +53,20 @@ export default class BashServer {
5353

5454
private documents: LSP.TextDocuments<TextDocument> = new LSP.TextDocuments(TextDocument)
5555
private connection: LSP.Connection
56+
private clientCapabilities: LSP.ClientCapabilities
5657

5758
private constructor(
5859
connection: LSP.Connection,
5960
executables: Executables,
6061
analyzer: Analyzer,
6162
linter: Linter,
63+
capabilities: LSP.ClientCapabilities,
6264
) {
6365
this.connection = connection
6466
this.executables = executables
6567
this.analyzer = analyzer
6668
this.linter = linter
69+
this.clientCapabilities = capabilities
6770
}
6871

6972
/**
@@ -83,7 +86,9 @@ export default class BashServer {
8386
// Run shellcheck diagnostics:
8487
let diagnostics: LSP.Diagnostic[] = []
8588

86-
const folders = await connection.workspace.getWorkspaceFolders()
89+
const folders = this.clientCapabilities.workspace?.workspaceFolders
90+
? await connection.workspace.getWorkspaceFolders()
91+
: []
8792
const lintDiagnostics = await this.linter.lint(change.document, folders || [])
8893
diagnostics = diagnostics.concat(lintDiagnostics)
8994

@@ -177,15 +182,13 @@ export default class BashServer {
177182

178183
const commentAboveSymbol = this.analyzer.commentsAbove(symbolUri, symbolStarLine)
179184
const symbolDocumentation = commentAboveSymbol ? `\n\n${commentAboveSymbol}` : ''
185+
const hoverHeader = `### ${symbolKindToDescription(symbol.kind)}: **${symbol.name}**`
186+
const symbolLocation =
187+
symbolUri !== currentUri
188+
? `in ${Path.relative(currentUri, symbolUri)}`
189+
: `on line ${symbolStarLine + 1}`
180190

181-
return symbolUri !== currentUri
182-
? `${symbolKindToDescription(symbol.kind)} defined in ${Path.relative(
183-
currentUri,
184-
symbolUri,
185-
)}${symbolDocumentation}`
186-
: `${symbolKindToDescription(symbol.kind)} defined on line ${
187-
symbolStarLine + 1
188-
}${symbolDocumentation}`
191+
return `${hoverHeader} - *defined ${symbolLocation}*${symbolDocumentation}`
189192
}
190193

191194
private getCompletionItemsForSymbols({
@@ -400,7 +403,7 @@ export default class BashServer {
400403

401404
const reservedWordsCompletions = ReservedWords.LIST.map((reservedWord) => ({
402405
label: reservedWord,
403-
kind: LSP.SymbolKind.Interface, // ??
406+
kind: LSP.CompletionItemKind.Keyword,
404407
data: {
405408
name: reservedWord,
406409
type: CompletionItemDataType.ReservedWord,
@@ -413,7 +416,7 @@ export default class BashServer {
413416
.map((executable) => {
414417
return {
415418
label: executable,
416-
kind: LSP.SymbolKind.Function,
419+
kind: LSP.CompletionItemKind.Function,
417420
data: {
418421
name: executable,
419422
type: CompletionItemDataType.Executable,
@@ -423,7 +426,7 @@ export default class BashServer {
423426

424427
const builtinsCompletions = Builtins.LIST.map((builtin) => ({
425428
label: builtin,
426-
kind: LSP.SymbolKind.Interface, // ??
429+
kind: LSP.CompletionItemKind.Function,
427430
data: {
428431
name: builtin,
429432
type: CompletionItemDataType.Builtin,
@@ -432,7 +435,7 @@ export default class BashServer {
432435

433436
const optionsCompletions = options.map((option) => ({
434437
label: option,
435-
kind: LSP.SymbolKind.Interface,
438+
kind: LSP.CompletionItemKind.Constant,
436439
data: {
437440
name: option,
438441
type: CompletionItemDataType.Symbol,

vscode-client/CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Bash IDE
22

3+
## 1.14.0
4+
5+
- Upgrade language server to 3.0.3 that includes support for Shellcheck linting (please follow https://github.com/koalaman/shellcheck#installing to install Shellcheck)
6+
37
## 1.13.0
48

59
- Upgrade language server to 2.1.0

0 commit comments

Comments
 (0)