stevearc / oil.nvim

Neovim file explorer: edit your filesystem like a buffer
MIT License
3.83k stars 109 forks source link

feature request: custom highlights #402

Open bennypowers opened 4 months ago

bennypowers commented 4 months ago

Did you check existing requests?

Describe the feature

In cases like these, it would be nice to be able to define some custom highlight groups, perhaps something like this:

function has_ts_source(bufnr, name)
  --impl left to the imagination
end

require'oil'.setup {
  -- ...
  view_options = {
    get_custom_highlight = function(name, bufnr)
      if name:gmatch'(.js|.map|.d.ts)$' and has_ts_source(name, bufnr) then
        return { 'OilArtifact' }
      end
    end,
  },
}

vim.cmd.highlight('link OilArtifact Comment')

Provide background

When working in a TypeScript project, it is common to have some build artifacts generated for each source file:

pf-icon.e2e.d.ts
pf-icon.e2e.js
pf-icon.e2e.js.map
pf-icon.e2e.ts
pf-icon.spec.d.ts
pf-icon.spec.js
pf-icon.spec.js.map
pf-icon.spec.ts

In this case, the user wants the .d.ts, .js and .map artifacts to appear in the buffer, but to receive subdued highlighting.

This is not the same as hiding gitignored files, because oftentimes the user still wants to be able to inspect build artifacts (for example, to verify that they were compiled as expected, or to insert debugging code in the runtime files).

What is the significance of this feature?

nice to have

Additional details

Similar to #375 Similar to https://github.com/nvim-neo-tree/neo-tree.nvim/issues/118