@@ -89,16 +89,22 @@ export default class BashServer {
89
89
}
90
90
}
91
91
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
+
92
102
private onHover ( pos : LSP . TextDocumentPositionParams ) : Promise < LSP . Hover > {
93
103
this . connection . console . log (
94
104
`Hovering over ${ pos . position . line } :${ pos . position . character } ` ,
95
105
)
96
106
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 )
102
108
103
109
return this . executables . isExecutableOnPATH ( word )
104
110
? this . executables . documentation ( word ) . then ( doc => ( {
@@ -114,11 +120,7 @@ export default class BashServer {
114
120
this . connection . console . log (
115
121
`Asked for definition at ${ pos . position . line } :${ pos . position . character } ` ,
116
122
)
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 )
122
124
return this . analyzer . findDefinition ( word )
123
125
}
124
126
@@ -129,22 +131,14 @@ export default class BashServer {
129
131
private onDocumentHighlight (
130
132
pos : LSP . TextDocumentPositionParams ,
131
133
) : 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 )
137
135
return this . analyzer
138
136
. findOccurrences ( pos . textDocument . uri , word )
139
137
. map ( n => ( { range : n . range } ) )
140
138
}
141
139
142
140
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 )
148
142
return this . analyzer . findReferences ( word )
149
143
}
150
144
0 commit comments