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

Type information for arbitrary portions of code #709

Open
jacg opened this issue Sep 14, 2019 · 15 comments
Open

Type information for arbitrary portions of code #709

jacg opened this issue Sep 14, 2019 · 15 comments
Labels
component: ghcide level: hard Ticket suited for experts priority: high High priority item type: enhancement New feature or request

Comments

@jacg
Copy link
Contributor

jacg commented Sep 14, 2019

ghcide gives me information on most alphanumeric symbols (and numeric literals) but there are two features that I'm used to from dante and/or intero:

  • type information on operators
  • type information on arbitrary selected expressions

Do these features exist, and have I simply not found them?

If not, any hints on how to implement them?

@mitchellwrosen
Copy link

I'm able to see type information on operators.
2019-09-14-221120_723x423_scrot

@cocreature
Copy link
Contributor

Operators should definitely work, given that it seems to work in some cases, it would be good if you could provide a specific test case where it fails.

Getting type information of a range is a bit more tricky. It is obviously more complex to implement but there is a second issue here: LSP hover does only give us a position not a range. I’ve taken a quick look at the spec and I also couldn’t find any other method that we could use here either.

@jacg
Copy link
Contributor Author

jacg commented Sep 18, 2019

Operators should definitely work

Sorry, yes, they do (it's just that in my configuration symbols' types were being shown spontaneously, while it took a bit more effort for symbols).

@jacg jacg changed the title Type information for operators and arbitrary portions of code Type information for ~~operators and~~ arbitrary portions of code Sep 23, 2019
@jacg jacg changed the title Type information for ~~operators and~~ arbitrary portions of code Type information for arbitrary portions of code Sep 23, 2019
@jacg
Copy link
Contributor Author

jacg commented Oct 7, 2019

I guess that the bug label isn't appropriate here, as everything that is expected to work (information about symbols) seems to work.

@jneira
Copy link
Member

jneira commented Sep 9, 2020

The type of arbitrary expression can be extracted indirectly in hls, using the eval plugin, that includes :t.
Not sure if it is possible right now to translate in the hover, using the lsp protocol as pointed by @cocreature. So we should wait for some spec update to implement it.

@jacg does the workaround using eval works for you?

@JacoboDominguez
Copy link

That question should be addressed by me nearly twin @jacg :)
Cheers,

@alanz
Copy link
Collaborator

alanz commented Sep 11, 2020

FYI microsoft/language-server-protocol#377

@normenmueller
Copy link

The type of arbitrary expression can be extracted indirectly in hls, using the eval plugin, that includes :t.

@jneira Could you please give some more advice on how to install/ configure?

@jneira
Copy link
Member

jneira commented Nov 22, 2020

@normenmueller you have to install haskell-language-server which includes by default the eval plugin (you can see it in action here ).

Then you can write -- >>> in the code to evaluate expressions in the module context:

-- >>> :t fooExe
fooExe :: [Char]
fooExe = "hi"
  • pressing a link Evaluate
-- >>> :t fooExe
-- fooExe :: [Char]
fooExe :: [Char]
fooExe = "hi"

You can write arbitrary expressions:

-- >>> :t "hi"
fooExe :: [Char]
fooExe = "hi"
-- >>> :t "hi"
-- "hi" :: [Char]
fooExe :: [Char]
fooExe = "hi"

@jneira jneira transferred this issue from haskell/ghcide Dec 29, 2020
@jneira jneira added component: ghcide type: enhancement New feature or request can-workaround status: blocked Not actionable, because blocked by upstream/GHC etc. labels Dec 29, 2020
@jneira
Copy link
Member

jneira commented Jan 19, 2021

@alanz commented in the issue originally in hls:

I guess someone needs to actually make a PR for microsoft/language-server-protocol#377

@jneira jneira removed the status: blocked Not actionable, because blocked by upstream/GHC etc. label Jan 19, 2021
@jamesdbrock
Copy link

“Type information on arbitrary selected expressions” is the killer feature of any Haskell IDE.

vim-hdevtools has that. Actually, what it has works a little bit differently:

  1. Press the F1 key and it will select the token which the cursor is on, and tell you the type of the token.
  2. Press the F1 key again, and it will expand the selection to the next outer subexpression and tell you the type of that.

... and you can repeat step 2 as many times as you like.

It would be great if we could have that feature again with HLS.

@jneira
Copy link
Member

jneira commented Jun 24, 2021

As @jamesdbrock gently pointed in #1973, this feature used to work in haskell-ide-engine (see the pr in the vscode extension which added the feature here)
Maybe it worths investigate how was done in hie, althoug it seems it used ghcmod underneath, a deprecated library that should not be used.

@Martinsos
Copy link

I found this comment explaining a bit on how they implemented this in rust-analyzer: microsoft/language-server-protocol#377 (comment) -> maybe this is useful to guide the possible implementation efforts?

@hasufell hasufell added priority: high High priority item level: hard Ticket suited for experts and removed can-workaround labels Jul 13, 2022
@hasufell
Copy link
Member

hasufell commented Jan 4, 2023

@alanz @mpickering does anyone have knowledge whether this is difficult in ghcide itself (getting type of arbitrary expression), ignoring the issues with LSP and clients?

Maybe we can make some step by step progress.

@fendor
Copy link
Collaborator

fendor commented Jan 4, 2023

For type information, I bet we can hack something together using HIE files and hiedb.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: ghcide level: hard Ticket suited for experts priority: high High priority item type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests