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 on hover missing #185

Open
wJoenn opened this issue Feb 17, 2024 · 7 comments
Open

Type on hover missing #185

wJoenn opened this issue Feb 17, 2024 · 7 comments
Assignees
Labels

Comments

@wJoenn
Copy link

wJoenn commented Feb 17, 2024

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
@nobodywasishere
Copy link
Member

nobodywasishere commented Feb 17, 2024

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
Copy link
Author

wJoenn commented Feb 17, 2024

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
Copy link
Member

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
Copy link
Author

wJoenn commented Feb 17, 2024

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
Copy link
Author

wJoenn commented Feb 18, 2024

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
Copy link
Member

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
Copy link
Author

wJoenn commented Feb 18, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants