From 46b3666140dc48ee59d9e37602816d14b14f8816 Mon Sep 17 00:00:00 2001 From: skovhus Date: Mon, 28 Nov 2022 12:32:54 +0100 Subject: [PATCH 1/2] Handle case when the formatted docs is an empty string This failed the unit tests on OS X. --- server/src/util/sh.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/server/src/util/sh.ts b/server/src/util/sh.ts index 746158819..079e050ee 100644 --- a/server/src/util/sh.ts +++ b/server/src/util/sh.ts @@ -85,7 +85,9 @@ export async function getShellDocumentationWithoutCache({ formattedDocumentation = formatManOutput(formattedDocumentation) } - return formattedDocumentation + if (formattedDocumentation) { + return formattedDocumentation + } } } catch (error) { // Ignoring if command fails and store failure in cache From 64db51da89cd8f92e611c406222689fc44ec6119 Mon Sep 17 00:00:00 2001 From: skovhus Date: Mon, 28 Nov 2022 12:33:52 +0100 Subject: [PATCH 2/2] Move small refactorings from #244 --- server/src/__tests__/analyzer.test.ts | 6 +++--- server/src/analyser.ts | 16 ++++++++-------- server/src/config.ts | 4 +++- server/src/server.ts | 2 +- 4 files changed, 15 insertions(+), 13 deletions(-) diff --git a/server/src/__tests__/analyzer.test.ts b/server/src/__tests__/analyzer.test.ts index 1f0efb449..f9d1dffe9 100644 --- a/server/src/__tests__/analyzer.test.ts +++ b/server/src/__tests__/analyzer.test.ts @@ -37,15 +37,15 @@ describe('analyze', () => { }) describe('findDefinition', () => { - it('returns empty list if parameter is not found', () => { + it('returns an empty list if word is not found', () => { analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL) - const result = analyzer.findDefinition('foobar') + const result = analyzer.findDefinition({ word: 'foobar' }) expect(result).toEqual([]) }) it('returns a list of locations if parameter is found', () => { analyzer.analyze(CURRENT_URI, FIXTURES.INSTALL) - const result = analyzer.findDefinition('node_version') + const result = analyzer.findDefinition({ word: 'node_version' }) expect(result).not.toEqual([]) expect(result).toMatchSnapshot() }) diff --git a/server/src/analyser.ts b/server/src/analyser.ts index 62d6f6f88..b9fbe10fe 100644 --- a/server/src/analyser.ts +++ b/server/src/analyser.ts @@ -17,7 +17,7 @@ const readFileAsync = promisify(fs.readFile) type Kinds = { [type: string]: LSP.SymbolKind } -type Declarations = { [name: string]: LSP.SymbolInformation[] } +type Declarations = { [word: string]: LSP.SymbolInformation[] } type FileDeclarations = { [uri: string]: Declarations } type Trees = { [uri: string]: Parser.Tree } @@ -126,12 +126,12 @@ export default class Analyzer { } /** - * Find all the locations where something named name has been defined. + * Find all the locations where something has been defined. */ - public findDefinition(name: string): LSP.Location[] { + public findDefinition({ word }: { word: string }): LSP.Location[] { const symbols: LSP.SymbolInformation[] = [] Object.keys(this.uriToDeclarations).forEach((uri) => { - const declarationNames = this.uriToDeclarations[uri][name] || [] + const declarationNames = this.uriToDeclarations[uri][word] || [] declarationNames.forEach((d) => symbols.push(d)) }) return symbols.map((s) => s.location) @@ -317,8 +317,8 @@ export default class Analyzer { return } - const name = contents.slice(named.startIndex, named.endIndex) - const namedDeclarations = this.uriToDeclarations[uri][name] || [] + const word = contents.slice(named.startIndex, named.endIndex) + const namedDeclarations = this.uriToDeclarations[uri][word] || [] const parent = TreeSitterUtil.findParent( n, @@ -334,14 +334,14 @@ export default class Analyzer { namedDeclarations.push( LSP.SymbolInformation.create( - name, + word, this.treeSitterTypeToLSPKind[n.type], TreeSitterUtil.range(n), uri, parentName, ), ) - this.uriToDeclarations[uri][name] = namedDeclarations + this.uriToDeclarations[uri][word] = namedDeclarations } }) diff --git a/server/src/config.ts b/server/src/config.ts index ca58d180a..d2afbc30d 100644 --- a/server/src/config.ts +++ b/server/src/config.ts @@ -27,7 +27,7 @@ export function getGlobPattern(): string { export function getHighlightParsingError(): boolean { const { HIGHLIGHT_PARSING_ERRORS } = process.env return typeof HIGHLIGHT_PARSING_ERRORS !== 'undefined' - ? HIGHLIGHT_PARSING_ERRORS === 'true' || HIGHLIGHT_PARSING_ERRORS === '1' + ? toBoolean(HIGHLIGHT_PARSING_ERRORS) : false } @@ -39,3 +39,5 @@ export function getBackgroundAnalysisMaxFiles(): number { const parsed = parseInt(BACKGROUND_ANALYSIS_MAX_FILES || '', 10) return !isNaN(parsed) ? parsed : DEFAULT_BACKGROUND_ANALYSIS_MAX_FILES } + +const toBoolean = (s: string): boolean => s === 'true' || s === '1' diff --git a/server/src/server.ts b/server/src/server.ts index e638a181c..58147bcce 100644 --- a/server/src/server.ts +++ b/server/src/server.ts @@ -321,7 +321,7 @@ export default class BashServer { if (!word) { return null } - return this.analyzer.findDefinition(word) + return this.analyzer.findDefinition({ word }) } private onDocumentSymbol(params: LSP.DocumentSymbolParams): LSP.SymbolInformation[] {