Skip to content

onHover and documentation improvements #230

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 7 commits into from
May 6, 2020
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
2 changes: 1 addition & 1 deletion .github/workflows/verify.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name: Verify changes

on: [push, pull_request]
on: [pull_request]

jobs:
verify:
Expand Down
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

## 1.14.0

* onHover and onCompletion documentation improvements (https://github.com/bash-lsp/bash-language-server/pull/230)
* support 0/1 as values for `HIGHLIGHT_PARSING_ERRORS` (https://github.com/bash-lsp/bash-language-server/pull/231)

## 1.13.1

* Gracefully handle glob failures (https://github.com/bash-lsp/bash-language-server/pull/224, https://github.com/bash-lsp/bash-language-server/pull/226)
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": "1.13.1",
"version": "1.14.0",
"publisher": "mads-hartmann",
"main": "./out/server.js",
"typings": "./out/server.d.ts",
Expand Down
17 changes: 9 additions & 8 deletions server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ describe('findSymbolCompletions', () => {
analyzer.analyze('install.sh', FIXTURES.INSTALL)
analyzer.analyze('sourcing-sh', FIXTURES.SOURCING)

expect(analyzer.findSymbolsMatchingWord({ word: 'npm_config_logl' }))
.toMatchInlineSnapshot(`
expect(
analyzer.findSymbolsMatchingWord({ word: 'npm_config_logl', exactMatch: false }),
).toMatchInlineSnapshot(`
Array [
Object {
"kind": 13,
Expand Down Expand Up @@ -181,13 +182,13 @@ describe('findSymbolCompletions', () => {
]
`)

expect(analyzer.findSymbolsMatchingWord({ word: 'xxxxxxxx' })).toMatchInlineSnapshot(
`Array []`,
)
expect(
analyzer.findSymbolsMatchingWord({ word: 'xxxxxxxx', exactMatch: false }),
).toMatchInlineSnapshot(`Array []`)

expect(analyzer.findSymbolsMatchingWord({ word: 'BLU' })).toMatchInlineSnapshot(
`Array []`,
)
expect(
analyzer.findSymbolsMatchingWord({ word: 'BLU', exactMatch: false }),
).toMatchInlineSnapshot(`Array []`)
})
})

Expand Down
14 changes: 0 additions & 14 deletions server/src/__tests__/builtins.test.ts

This file was deleted.

7 changes: 0 additions & 7 deletions server/src/__tests__/executables.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,6 @@ describe('list', () => {
})
})

describe('documentation', () => {
it('uses `man` so it disregards the PATH it has been initialized with', async () => {
const result = await executables.documentation('ls')
expect(result).toBeTruthy()
})
})

describe('isExecutableOnPATH', () => {
it('looks at the PATH it has been initialized with', async () => {
const result = executables.isExecutableOnPATH('ls')
Expand Down
2 changes: 1 addition & 1 deletion server/src/__tests__/server.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ describe('server', () => {
expect(result).toEqual({
contents: {
kind: 'markdown',
value: expect.stringContaining('RM(1)'),
value: expect.stringContaining('remove directories'),
},
})
})
Expand Down
11 changes: 9 additions & 2 deletions server/src/analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,13 +264,20 @@ export default class Analyzer {
/**
* Find symbol completions for the given word.
*/
public findSymbolsMatchingWord({ word }: { word: string }): LSP.SymbolInformation[] {
public findSymbolsMatchingWord({
exactMatch,
word,
}: {
exactMatch: boolean
word: string
}): LSP.SymbolInformation[] {
const symbols: LSP.SymbolInformation[] = []

Object.keys(this.uriToDeclarations).forEach(uri => {
const declarationsInFile = this.uriToDeclarations[uri] || {}
Object.keys(declarationsInFile).map(name => {
if (name.startsWith(word)) {
const match = exactMatch ? name === word : name.startsWith(word)
if (match) {
declarationsInFile[name].forEach(symbol => symbols.push(symbol))
}
})
Expand Down
12 changes: 0 additions & 12 deletions server/src/builtins.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as ShUtil from './util/sh'

// You can generate this list by running `compgen -b` in a bash session
export const LIST = [
'.',
Expand Down Expand Up @@ -68,13 +66,3 @@ const SET = new Set(LIST)
export function isBuiltin(word: string): boolean {
return SET.has(word)
}

export async function documentation(builtin: string): Promise<string> {
const errorMessage = `No help page for ${builtin}`
try {
const doc = await ShUtil.execShellScript(`help ${builtin}`)
return doc || errorMessage
} catch (error) {
return errorMessage
}
}
14 changes: 0 additions & 14 deletions server/src/executables.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { promisify } from 'util'

import * as ArrayUtil from './util/array'
import * as FsUtil from './util/fs'
import * as ShUtil from './util/sh'

const lstatAsync = promisify(fs.lstat)
const readdirAsync = promisify(fs.readdir)
Expand Down Expand Up @@ -44,19 +43,6 @@ export default class Executables {
public isExecutableOnPATH(executable: string): boolean {
return this.executables.has(executable)
}

/**
* Look up documentation for the given executable.
*
* For now it simply tries to look up the MAN documentation.
*/
public documentation(executable: string): Promise<string> {
return ShUtil.execShellScript(`man ${executable} | col -b`).then(doc => {
return !doc
? Promise.resolve(`No MAN page for ${executable}`)
: Promise.resolve(doc)
})
}
}

/**
Expand Down
11 changes: 0 additions & 11 deletions server/src/reservedWords.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
import * as ShUtil from './util/sh'

// https://www.gnu.org/software/bash/manual/html_node/Reserved-Word-Index.html

export const LIST = [
Expand Down Expand Up @@ -31,12 +29,3 @@ const SET = new Set(LIST)
export function isReservedWord(word: string): boolean {
return SET.has(word)
}

export async function documentation(reservedWord: string): Promise<string> {
try {
const doc = await ShUtil.execShellScript(`help ${reservedWord}`)
return doc || ''
} catch (error) {
return ''
}
}
Loading