crystal-lang-tools/vscode-crystal-lang

Type on hover missing

wJoenn opened this issue ยท 7 comments

Describe the bug
I've just installed the extension (0.9.1) on my WSL machine and no types are appearing on hover despite the setting being enabled.
In my Crystal lsp output I can see getting context... froze

To Reproduce
Not sure tbh
I just installed Crystal with asdf

git clone https://github.com/asdf-vm/asdf.git ~/.asdf --branch v0.14.0
asdf plugin-add crystal https://github.com/asdf-community/asdf-crystal.git
asdf install crystal latest
asdt global crystal 1.11.2

Then installed the extension in vscode
Reloaded vscode, created a .cr file and wrote a simple method

def foo : String
  "bar"
end

Expected behavior
To see the type of what I'm hovering

Screenshots
image

Desktop (please complete the following information):

  • OS: Windows 10 with WSL:Ubuntu 22
  • Crystal version: v1.11.2
  • This plugin version: v0.9.1

Thank you for the bug report! Currently type information can only be provided for methods / etc that are included in the final executable. Can you try doing this, and seeing if the hover works over the foo method call?

def foo : String
  "hello"
end

puts foo # <-- here

It is weird though that there were no messages after "getting context...", I'll try to get a WSL2 system setup soon to see if I can reproduce.

Thanks for the quick response ๐Ÿ™Œ
Printing doesn't seem to work either
Another detail is that the loading tooltip only appear on the first hover after reloading vscode but if I unhover and hover again then no tooltip ever appear again until I reload vscode again

image

Currently type information can only be provided for methods / etc that are included in the final executable.

Is that something that is planned to be improved later on or a limitation coming from Crystal ? ๐Ÿค”
I started using the language today so I was planning on making a bunch of small methods and test just to get to know the syntax and the differences with Ruby.
It'd be a bummer if I couldn't get type hints when doing something simple like

require "spec"

def foo : String
  "hello"
end

describe "#foo" do
  it "should return 'hello'" do
    foo.should eq "hello"
  end
end

Ah alright good to know, thank you for testing that! I also started on Ruby before finding Crystal, let me know if you have any questions about the language.

It's a limitation of the compiler currently, it removes anything not included in an executable (methods defined but never used, for example). Also due to type inference, the types can change depending on what's using the method (unless you've explicitly typed it like with your foo method). Specs are executables though, so that should work.

let me know if you have any questions about the language.

It's a bit early but I'll be sure to take you on that offer soon ๐Ÿ‘€ Thank you very much

I just realized but it seems I'm not getting any type error either
Like on this screenshot, I assume I should have an error showing up in vscode saying that 1 is not of type String right ?
Might be related to the LSP not loading properly.

image

LSP which btw no prints an additional error: undefined line when hovering a value (this wasn't the case yesterday)

[Crystal] extension loaded
[Hover] getting context...
[Hover] error: undefined
[Hover] getting context...
[Hover] error: undefined

So currently, you're not utilizing an LSP but instead wrappers for several compiler tools. I should provide better documentation but you need to install https://github.com/elbywan/crystalline somewhere and point the server setting at it, then restart vscode.

You should be seeing type error information, looks like the problems tool isn't running for some reason. It's supposed to run every time you save or open a new file.

Yes that was it ๐Ÿ™Œ
I installed crystalline's binary with the command found in the repo's README, wrote the absolute path to that binary as the server's path in the Crystal Language vscode extension's settings and reloaded VSCode.
Everything works fine as far as Types on hover and type errors go now.

Thank you @nobodywasishere

I could probably open a PR within the next couple of days to update the README if you'd like