@@ -123,7 +123,12 @@ export default function createMiddleware(
123123 provideReferences ( document , position , options , token , next ) {
124124 return flowconfigCache . get ( document ) . then ( docFlowconfig => {
125125 if ( docFlowconfig === clientFlowconfig ) {
126- return next ( document , position , options , token ) ;
126+ return next (
127+ document ,
128+ fixPosition ( document , position ) ,
129+ options ,
130+ token ,
131+ ) ;
127132 }
128133 return null ;
129134 } ) ;
@@ -132,7 +137,7 @@ export default function createMiddleware(
132137 provideDocumentHighlights ( document , position , token , next ) {
133138 return flowconfigCache . get ( document ) . then ( docFlowconfig => {
134139 if ( docFlowconfig === clientFlowconfig ) {
135- return next ( document , position , token ) ;
140+ return next ( document , fixPosition ( document , position ) , token ) ;
136141 }
137142 return null ;
138143 } ) ;
@@ -150,7 +155,12 @@ export default function createMiddleware(
150155 provideRenameEdits ( document , position , newName , token , next ) {
151156 return flowconfigCache . get ( document ) . then ( docFlowconfig => {
152157 if ( docFlowconfig === clientFlowconfig ) {
153- return next ( document , position , newName , token ) ;
158+ return next (
159+ document ,
160+ fixPosition ( document , position ) ,
161+ newName ,
162+ token ,
163+ ) ;
154164 }
155165 return null ;
156166 } ) ;
@@ -206,3 +216,18 @@ function formatHoverContent(value: ?vscode.Hover): ?vscode.Hover {
206216
207217 return value ;
208218}
219+
220+ function fixPosition ( document , position ) {
221+ const range = document . getWordRangeAtPosition ( position ) ;
222+ if ( ! range ) {
223+ return position ;
224+ }
225+ // Fix position to handle differences in flow and vscode
226+ // [flow] uses `position` as cursor on letter `te` (so only works if cursor on character (t & e))
227+ // -------^^----
228+ // [vscode] uses `position` as cursor b/w character & character + 1 `|te`, `t|e, `te|` (expect 0, 1, 2 all 3 to work)
229+ // @Fix : if position is the end of word move position one char back.
230+ return position . isEqual ( range . end )
231+ ? position . with ( { character : position . character - 1 } )
232+ : position ;
233+ }
0 commit comments