Skip to content

Commit 075c521

Browse files
committed
Add getWordAtPoint helper function
1 parent be1d796 commit 075c521

File tree

1 file changed

+14
-20
lines changed

1 file changed

+14
-20
lines changed

server/src/server.ts

+14-20
Original file line numberDiff line numberDiff line change
@@ -89,16 +89,22 @@ export default class BashServer {
8989
}
9090
}
9191

92+
private getWordAtPoint(
93+
params: LSP.ReferenceParams | LSP.TextDocumentPositionParams,
94+
): string | null {
95+
return this.analyzer.wordAtPoint(
96+
params.textDocument.uri,
97+
params.position.line,
98+
params.position.character,
99+
)
100+
}
101+
92102
private onHover(pos: LSP.TextDocumentPositionParams): Promise<LSP.Hover> {
93103
this.connection.console.log(
94104
`Hovering over ${pos.position.line}:${pos.position.character}`,
95105
)
96106

97-
const word = this.analyzer.wordAtPoint(
98-
pos.textDocument.uri,
99-
pos.position.line,
100-
pos.position.character,
101-
)
107+
const word = this.getWordAtPoint(pos)
102108

103109
return this.executables.isExecutableOnPATH(word)
104110
? this.executables.documentation(word).then(doc => ({
@@ -114,11 +120,7 @@ export default class BashServer {
114120
this.connection.console.log(
115121
`Asked for definition at ${pos.position.line}:${pos.position.character}`,
116122
)
117-
const word = this.analyzer.wordAtPoint(
118-
pos.textDocument.uri,
119-
pos.position.line,
120-
pos.position.character,
121-
)
123+
const word = this.getWordAtPoint(pos)
122124
return this.analyzer.findDefinition(word)
123125
}
124126

@@ -129,22 +131,14 @@ export default class BashServer {
129131
private onDocumentHighlight(
130132
pos: LSP.TextDocumentPositionParams,
131133
): LSP.DocumentHighlight[] {
132-
const word = this.analyzer.wordAtPoint(
133-
pos.textDocument.uri,
134-
pos.position.line,
135-
pos.position.character,
136-
)
134+
const word = this.getWordAtPoint(pos)
137135
return this.analyzer
138136
.findOccurrences(pos.textDocument.uri, word)
139137
.map(n => ({ range: n.range }))
140138
}
141139

142140
private onReferences(params: LSP.ReferenceParams): LSP.Location[] {
143-
const word = this.analyzer.wordAtPoint(
144-
params.textDocument.uri,
145-
params.position.line,
146-
params.position.character,
147-
)
141+
const word = this.getWordAtPoint(params)
148142
return this.analyzer.findReferences(word)
149143
}
150144

0 commit comments

Comments
 (0)