LintaoAmons / scratch.nvim

Create temporary playground files effortlessly. Find them later without worrying about filenames or locations.
Other
224 stars 9 forks source link

filetype_details appear in unexpected order #41

Open gadzbi123 opened 1 month ago

gadzbi123 commented 1 month ago

Hi, I ran into the issue when I was trying to specify the filetype I want when I create a new file. My configuration looks like this:

 {
    "LintaoAmons/scratch.nvim",
    config = function()
      require("scratch").setup({
        filetypes = { "md", "txt" },
        filetype_details = {
          js = {},        -- JS FIRST
          go = {          -- GO SECOND
            requireDir = true,
            filename = "main",
            content = { "package main", "", "func main() {", "  ", "}" },
            cursor = {
              location = { 4, 2 },
              insert_mode = false,
            },
          },
        },
      })
    end,
    event = "VeryLazy",
  },

but the output of the when I run :Scratch returns wrong order of filetype (go first and js second) like so:

Select filetype                                                                                                                                                                                                                     
1: md                                                                                                                                                                                                                                        
2: txt                                                                                                                                                                                                                                       
3: go               -- GO FIRST                                                                                                                                                                                                                         
4: js               -- JS SECOND                                                                                                                                                                                                                       
5: MANUAL_INPUT   

I looked at the code, but I am not very fimiliar with lua. isn't it a mistake to put pairs() instead of ipairs() like above? https://github.com/LintaoAmons/scratch.nvim/blob/0c3badbc8b1fbe31ed5b422ba8f5c66ea6f7a9bf/lua/scratch/api.lua#L106

For me it is not a huge problem to change the order, but I wander if it is not a bug?

LintaoAmons commented 1 month ago

I didn't do anything special to keep the order of the filetypes

So right now I would say the order of the filetypes is relatively arbitrary~