ghc-mod icon indicating copy to clipboard operation
ghc-mod copied to clipboard

Support getting information in modules with type errors

Open rikvdkleij opened this issue 11 years ago • 9 comments

It would be very nice if ghc-mod(i) also works if Haskell file contains some invalid Haskell code besides valid Haskell code.

For example, while typing you want to know type of expression which is defined in same Haskell file. Currently that is not possible and it would be very nice if that works.

I have no idea if this request is achievable and I like to hear your answer.

rikvdkleij avatar Aug 09 '14 13:08 rikvdkleij

ghc-mod had such a feature. ghc-mod allocated a buffer and imported necessary modules and got information from an expression in the context. It was removed. See #199. We should revisit this topic.

kazu-yamamoto avatar Aug 13 '14 06:08 kazu-yamamoto

@kazu-yamamoto Thanks for your reply. Would be very nice if this feature is supported.

To get info/type information I created workaround in IntelliJ plugin by looking in PSI trees of project files.

rikvdkleij avatar Aug 13 '14 07:08 rikvdkleij

Just a question: what are PSI trees? (What does PSI stand for?)

kazu-yamamoto avatar Aug 13 '14 12:08 kazu-yamamoto

PSI stands for Program Structure Interface, see http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview#IntelliJIDEAArchitecturalOverview-PsiFiles

rikvdkleij avatar Aug 13 '14 14:08 rikvdkleij

@rikvdkleij could you be a bit more prescise as to what constitutes "not completely valid" haskell? If you just want to know the type of an expression that uses only things imported from other modules then this would be easy to do. However if you want to know the type of a sub-expression somewhere in a declaration defined in the current file it could become a whole lot more involved. Consider the following:

foo = "Hello " ++ bar
  where bar = <some kind of invalid code involving 'baz'>
        baz = "asdf"

If you wanted to know the type of baz but bar

  • only has a type error

We could more or less easily extract baz's definition by inspecting the syntax tree GHC spits out and find the type by evaluating that in a ghci-like fashion.

  • has a syntax error

We'd need some kind of very forgiving parser for haskell to extract the code for baz which I just don't really see happening easily.

DanielG avatar Aug 21 '14 04:08 DanielG

It would be nice to support every case in which Haskell file contains some invalid code block. From you comment I understand it is difficult to support some cases. I would say start with supporting the simple to solve cases and let's see if that is sufficient in practise.

Normally I would say that only the last part of Haskell file contains the invalid code. But I can also imagine that while busy with writing a function, you want to create another function which you need in the former function which is not finished yet because you want to call that new function -:)

Hopefully this give you enough input. Otherwise let me know.

rikvdkleij avatar Aug 21 '14 08:08 rikvdkleij

@DanielG It's concerning the type and info command.

rikvdkleij avatar Aug 21 '14 13:08 rikvdkleij

That would be handy indeed :+1:

PierreR avatar Aug 25 '14 13:08 PierreR

I tested it, it does give info about types even in modules with type errors , but it doesn't give information in modules which would result in "parse error on input ...", what it gives is that symbol is not in scope ?!!!

abnud1 avatar Nov 07 '16 17:11 abnud1