mirror of
https://github.com/nvim-treesitter/nvim-treesitter.git
synced 2026-07-01 19:17:02 -04:00
have to default to global shiftwidth
This commit is contained in:
parent
cd1cd54849
commit
ed14c4d855
1 changed files with 9 additions and 3 deletions
|
|
@ -107,8 +107,11 @@ end, function(bufnr, root, lang)
|
|||
return tostring(bufnr) .. root:id() .. '_' .. lang
|
||||
end)
|
||||
|
||||
---@param bufnr integer
|
||||
---@param lang string
|
||||
---@return integer
|
||||
local get_language_shiftwidth = memoize(function(bufnr, lang)
|
||||
local buffer_shiftwidth = vim.bo.shiftwidth
|
||||
---@type integer
|
||||
local global_shiftwidth = vim.go.shiftwidth
|
||||
-- See :h 'shiftwidth': If set to 0, should use tabstop (0 is not the default value,
|
||||
-- but users may rely on this behavior)
|
||||
|
|
@ -119,16 +122,19 @@ local get_language_shiftwidth = memoize(function(bufnr, lang)
|
|||
global_shiftwidth = vim.bo.tabstop
|
||||
end
|
||||
|
||||
---@type integer|nil
|
||||
local lang_shiftwidth = nil
|
||||
-- Note: get_filetypes(lang) always includes `lang` in the returned array of filetypes even if
|
||||
-- `lang` is not a filetype
|
||||
---@type string[]
|
||||
local filetypes = vim.treesitter.language.get_filetypes(lang)
|
||||
for _, ft in ipairs(filetypes) do
|
||||
-- filetype.get_option will default to the global value for the option
|
||||
-- if (1) there is no local equivalent set, or (2) the filetype does not exist
|
||||
---@type integer
|
||||
local filetype_shiftwidth = vim.filetype.get_option(ft, 'shiftwidth')
|
||||
if filetype_shiftwidth == 0 then
|
||||
filetype_shiftwidth = vim.filetype.get_option(ft, 'tabstop')
|
||||
filetype_shiftwidth = vim.filetype.get_option(ft, 'tabstop')--[[@as integer]]
|
||||
end
|
||||
if filetype_shiftwidth ~= global_shiftwidth then
|
||||
lang_shiftwidth = filetype_shiftwidth
|
||||
|
|
@ -137,7 +143,7 @@ local get_language_shiftwidth = memoize(function(bufnr, lang)
|
|||
|
||||
-- if lang_shiftwidth is nil, then it is either unset OR it is the same as
|
||||
-- global_shiftwidth
|
||||
return lang_shiftwidth or global_shiftwidth or buffer_shiftwidth
|
||||
return lang_shiftwidth or global_shiftwidth
|
||||
end, function(bufnr, lang)
|
||||
return tostring(bufnr) .. '_' .. lang
|
||||
end)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue