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 ankddev force-pushed the fix-4751 branch 2 times, most recently from 844c42b to b011094 Compare October 3, 2025 12:34
@ankddev
Copy link
Contributor Author

ankddev commented Oct 3, 2025

Ah, CI was failed because of network issues

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.

Lovely! Thank you very much!

I've added some notes inline.

@ankddev ankddev force-pushed the fix-4751 branch 2 times, most recently from fc32b72 to 592d465 Compare October 23, 2025 10:36
@ankddev ankddev requested a review from lpil October 23, 2025 10:46
@ankddev
Copy link
Contributor Author

ankddev commented Oct 23, 2025

@lpil Done!

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

4 participants