@@ -155,8 +155,9 @@ getContext (ContextMap chunks) query =
155155 searchChunks :: Bool -> [ContextChunk ] -> ([ContextGroup ], ContextResult )
156156 searchChunks _ [] = ([] , mempty )
157157 searchChunks firstChunk (Chunk cLo cHi group contextOf : rest)
158- | -- query is past this chunk
159- qLo > cHi = searchChunks False rest
158+ | -- query is past this chunk (line-only comparison so cursors
159+ -- past the last column on the final line still match)
160+ _line qLo > _line cHi = searchChunks False rest
160161 | -- query is before this chunk
161162 qHi < cLo = (if firstChunk then [HeaderGroup ] else [] , mempty )
162163 -- this chunk is relevant, emit the group and all relevant intervals
@@ -209,8 +210,13 @@ contextual context shouldStop query s =
209210dominates :: Range -> Range -> Bool
210211dominates (Range s e) (Range qs qe) = s <= qs && qe <= e
211212
213+ -- | A query range is outside a source range if it ends before the source
214+ -- starts, or it starts on a line after the source ends.
215+ -- We intentionally compare only lines (not columns) for the trailing
216+ -- boundary so that a cursor past the last token on a line still falls
217+ -- inside the node occupying that line.
212218outside :: Range -> Range -> Bool
213- outside (Range ps pe) (Range qs qe) = pe < qs || ps > qe
219+ outside (Range ps pe) (Range qs qe) = pe < qs || _line ps > _line qe
214220
215221instance Pretty Context where
216222 pretty = \ case
0 commit comments