Skip to content

Commit 18cfd87

Browse files
authored
Merge pull request #577 from bash-lsp/fix-documentation
Fix shell documentation for newlines
2 parents 5976669 + 64db51d commit 18cfd87

File tree

5 files changed

+18
-14
lines changed

5 files changed

+18
-14
lines changed

Diff for: server/src/__tests__/analyzer.test.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,15 @@ describe('analyze', () => {
3737
})
3838

3939
describe('findDefinition', () => {
40-
it('returns empty list if parameter is not found', () => {
40+
it('returns an empty list if word is not found', () => {
4141
analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
42-
const result = analyzer.findDefinition('foobar')
42+
const result = analyzer.findDefinition({ word: 'foobar' })
4343
expect(result).toEqual([])
4444
})
4545

4646
it('returns a list of locations if parameter is found', () => {
4747
analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL)
48-
const result = analyzer.findDefinition('node_version')
48+
const result = analyzer.findDefinition({ word: 'node_version' })
4949
expect(result).not.toEqual([])
5050
expect(result).toMatchSnapshot()
5151
})

Diff for: server/src/analyser.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ const readFileAsync = promisify(fs.readFile)
1717

1818
type Kinds = { [type: string]: LSP.SymbolKind }
1919

20-
type Declarations = { [name: string]: LSP.SymbolInformation[] }
20+
type Declarations = { [word: string]: LSP.SymbolInformation[] }
2121
type FileDeclarations = { [uri: string]: Declarations }
2222

2323
type Trees = { [uri: string]: Parser.Tree }
@@ -126,12 +126,12 @@ export default class Analyzer {
126126
}
127127

128128
/**
129-
* Find all the locations where something named name has been defined.
129+
* Find all the locations where something has been defined.
130130
*/
131-
public findDefinition(name: string): LSP.Location[] {
131+
public findDefinition({ word }: { word: string }): LSP.Location[] {
132132
const symbols: LSP.SymbolInformation[] = []
133133
Object.keys(this.uriToDeclarations).forEach((uri) => {
134-
const declarationNames = this.uriToDeclarations[uri][name] || []
134+
const declarationNames = this.uriToDeclarations[uri][word] || []
135135
declarationNames.forEach((d) => symbols.push(d))
136136
})
137137
return symbols.map((s) => s.location)
@@ -317,8 +317,8 @@ export default class Analyzer {
317317
return
318318
}
319319

320-
const name = contents.slice(named.startIndex, named.endIndex)
321-
const namedDeclarations = this.uriToDeclarations[uri][name] || []
320+
const word = contents.slice(named.startIndex, named.endIndex)
321+
const namedDeclarations = this.uriToDeclarations[uri][word] || []
322322

323323
const parent = TreeSitterUtil.findParent(
324324
n,
@@ -334,14 +334,14 @@ export default class Analyzer {
334334

335335
namedDeclarations.push(
336336
LSP.SymbolInformation.create(
337-
name,
337+
word,
338338
this.treeSitterTypeToLSPKind[n.type],
339339
TreeSitterUtil.range(n),
340340
uri,
341341
parentName,
342342
),
343343
)
344-
this.uriToDeclarations[uri][name] = namedDeclarations
344+
this.uriToDeclarations[uri][word] = namedDeclarations
345345
}
346346
})
347347

Diff for: server/src/config.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function getGlobPattern(): string {
2727
export function getHighlightParsingError(): boolean {
2828
const { HIGHLIGHT_PARSING_ERRORS } = process.env
2929
return typeof HIGHLIGHT_PARSING_ERRORS !== 'undefined'
30-
? HIGHLIGHT_PARSING_ERRORS === 'true' || HIGHLIGHT_PARSING_ERRORS === '1'
30+
? toBoolean(HIGHLIGHT_PARSING_ERRORS)
3131
: false
3232
}
3333

@@ -39,3 +39,5 @@ export function getBackgroundAnalysisMaxFiles(): number {
3939
const parsed = parseInt(BACKGROUND_ANALYSIS_MAX_FILES || '', 10)
4040
return !isNaN(parsed) ? parsed : DEFAULT_BACKGROUND_ANALYSIS_MAX_FILES
4141
}
42+
43+
const toBoolean = (s: string): boolean => s === 'true' || s === '1'

Diff for: server/src/server.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ export default class BashServer {
321321
if (!word) {
322322
return null
323323
}
324-
return this.analyzer.findDefinition(word)
324+
return this.analyzer.findDefinition({ word })
325325
}
326326

327327
private onDocumentSymbol(params: LSP.DocumentSymbolParams): LSP.SymbolInformation[] {

Diff for: server/src/util/sh.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,9 @@ export async function getShellDocumentationWithoutCache({
8585
formattedDocumentation = formatManOutput(formattedDocumentation)
8686
}
8787

88-
return formattedDocumentation
88+
if (formattedDocumentation) {
89+
return formattedDocumentation
90+
}
8991
}
9092
} catch (error) {
9193
// Ignoring if command fails and store failure in cache

0 commit comments

Comments
 (0)