Skip to content

Add hover info for custom types #4458

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

unknown
Copy link
Contributor

@unknown unknown commented Apr 7, 2025

Adds hover info for custom types and closes #4451.

I marked this PR as a draft, because the behavior I implemented differs slightly from the original proposed behavior I proposed. See #4451 (comment) for more context. Otherwise, this is ready to be reviewed.

This PR changes the language server display type info like the following:

//// wibble.gleam

type Wibble {
  // ^ Wibble

  Wibble(Int)
  // ^ Wibble(Int)

  Wobble(label: String)
  // ^ Wobble(label: String)
  //     ^ String
}

@unknown unknown changed the title LS: hover info for custom types Add hover info for custom types Apr 7, 2025
@unknown unknown marked this pull request as ready for review April 26, 2025 16:41
Copy link
Member

@lpil lpil left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you. I've left a note inline

.as_ref()
.map(|(_, doc)| doc)
.unwrap_or(&empty_str);
let contents = format!("```gleam\n{name}({arguments})\n```\n{documentation}");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is different from the format we use for variants!

image

Can we reuse the existing code to ensure they are the same?

Copy link
Contributor Author

@unknown unknown May 3, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I made a note of that here: #4451 (comment)

It's been a while since I worked on this, but if I remember correctly, the reason it differs is because RecordConstructor doesn't store any information about the custom type its a member of (aka the return type of the constructor). Should I add a string in RecordConstructor with the name of the custom type?

Not sure if there are other approaches, but adding a string wouldn't allow for code reuse. The return type would have to be a Type.

@lpil lpil marked this pull request as draft April 27, 2025 13:15
@unknown unknown force-pushed the ls-custom-type-hover branch from 94ef4ab to 0c6acae Compare May 3, 2025 20:10
@unknown unknown marked this pull request as ready for review May 6, 2025 23:52
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

LS: hover info for custom types and their constructors
2 participants