SpyglassMC / Spyglass

Development tools for vanilla Minecraft: Java Edition data pack developers.
https://spyglassmc.com
MIT License
322 stars 34 forks source link

Feat: Auto Extension Fix #1653

Open Kesuaheli opened 4 days ago

Kesuaheli commented 4 days ago

It frequently happens that one misspelled a file extension e.g. .mcfuntion instead of .mcfunction. Misode hat the Idea if Spyglass could detect that. Which gave me the following concept:


I'm thinking of a popup notification in the bottom right. Which says something like, "The file you just created has an unknown extension for the function folder. Expected '.mcfunction'." And then there are two buttons. One that just closes it. And one to automagically rename it. (Ik, the close button is redundant, as you can close a popup on the :95_x:. But I feel like it's better UX to have it next to the button that does stuff)

That same concept can be applied to all folders. For example:

A sort of config option would be cool; obviously. Maybe even overrides. Simply turning that on/off. By overrides, I mean a whitelist-ish thing, where you specify file extensions that Spyglass won't complain about. Example:

{
  "function": [
    ".foo"
  ],
  "tags/function": [
    ".bar",
    "barfoo"
  ]
}

Would result in a behaviour like:

If the created file does not exist in the whitelist and the user decides to let Spyglass rename it, Spyglass cuts everything from (including) the last dot ., if any. And then the expected extension is added at the end. Example:

Maybe also an option to set the expected extensions? Like this:

{
  "function": {
    "replace": ".mcfunction",
    "allow": [
      ".foo"
    ]
  },
  "tag/biome": {
    "replace": "_custom.json",
    "allow": [
      "foobar"
    ]
  }
}
SPGoding commented 4 days ago

Thanks for the write up. Popups are rather un-LSP-ly, but I think a warning on the first line of the file with a quick fix for renaming it would work? We could even add another quick fix for automatically changing the config file to allow the current file name/extension, but that might be too much magic.