crystal-lang-tools / vscode-crystal-lang

Yet another VSCode extension for Crystal Programming Language
https://marketplace.visualstudio.com/items?itemName=crystal-lang-tools.crystal-lang
MIT License
279 stars 58 forks source link

Type on hover missing #185

Open wJoenn opened 9 months ago

wJoenn commented 9 months ago

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):

nobodywasishere commented 9 months ago

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.

wJoenn commented 9 months ago

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
nobodywasishere commented 9 months ago

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.

wJoenn commented 9 months ago

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

wJoenn commented 9 months ago

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
nobodywasishere commented 9 months ago

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.

wJoenn commented 9 months ago

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