[WIP] Update LSP hover action to return labelled definition
Relates to https://github.com/gleam-lang/gleam/issues/2653
Updating the LSP hover action to return the full function head, as per the documentation.
The planned format is as below
<fn-accessor-type> fn <function-name>(<label> <argument-name>: <type>, ..) -> <return-type>
Eg: For a function like below
fn greet(firstname name:String) { io.println("Hello " <> name) }
The generated string would be
fn greet(firstname name: String) -> Nil
Current implementation uses pretty print and existing Fn Type enum. Since labels are not part of the type system, we are going ahead with simple string interpolation for now.
P.S : This is the first time working with the codebase and such a big Rust repo, hence please feel free to suggest changes and improvements.
P.P.S: I am trying to test it out in local hence kept the [WIP] tag.
Considering the sampe like below
import gleam/io
import gleam/string
fn greet(n name: String) -> String {
string.append(name, "hello")
}
pub fn main() {
io.println(greet("Tom"))
}
Some of my findings (being new to the language)
- Hovering on
main()our Lsp identifies the keyword as a function and it works fine - Hovering on
greeton this lineio.println(greet("Tom")), it get idenfitied asexpressionhere
Will need to identify how to handle that case there. Plus, I am also trying to understand how to quickly identify if the expression in this method here
Tried defining something like below but seems to not to work
/// Returns `true` if the typed expr is [`Fn`].
///
/// [`Fn`]: TypedExpr::Fn
#[must_use]
pub fn is_function(&self) -> bool {
matches!(self, Self::Fn { .. })
}
cc @lpil
The case you are probably looking for there is a Self::Call not a Self::Fn fn is a function definition whereas call is when the function is actually being used