Tree Sitter Not enabling on .rake files - Ruby

I’ve been running into an issue for a month or so now. *.rake files no longer have any type of color or syntax highlighting. Treesitter does not seem to active for this type of file anymore.

However when viewing the file preview from Telescope, it shows with proper syntax highlighting.

Here’s my Treesitter config

local parser_configs = require('nvim-treesitter.parsers').get_parser_configs()
parser_configs.http = {
  install_info = {
    url = 'https://github.com/NTBBloodbath/tree-sitter-http',
    files = { 'src/parser.c' },
    branch = 'main',
  },
}

require('nvim-treesitter.configs').setup {
  ensure_installed = 'maintained',
  ignore_installed = { 'haskell' },
  autopairs = { enable = true },
  autotag = { enable = true },
  context_commentstring = {
    enable = true,
    enable_autocmd = false,
  },
  incremental_selection = {
    enable = true,
    keymaps = {
      init_selection = '<CR>',
      scope_incremental = '<CR>',
      node_incremental = '<TAB>',
      node_decremental = '<S-TAB>',
    },
  },
  indent = {
    enable = true,
  },
  highlight = {
    enable = true, -- false will disable the whole extension
  },
  textobjects = {
    lsp_interop = {
      enable = true,
      border = 'none',
      peek_definition_code = {
        ['df'] = '@function.outer',
        ['dF'] = '@class.outer',
      },
    },
    move = {
      enable = true,
      set_jumps = true, -- whether to set jumps in the jumplist
      goto_next_start = {
        [']m'] = '@function.outer',
        [']]'] = '@class.outer',
      },
      goto_next_end = {
        [']M'] = '@function.outer',
        [']['] = '@class.outer',
      },
      goto_previous_start = {
        ['[m'] = '@function.outer',
        ['[['] = '@class.outer',
      },
      goto_previous_end = {
        ['[M'] = '@function.outer',
        ['[]'] = '@class.outer',
      },
    },
    select = {
      enable = true,
      -- Automatically jump forward to textobj, similar to targets.vim
      lookahead = true,
      keymaps = {
        -- You can use the capture groups defined in textobjects.scm
        ['af'] = '@function.outer',
        ['if'] = '@function.inner',
        ['ac'] = '@class.outer',
        ['ic'] = '@class.inner',
      },
    },
    swap = {
      enable = true,
      swap_next = {
        ['<leader>a'] = '@parameter.inner',
      },
      swap_previous = {
        ['<leader>A'] = '@parameter.inner',
      },
    },
  },
}

Any help would be greatly appreciated!

Update: It was a super simple fix. By setting the filetype to ruby, everything began working properly. So either create an autocommand for the Filetype rake or create ftplugin/rake.vim with set ft=ruby and it’ll work.

Hi, it might be worth opening an issue about thre ruby filetype not being correctly detected for *.rake files if that’s what you want.

You could contribute your discovery, and fix, to the the community this way :smile:

Note that filetype detection is in issue for Vim – we take their runtime files (which includes detection) as-is, so you’ll have to open an issue (or better yet, a PR) there. Neovim will then include it as part of the ongoing runtime file updates.

Nvim-treesitter no longer is responsible for that, and all remaining ftdetect and ftplugin files will be removed when Neovim 0.7 is released.

(In fact, at least on master, .rake files are already recognized as Ruby.)

Can you point me to a bit more info on this? I’m just now studying ftplugin files in my attempt to get my dev environment configured and am having trouble understanding how they fit in with the Lua way of configuring. Your comment is making me second guess configuring a bunch of ftplugin files.