Skip to content

hls-rename-plugin can’t rename import aliases #4873

@izuzu-izuzu

Description

@izuzu-izuzu

Is your enhancement request related to a problem? Please describe.

Sometimes I find it difficult to organize my imports, because hls-rename-plugin doesn’t support renaming import aliases.

For example, consider the following code:

import qualified Data.List as L

betterTail = L.drop 1

Now, suppose I want to rename L because I want to import Control.Lens as L and refer to Data.List as List instead.

hls-rename-plugin can’t do this yet. Specifically:

  • If I place my cursor on L in as L, the plugin says “No symbol to rename at given location.”
  • If I place my cursor on L in L.drop and attempt to rename L to List, I get “Renaming of an imported name is unsupported.”

Describe the solution you'd like

I want to be able to place my cursor on an import alias (whether in an import statement or in a qualified name), and rename the alias.

For example, I should be able go to either L below, rename it to List, and have all occurrences of L changed correctly:

-- Before: ----------------------------

import qualified Data.List as L

betterTail = L.drop 1

-- After: -----------------------------

import qualified Data.List as List

betterTail = List.drop 1

Bonus

I also want to be able to rename the following aliases separately:

-- Before: ----------------------------

import Control.Monad as M
import Data.Maybe as M

isSomething = M.isJust  -- from Maybe
discard = M.void  -- from Monad

-- After: -----------------------------

import Control.Monad as Monad
import Data.Maybe as Maybe

isSomething = Maybe.isJust  -- from Maybe
discard = Monad.void  -- from Monad

Describe alternatives you've considered

I tried search-and-replace, but it always felt less convenient and more error prone.

For example, if I have two aliases named L and URL, doing search-and-replace to rename L to List might also turn URL to URList.

Additional context

I think there’s none.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions