Skip to content

Conversation

ankddev
Copy link
Contributor

@ankddev ankddev commented Sep 30, 2025

Closes #4751
Add code action to add type annotation to all top level definitions.

Showcase

pub const answer = 42
pub fn add(x, y) {
  x + y
}
pub fn add_one(thing) {
  //     ^ Triggering "Annotate all top level definitions" code action here
  let result = add(thing, 1)
  result
}

would become:

pub const answer: Int = 42
pub fn add(x: Int, y: Int) -> Int {
  x + y
}
pub fn add_one(thing: Int) -> Int {
  let result = add(thing, 1)
  result
}

Copy link
Member

@giacomocavalieri giacomocavalieri 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, that's a great start! I left a couple of comments and questions inline

@ankddev ankddev changed the title feat(LS): Annotate all top level type definitions code action feat(LS): Annotate all top level definitions code action Sep 30, 2025
@ankddev ankddev marked this pull request as draft September 30, 2025 15:25
@ankddev ankddev marked this pull request as ready for review October 1, 2025 04:01
Copy link
Member

@giacomocavalieri giacomocavalieri left a comment

Choose a reason for hiding this comment

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

Fantastic! I've left just two comments that need addressing, well done!

Copy link
Member

@GearsDatapacks GearsDatapacks left a comment

Choose a reason for hiding this comment

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

Could we also have a test for partially annotated generic functions? For example:

pub fn wibble(a: a, b, c: c, d) {
  todo
}

@ankddev
Copy link
Contributor Author

ankddev commented Oct 1, 2025

Hmm, interesting. Why it shows code action for annotated functions? It worked yesterday (I tested it in Zed and Neovim), but it doesn't now.
UPD: I found it

@giacomocavalieri
Copy link
Member

Great, this looks good to me!! It only needs Louis' approval now :)

@ankddev
Copy link
Contributor Author

ankddev commented Oct 3, 2025

Ah, CI was failed because of network issues

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.

Add a code action to add type annotations to all functions in a module / project
3 participants