Skip to content

Symbol renaming work in simple modules without any exports does not work #3571

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
halloleo opened this issue Apr 23, 2023 · 7 comments
Closed
Labels
component: hls-rename-plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..

Comments

@halloleo
Copy link

Your environment

Using VS Code as LSP client with Haskell 9.2.5 via ghcup on macOS. HLS is on 1.9.1

Steps to reproduce

Write a simple module Cnt.hs:

-- File Cnt.hs
module Cnt where

mostFrequentChar' :: String -> Char -> Int -> (Char, Int)
mostFrequentChar' [] maxChar maxFreq = (maxChar, maxFreq)
mostFrequentChar' (c:cs) maxChar maxFreq =
    let freq = count c (c:cs)
    in if freq > maxFreq
        then mostFrequentChar' cs c freq
        else mostFrequentChar' cs maxChar maxFreq
    where count x xs = length $ filter (== x) xs

No exports needed. (I will load the file into ghci to play with it.)

Then try to rename mostFrequentChar' to mostFrequentChar.

Expected behaviour

I expected that mostFrequentChar' is changed to mostFrequentChar.

Actual behaviour

No renaming is performed, but you get (in VS Code):

f66fff2629027c4a07f98d65705df3f9284b34bf

See also

I discussed this problem first on the Haskell discourse.

@halloleo halloleo added status: needs triage type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc.. labels Apr 23, 2023
@July541
Copy link
Collaborator

July541 commented Apr 23, 2023

Thanks for your report! It's a known limitation for hls-rename-plugin, see #3130 for details.

@halloleo
Copy link
Author

Thanks for picking this up, @July541.

I had a look at #3130 and I saw the tip about "haskell.plugin.rename.config.crossModule": true. Interesting, but how can a crossModule setting help in a local rename situation?

I think I don't understand...

@July541
Copy link
Collaborator

July541 commented Apr 23, 2023

but how can a crossModule setting help in a local rename situation?

Rename only work for local symbols, without the explicit export list, hls with consider all function as exported symbols, that doesn't work.

So you have two choices:

  1. Supply an explicit export list, and rename local symbols.
  2. Enable crossModule even if it's an experimental item.

@halloleo
Copy link
Author

Ah, makes sense: The initial error means I can normally rename local symbols only with export list, but with the crossModule setting I can rename local symbols even without export list, right?

Then excuse my newbie question, but in which file do I need to set this HLS setting haskell.plugin.rename.config.crossModule: true when I use HLS in VS Code?

@July541
Copy link
Collaborator

July541 commented Apr 24, 2023

Precisely, you are renaming exported symbols with crossModule enabled since all symbols will be exported implicitly.

On the Settings page, and search haskell rename, you'll find it.

image

@halloleo
Copy link
Author

Thank you, @July541! This works brilliantly!

PS: Not sure whether I should close this issue...

@July541 July541 closed this as completed Apr 26, 2023
@OlegAlexander
Copy link

Hello, and thank you for creating HLS! I'm on Windows in VSCode, and I just ran into the "Explicit export list required for renaming." Luckily, setting haskell.plugin.rename.config.crossModule: true seems to have fixed the problem. I'm new to Haskell, and I want to say that this error was very unexpected coming from other languages. I hope the crossModule renaming settings will be on by default in the future. Again, thank you for making HLS!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: hls-rename-plugin type: bug Something isn't right: doesn't work as intended, documentation is missing/outdated, etc..
Projects
None yet
Development

No branches or pull requests

3 participants