#Girard - a Gleam source type annotator in Gleam

1 messages · Page 1 of 1 (latest)

mellow hare
#

Maybe someone else finds this useful too: girard is a type annotator for Gleam, written in Gleam (built on top of glance). Given Gleam source, it runs the same type inference the compiler does and hands you the inferred type of every expression, plus each top-level definition's signature.

It should be stable enough to use out there: I've run it across the public hex ecosystem, comparing its per-expression output against the real Gleam compiler — and aside from a few parsing gaps in glance, it returns the same types.

I built it because most of the Gleam I write these days is written by machines, so I'm putting together some static-analysis tooling to help with that — and I needed the types.

https://github.com/alvivi/girard

GitHub

A Gleam type annotator that mirrors the compiler's type inference - alvivi/girard

short briar
#

Better to forward this message here

#

But yeah now I'm thinking this package might be useful for me because right now in my backlog of project to do I got a lustre LSP where I can detect the function the user selected and wrap another function.
The idea would be to have a code action to wrap a lustre element inside another one.
But I would want of course this code action to only show if the function return a Lustre Element.
So I would need something that either see where the function is and what type it return if it's specified. Or dig every bit of code until it can resolve it.

#

But this is when your library might really help me because it's maybe the missing piece that can know what the user selected function got has arguments and returns type. Which would make possible to finish my dearly and beloved Lustre LSP

mellow hare
#

Are you planning to build the LSP in Gleam? I’m not aware of any others currently, but it would definitely be possible. It’s just a matter of using Glance for parsing and Girard to retrieve the types of current expressions. I would be worried about performance, though, since an LSP is an online tool.

#

I’m actually developing this because of Lustre. I’m tired of side effects leaking into update or view functions (both from my own code and from AI agents). So, I’m working on Graded (https://github.com/alvivi/graded), though it’s still far from being prod-ready. But, this is designed as an 'offline' static analyzer.

short briar
mellow hare
short briar
#

I have kind the feeling you stole my idea 😔

mellow hare
#

🤣 that's why I'm not sharing the code. I just wanted to try the lib, no problem

short briar
#

At least thank you to show me your library is really the missing part to my detection

#

Right now what I did in my version is I know where the function called is and when I call this test action I wrap the code inside {}

#

(Of course this is mostly to test if I can wrap stuff, I didn't wanted to bother writing a function called and do stuff like auto import yet ^^)

mellow hare