AstroNvim / AstroNvim

AstroNvim is an aesthetic and feature-rich neovim config that is extensible and easy to use with a great set of plugins
https://AstroNvim.com
GNU General Public License v3.0
12.54k stars 918 forks source link

Filetype not working anymore #672

Closed flamendless closed 2 years ago

flamendless commented 2 years ago

Hi, previous I have this in my config:

        filetype = {
            overrides = {
                -- extensions = { lua2p = "lua", },
                function_extensions = {
                    lua = function()
                        vim.bo.filetype = "lua"
                        require("user.love").SetLove()
                    end,
                    lua2p = function()
                        require("user.love").SetLua2p()
                    end
                }
            },
        },

which adds syntax highlighting to my custom extension, but after updating to the latest astrovim config it does not work anymore, I also tried moving that to the polish function and:

    --also in polish
    vim.filetype.add = {
      extensions = {
        lua = function()
          vim.bo.filetype = "lua"
          require("user.love").SetLove()
        end,
        lua2p = function()
          require("user.love").SetLua2p()
        end
      }
    }
mehalter commented 2 years ago

Do you happen to have vim polyglot installed?

flamendless commented 2 years ago

No, i only have these additional plugins:

      {"gpanders/editorconfig.nvim"},
      {"f-person/git-blame.nvim"},
      {"simnalamburt/vim-mundo"},
      {"bkad/CamelCaseMotion"},
      {"dewyze/vim-tada"},
mehalter commented 2 years ago

Are you using nightly still? Or have you moved to using stable AstroNvim/Neovim? Also can you provide a link/paste your user config and I can try to take a look. I can't replicate on a base AstroNvim installation or my own configuration.

flamendless commented 2 years ago

Are you using nightly still? Or have you moved to using stable AstroNvim/Neovim? Also can you provide a link/paste your user config and I can try to take a look. I can't replicate on a base AstroNvim installation or my own configuration.

Didn't work for stable and nightly. Now im using nightly. Here's the link to my config https://github.com/flamendless/AstroVim/tree/main/lua/user the init_backup.lua is the previous config that works before me updating

mehalter commented 2 years ago

According to :help vim.filetype.add() it looks like a function should return the string that it should set as the filetype. So I think it should be something like this:

    --also in polish
    vim.filetype.add {
      extensions = {
        lua = function()
          require("user.love").SetLove()
          return "lua"
        end,
        lua2p = function()
          require("user.love").SetLua2p()
          return "lua"
        end
      }
    }

Have you checked the docs and tried something like this to follow what they describe?

The filetype can be either a string (in which case it is used as the filetype directly) or a function. If a function, it takes the full path and buffer number of the file as arguments (along with captures from the matched pattern, if any) and should return a string that will be used as the buffer's filetype.

flamendless commented 2 years ago

I've tried that, didn't work. whats confusing is that the previous config (even if not in polish function) worked.

i think the code is not ran, after opening a lua2p file and doing :set filetype? i get filetype= only

mehalter commented 2 years ago

It should go in the polish function since neovim 0.7 has moved filetype.lua to core Neovim. So this is no longer a plugin. I also just noticed your blunder in your polish function. Give this a try:

    --also in polish
    vim.filetype.add {
      extensions = {
        lua = function()
          require("user.love").SetLove()
          return "lua"
        end,
        lua2p = function()
          require("user.love").SetLua2p()
          return "lua"
        end
      }
    }
flamendless commented 2 years ago

Ahhh i missed that function call instead of assignment in vim.filetype.add, Ive tried that (ive pushed my config) but it still didnt work :/

mehalter commented 2 years ago

I also just noticed in the :help vim.filetype.add that it is extension not extensions. After that your config works for me.

    --also in polish
    vim.filetype.add {
      extension = {
        lua = function()
          require("user.love").SetLove()
          return "lua"
        end,
        lua2p = function()
          require("user.love").SetLua2p()
          return "lua"
        end
      }
    }
flamendless commented 2 years ago

Awesome. works now. now i need to turn off lua lsp for lua2p files

mehalter commented 2 years ago

do you just want to not change the filetype to lua like you had before? Just return lua2p or something instead of lua

flamendless commented 2 years ago

if i do that i dont get any syntax highlighting anymore. basically what im aiming for is lua syntax highlight but no lsp since it has custom tokens so the lsp will complain alot

mehalter commented 2 years ago

Interesting, good luck haha I'm not sure of a good way to do that.

flamendless commented 2 years ago

Finally figured it out by accident, i removed the return "lua" and return "lua2p" and it works