Skip to content
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

[Feature Request] Quick action: add variable "not in scope" to function arguments and as local definition (using where or let) #337

Open
GuillaumeDesforges opened this issue Aug 18, 2020 · 6 comments
Labels
type: enhancement New feature or request

Comments

@GuillaumeDesforges
Copy link

Say I have:

print :: IO ()
print = putStrLn . show $ x

x is not defined/not in scope of print

Quick action could insert variable inside and change type:

print :: String -> IO ()
print x = putStrLn . show $ x
@GuillaumeDesforges GuillaumeDesforges changed the title [Feature Request] Quick action: add "variable not in scope" to function arguments [Feature Request] Quick action: add variable "not in scope" to function arguments Aug 18, 2020
@Ailrun Ailrun added the type: enhancement New feature or request label Aug 18, 2020
pepeiborra pushed a commit that referenced this issue Dec 27, 2020
This was causing the following error when trying to build under MinGW:

    [28 of 38] Compiling Development.IDE.Core.FileStore

    C:\Snapshot\src\ghcide\src\Development\IDE\Core\FileStore.hs:142:20: error:
        Not in scope: `Dir.getModificationTime'
        No module named `Dir' is imported.
        |
    142 |         do time <- Dir.getModificationTime f
        |                    ^^^^^^^^^^^^^^^^^^^^^^^
@jneira
Copy link
Member

jneira commented Jan 18, 2021

Seems to me this one would be great.

@jneira
Copy link
Member

jneira commented Oct 4, 2021

Another quick action could be Define x :: String as local definition to go from

test2 :: String
test2 = id x

to

test2 :: String
test2 = id x
where x :: String
      x = error "not implemented"

@jneira jneira changed the title [Feature Request] Quick action: add variable "not in scope" to function arguments [Feature Request] Quick action: add variable "not in scope" to function arguments and as local definition (using where) Oct 4, 2021
@GuillaumeDesforges
Copy link
Author

GuillaumeDesforges commented Oct 4, 2021

@jneira some people prefer let bindings, would that be a setting or would we have 2 actions? One way to think about it is to have 1 action per possibility

  • add to function arguments
  • define in where
  • define in let

@jneira
Copy link
Member

jneira commented Oct 4, 2021

totally agree, thanks for noting it

@jneira jneira changed the title [Feature Request] Quick action: add variable "not in scope" to function arguments and as local definition (using where) [Feature Request] Quick action: add variable "not in scope" to function arguments and as local definition (using where or let) Oct 4, 2021
@GuillaumeDesforges
Copy link
Author

GuillaumeDesforges commented Oct 4, 2021

Cool :) I'm pushing further the thoughts, stop me now if it's not relevant to talk about it here.

Say I have

a = foo
  where
    foo = bar baz
      where bar = fmap

I get baz not defined, I use quick action "insert in where", where does my definition go?

a = foo
  where
    foo = bar baz
      where
        bar = fmap
        baz = error "not implemented"

or

a = foo
  where
    foo = bar baz
      where
        bar = fmap
    baz = error "not implemented"

?

Same question for let

@jneira
Copy link
Member

jneira commented Oct 5, 2021

Well, i think it could be 2 alternatives, not totally exclusive:

  • Add it always in the same context where it is being referred. And leverage a hypothetical and orthogonal feature to move up and down definitions in the subexpresions tree (inside let or where)
  • Add as many code actions as possible contexts where the definition can be added: Add baz to 'foo' context, Add bazz to 'a' context, Add baz in the top level context

First one needs some indirection but it is more elegant and less invasive cause it uses less code actions and their number is fixed, not depending on the subexpression tree deep.
Second one is direct and maybe more intuitive?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants