Open rikvdkleij opened 10 years ago
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 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.
Just a question: what are PSI trees? (What does PSI stand for?)
PSI stands for Program Structure Interface, see http://confluence.jetbrains.com/display/IDEADEV/IntelliJ+IDEA+Architectural+Overview#IntelliJIDEAArchitecturalOverview-PsiFiles
@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
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.
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.
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.
@DanielG It's concerning the type
and info
command.
That would be handy indeed :+1:
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 ?!!!
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.