Skip to content

Fix shell documentation for newlines #577

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 2 commits into from
Nov 28, 2022
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
6 changes: 3 additions & 3 deletions server/src/__tests__/analyzer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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()
})
Expand Down
16 changes: 8 additions & 8 deletions server/src/analyser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand All @@ -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
}
})

Expand Down
4 changes: 3 additions & 1 deletion server/src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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'
2 changes: 1 addition & 1 deletion server/src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] {
Expand Down
4 changes: 3 additions & 1 deletion server/src/util/sh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down