@@ -174,7 +174,7 @@ findAliasDeclAtPos pos imports = listToMaybe $ do
174174 Just locatedAlias <- [ideclAs importDecl]
175175 RealSrcSpan aliasDeclSpan _ <- [getLoc locatedAlias]
176176 let aliasDeclRange = realSrcSpanToCodePointRange aliasDeclSpan
177- guard (rangeContainsPosition aliasDeclRange pos)
177+ guard (rangeContainsPositionInclusive aliasDeclRange pos)
178178 let aliasModuleName = unLoc (ideclName importDecl)
179179 aliasName = unLoc locatedAlias
180180 aliasIsShared = length (filter (== aliasName) allAliases) > 1
@@ -194,12 +194,12 @@ findAliasUseAtPos pos imports hsDecls =
194194 Qual qualifier _ <- [unLoc locatedRdrName]
195195 RealSrcSpan qualifiedNameSpan _ <- [getLoc locatedRdrName]
196196 let qualifiedNameRange = realSrcSpanToCodePointRange qualifiedNameSpan
197- guard (rangeContainsPosition qualifiedNameRange pos)
197+ guard (rangeContainsPositionInclusive qualifiedNameRange pos)
198198 let qualifierLength = fromIntegral (moduleNameLength qualifier)
199199 qualifierStart = qualifiedNameRange ^. VFS. start
200200 qualifierRange = qualifiedNameRange
201201 & VFS. end .~ (qualifierStart & VFS. character +~ qualifierLength)
202- guard (rangeContainsPosition qualifierRange pos)
202+ guard (rangeContainsPositionInclusive qualifierRange pos)
203203 [(qualifierRange, qualifier)]
204204 in case qualifiersAtPos of
205205 [] -> Nothing
@@ -295,16 +295,18 @@ ambiguousAliasErrorMessage _ = ""
295295---------------------------------------------------------------------------------------------------
296296-- Utility functions
297297
298- -- | Check whether a 'CodePointRange' contains a 'CodePointPosition'
299- -- (inclusive start, exclusive end).
300- rangeContainsPosition :: VFS. CodePointRange -> VFS. CodePointPosition -> Bool
301- rangeContainsPosition
298+ -- | Check whether a 'CodePointRange' contains a 'CodePointPosition' (inclusive
299+ -- start, inclusive end).
300+ -- NOTE: The use of inclusive end allows the user to place the cursor at the end
301+ -- of an import alias and rename it.
302+ rangeContainsPositionInclusive :: VFS. CodePointRange -> VFS. CodePointPosition -> Bool
303+ rangeContainsPositionInclusive
302304 (VFS. CodePointRange
303305 (VFS. CodePointPosition startLine startColumn)
304306 (VFS. CodePointPosition endLine endColumn))
305307 (VFS. CodePointPosition posLine posColumn)
306308 = (posLine > startLine || (posLine == startLine && posColumn >= startColumn))
307- && (posLine < endLine || (posLine == endLine && posColumn < endColumn))
309+ && (posLine < endLine || (posLine == endLine && posColumn <= endColumn))
308310
309311-- | Build a 'TextEdit' from a 'VFS.CodePointRange' and replacement text.
310312-- Returns @Nothing@ if the range is out of bounds in the VFS.
0 commit comments