Skip to content

Commit 4a51d52

Browse files
committed
Refactor getDocumentationForSymbol for readability
1 parent 84e117b commit 4a51d52

File tree

1 file changed

+10
-12
lines changed

1 file changed

+10
-12
lines changed

server/src/server.ts

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -142,21 +142,19 @@ export default class BashServer {
142142
symbol: LSP.SymbolInformation
143143
currentUri: string
144144
}): string {
145-
const getCommentsAbove = (uri: string, line: number): string => {
146-
const comment = this.analyzer.commentsAbove(uri, line)
147-
return comment ? `\n\n${comment}` : ''
148-
}
145+
const symbolUri = symbol.location.uri
146+
const symbolStarLine = symbol.location.range.start.line
147+
148+
const commentAboveSymbol = this.analyzer.commentsAbove(symbolUri, symbolStarLine)
149+
const symbolDocumentation = commentAboveSymbol ? `\n\n${commentAboveSymbol}` : ''
149150

150-
return symbol.location.uri !== currentUri
151+
return symbolUri !== currentUri
151152
? `${symbolKindToDescription(symbol.kind)} defined in ${path.relative(
152153
currentUri,
153-
symbol.location.uri,
154-
)}${getCommentsAbove(symbol.location.uri, symbol.location.range.start.line)}`
155-
: `${symbolKindToDescription(symbol.kind)} defined on line ${symbol.location.range
156-
.start.line + 1}${getCommentsAbove(
157-
currentUri,
158-
symbol.location.range.start.line,
159-
)}`
154+
symbolUri,
155+
)}${symbolDocumentation}`
156+
: `${symbolKindToDescription(symbol.kind)} defined on line ${symbolStarLine +
157+
1}${symbolDocumentation}`
160158
}
161159

162160
private getCompletionItemsForSymbols({

0 commit comments

Comments
 (0)