Skip to content

Commit d03a676

Browse files
authored
Merge pull request #230 from bash-lsp/documentation-improvements
onHover and documentation improvements
2 parents 991ad3d + 8777456 commit d03a676

File tree

15 files changed

+715
-138
lines changed

15 files changed

+715
-138
lines changed

.github/workflows/verify.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: Verify changes
22

3-
on: [push, pull_request]
3+
on: [pull_request]
44

55
jobs:
66
verify:

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+
## 1.14.0
4+
5+
* onHover and onCompletion documentation improvements (https://github.com/bash-lsp/bash-language-server/pull/230)
6+
* support 0/1 as values for `HIGHLIGHT_PARSING_ERRORS` (https://github.com/bash-lsp/bash-language-server/pull/231)
7+
38
## 1.13.1
49

510
* Gracefully handle glob failures (https://github.com/bash-lsp/bash-language-server/pull/224, https://github.com/bash-lsp/bash-language-server/pull/226)

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

server/src/__tests__/analyzer.test.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ describe('findSymbolCompletions', () => {
107107
analyzer.analyze('install.sh', FIXTURES.INSTALL)
108108
analyzer.analyze('sourcing-sh', FIXTURES.SOURCING)
109109

110-
expect(analyzer.findSymbolsMatchingWord({ word: 'npm_config_logl' }))
111-
.toMatchInlineSnapshot(`
110+
expect(
111+
analyzer.findSymbolsMatchingWord({ word: 'npm_config_logl', exactMatch: false }),
112+
).toMatchInlineSnapshot(`
112113
Array [
113114
Object {
114115
"kind": 13,
@@ -181,13 +182,13 @@ describe('findSymbolCompletions', () => {
181182
]
182183
`)
183184

184-
expect(analyzer.findSymbolsMatchingWord({ word: 'xxxxxxxx' })).toMatchInlineSnapshot(
185-
`Array []`,
186-
)
185+
expect(
186+
analyzer.findSymbolsMatchingWord({ word: 'xxxxxxxx', exactMatch: false }),
187+
).toMatchInlineSnapshot(`Array []`)
187188

188-
expect(analyzer.findSymbolsMatchingWord({ word: 'BLU' })).toMatchInlineSnapshot(
189-
`Array []`,
190-
)
189+
expect(
190+
analyzer.findSymbolsMatchingWord({ word: 'BLU', exactMatch: false }),
191+
).toMatchInlineSnapshot(`Array []`)
191192
})
192193
})
193194

server/src/__tests__/builtins.test.ts

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

server/src/__tests__/executables.test.ts

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,6 @@ describe('list', () => {
2727
})
2828
})
2929

30-
describe('documentation', () => {
31-
it('uses `man` so it disregards the PATH it has been initialized with', async () => {
32-
const result = await executables.documentation('ls')
33-
expect(result).toBeTruthy()
34-
})
35-
})
36-
3730
describe('isExecutableOnPATH', () => {
3831
it('looks at the PATH it has been initialized with', async () => {
3932
const result = executables.isExecutableOnPATH('ls')

server/src/__tests__/server.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ describe('server', () => {
7171
expect(result).toEqual({
7272
contents: {
7373
kind: 'markdown',
74-
value: expect.stringContaining('RM(1)'),
74+
value: expect.stringContaining('remove directories'),
7575
},
7676
})
7777
})

server/src/analyser.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -264,13 +264,20 @@ export default class Analyzer {
264264
/**
265265
* Find symbol completions for the given word.
266266
*/
267-
public findSymbolsMatchingWord({ word }: { word: string }): LSP.SymbolInformation[] {
267+
public findSymbolsMatchingWord({
268+
exactMatch,
269+
word,
270+
}: {
271+
exactMatch: boolean
272+
word: string
273+
}): LSP.SymbolInformation[] {
268274
const symbols: LSP.SymbolInformation[] = []
269275

270276
Object.keys(this.uriToDeclarations).forEach(uri => {
271277
const declarationsInFile = this.uriToDeclarations[uri] || {}
272278
Object.keys(declarationsInFile).map(name => {
273-
if (name.startsWith(word)) {
279+
const match = exactMatch ? name === word : name.startsWith(word)
280+
if (match) {
274281
declarationsInFile[name].forEach(symbol => symbols.push(symbol))
275282
}
276283
})

server/src/builtins.ts

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as ShUtil from './util/sh'
2-
31
// You can generate this list by running `compgen -b` in a bash session
42
export const LIST = [
53
'.',
@@ -68,13 +66,3 @@ const SET = new Set(LIST)
6866
export function isBuiltin(word: string): boolean {
6967
return SET.has(word)
7068
}
71-
72-
export async function documentation(builtin: string): Promise<string> {
73-
const errorMessage = `No help page for ${builtin}`
74-
try {
75-
const doc = await ShUtil.execShellScript(`help ${builtin}`)
76-
return doc || errorMessage
77-
} catch (error) {
78-
return errorMessage
79-
}
80-
}

server/src/executables.ts

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import { promisify } from 'util'
44

55
import * as ArrayUtil from './util/array'
66
import * as FsUtil from './util/fs'
7-
import * as ShUtil from './util/sh'
87

98
const lstatAsync = promisify(fs.lstat)
109
const readdirAsync = promisify(fs.readdir)
@@ -44,19 +43,6 @@ export default class Executables {
4443
public isExecutableOnPATH(executable: string): boolean {
4544
return this.executables.has(executable)
4645
}
47-
48-
/**
49-
* Look up documentation for the given executable.
50-
*
51-
* For now it simply tries to look up the MAN documentation.
52-
*/
53-
public documentation(executable: string): Promise<string> {
54-
return ShUtil.execShellScript(`man ${executable} | col -b`).then(doc => {
55-
return !doc
56-
? Promise.resolve(`No MAN page for ${executable}`)
57-
: Promise.resolve(doc)
58-
})
59-
}
6046
}
6147

6248
/**

server/src/reservedWords.ts

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import * as ShUtil from './util/sh'
2-
31
// https://www.gnu.org/software/bash/manual/html_node/Reserved-Word-Index.html
42

53
export const LIST = [
@@ -31,12 +29,3 @@ const SET = new Set(LIST)
3129
export function isReservedWord(word: string): boolean {
3230
return SET.has(word)
3331
}
34-
35-
export async function documentation(reservedWord: string): Promise<string> {
36-
try {
37-
const doc = await ShUtil.execShellScript(`help ${reservedWord}`)
38-
return doc || ''
39-
} catch (error) {
40-
return ''
41-
}
42-
}

0 commit comments

Comments
 (0)