aboutsummaryrefslogtreecommitdiff
path: root/runtime/lua/vim/treesitter/dev.lua
diff options
context:
space:
mode:
authorYochem van Rosmalen <git@yochem.nl>2026-01-22 13:22:35 +0100
committerLewis Russell <me@lewisr.dev>2026-01-28 10:57:39 +0000
commitf7041625f1abe4e9bfd2461fef23d1d74dc75c29 (patch)
treeeae20b5f4f7dfd3540d4727af357f8866d519873 /runtime/lua/vim/treesitter/dev.lua
parent9988d7142d65f1bd732480d7d942ccd16669c5b2 (diff)
downloadrneovim-f7041625f1abe4e9bfd2461fef23d1d74dc75c29.tar.gz
rneovim-f7041625f1abe4e9bfd2461fef23d1d74dc75c29.tar.bz2
rneovim-f7041625f1abe4e9bfd2461fef23d1d74dc75c29.zip
refactor(lua): use vim.fs instead of fnamemodify
Although powerful -- especially with chained modifiers --, the readability (and therefore maintainability) of `fnamemodify()` and its modifiers is often worse than a function name, giving less context and having to rely on `:h filename-modifiers`. However, it is used plenty in the Lua stdlib: - 16x for the basename: `fnamemodify(path, ':t')` - 7x for the parents: `fnamemodify(path, ':h')` - 7x for the stem (filename w/o extension): `fnamemodify(path, ':r')` - 6x for the absolute path: `fnamemodify(path, ':p')` - 2x for the suffix: `fnamemodify(path, ':e')` - 2x relative to the home directory: `fnamemodify(path, ':~')` - 1x relative to the cwd: `fnamemodify(path, ':.')` The `fs` module in the stdlib provides a cleaner interface for most of these path operations: `vim.fs.basename` instead of `':t'`, `vim.fs.dirname` instead of `':h'`, `vim.fs.abspath` instead of `':p'`. This commit refactors the runtime to use these instead of fnamemodify. Not all fnamemodify calls are removed; some have intrinsic differences in behavior with the `vim.fs` replacement or do not yet have a replacement in the Lua module, i.e. `:~`, `:.`, `:e` and `:r`.
Diffstat (limited to 'runtime/lua/vim/treesitter/dev.lua')
-rw-r--r--runtime/lua/vim/treesitter/dev.lua2
1 files changed, 1 insertions, 1 deletions
diff --git a/runtime/lua/vim/treesitter/dev.lua b/runtime/lua/vim/treesitter/dev.lua
index 589dc00fe1..246525757d 100644
--- a/runtime/lua/vim/treesitter/dev.lua
+++ b/runtime/lua/vim/treesitter/dev.lua
@@ -378,7 +378,7 @@ function M.inspect_tree(opts)
local opts_title = opts.title
if not opts_title then
local bufname = api.nvim_buf_get_name(buf)
- title = string.format('Syntax tree for %s', vim.fn.fnamemodify(bufname, ':.'))
+ title = ('Syntax tree for %s'):format(vim.fs.relpath('.', bufname))
elseif type(opts_title) == 'function' then
title = opts_title(buf)
end