Skip to content
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

Extract const code action #3936

Closed
lpil opened this issue Dec 2, 2024 · 6 comments
Closed

Extract const code action #3936

lpil opened this issue Dec 2, 2024 · 6 comments
Labels
help wanted Contributions encouraged priority:medium

Comments

@lpil
Copy link
Member

lpil commented Dec 2, 2024

An action that extracts a highlighted value and replaces it with a const

pub fn main() {
  list.map([1, 2, 3], run)
  #        ^^^^^^^^^
}
const value = [1, 2, 3]

pub fn main() {
  list.map(value, run)
}
@lpil lpil added help wanted Contributions encouraged priority:medium labels Dec 2, 2024
@matiascr
Copy link
Contributor

matiascr commented Feb 10, 2025

I'm taking a look at this. I'm guessing this should also perform these kinds of conversions?

Before:

pub fn main() {
  let l = ["A", "B", "C"]
  list.map(l, run)
}

After extracting whole composite type (as long as the contents are all literals):

const l = ["A", "B", "C"]

pub fn main() {
  list.map(l, run)
}

Or after extracting by individual literals:

const string = "A"

pub fn main() {
  let l = [string, "B", "C"]
  list.map(l, run)
}

@lpil
Copy link
Member Author

lpil commented Feb 10, 2025

Yeah!!

@matiascr
Copy link
Contributor

matiascr commented Feb 10, 2025

WIP @ #4228
Currently extracts literals (Int, Float, String) in

  • Literals in right hand side of assignments
  • Literals inside lists and tuples
  • Lists and tuples of literals
  • Literal function arguments

Next steps

  • Extracting whole variable declaration as constant declaration
  • Extacting individual type variants

@lpil
Copy link
Member Author

lpil commented Feb 11, 2025

If you'd like to PR just a subset of expressions to start that would be good by me!

@matiascr
Copy link
Contributor

Sounds great. I've cleaned it up and put it here #4228

@GearsDatapacks
Copy link
Member

I believe this can be closed now, as the relevant PR has been merged

@lpil lpil closed this as completed Mar 20, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Contributions encouraged priority:medium
Projects
None yet
Development

No branches or pull requests

3 participants