@@ -137,19 +137,20 @@ func hoverRune(ctx context.Context, snapshot Snapshot, fh FileHandle, position p
137
137
var ErrNoRuneFound = errors .New ("no rune found" )
138
138
139
139
// findRune returns rune information for a position in a file.
140
- func findRune (ctx context.Context , snapshot Snapshot , fh FileHandle , pos protocol.Position ) (rune , MappedRange , error ) {
140
+ func findRune (ctx context.Context , snapshot Snapshot , fh FileHandle , position protocol.Position ) (rune , MappedRange , error ) {
141
141
pkg , pgf , err := GetParsedFile (ctx , snapshot , fh , NarrowestPackage )
142
142
if err != nil {
143
143
return 0 , MappedRange {}, err
144
144
}
145
- spn , err := pgf .Mapper .PointSpan (pos )
145
+ spn , err := pgf .Mapper .PointSpan (position )
146
146
if err != nil {
147
147
return 0 , MappedRange {}, err
148
148
}
149
149
rng , err := spn .Range (pgf .Mapper .Converter )
150
150
if err != nil {
151
151
return 0 , MappedRange {}, err
152
152
}
153
+ pos := rng .Start
153
154
154
155
// Find the basic literal enclosing the given position, if there is one.
155
156
var lit * ast.BasicLit
@@ -158,7 +159,7 @@ func findRune(ctx context.Context, snapshot Snapshot, fh FileHandle, pos protoco
158
159
if found {
159
160
return false
160
161
}
161
- if n , ok := n .(* ast.BasicLit ); ok && rng . Start >= n .Pos () && rng . Start <= n .End () {
162
+ if n , ok := n .(* ast.BasicLit ); ok && pos >= n .Pos () && pos <= n .End () {
162
163
lit = n
163
164
found = true
164
165
}
@@ -202,16 +203,9 @@ func findRune(ctx context.Context, snapshot Snapshot, fh FileHandle, pos protoco
202
203
// It's a string, scan only if it contains a unicode escape sequence under or before the
203
204
// current cursor position.
204
205
var found bool
205
- strMappedRng , err := posToMappedRange (snapshot , pkg , lit .Pos (), lit .End ())
206
- if err != nil {
207
- return 0 , MappedRange {}, err
208
- }
209
- strRng , err := strMappedRng .Range ()
210
- if err != nil {
211
- return 0 , MappedRange {}, err
212
- }
213
- offset := strRng .Start .Character
214
- for i := pos .Character - offset ; i > 0 ; i -- {
206
+ litOffset := pgf .Tok .Offset (lit .Pos ())
207
+ offset := pgf .Tok .Offset (pos )
208
+ for i := offset - litOffset ; i > 0 ; i -- {
215
209
// Start at the cursor position and search backward for the beginning of a rune escape sequence.
216
210
rr , _ := utf8 .DecodeRuneInString (lit .Value [i :])
217
211
if rr == utf8 .RuneError {
0 commit comments