fix: add type annotations, improve code structure, autocmd groupped#2
fix: add type annotations, improve code structure, autocmd groupped#2DrKJeff16 wants to merge 4 commits intoJ-Cowsert:masterfrom
Conversation
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
| args = {}, | ||
| compile_commands = true, -- auto-detect flags from compile_commands.json | ||
| } | ||
| M.augroup = vim.api.nvim_create_augroup("ClassLayout", { clear = true }) |
There was a problem hiding this comment.
Was not sure how to declare the augroup, but I decided to make it part of the module PROVISIONALLY since I'm planning to introduce another autocmd in another PR.
The aforementioned future PR will not be created unless this PR gets (partially) merged.
| keymap = "<leader>cl", | ||
| compiler = "clang", | ||
| args = {}, | ||
| compile_commands = true, -- auto-detect flags from compile_commands.json | ||
| } | ||
| M.augroup = vim.api.nvim_create_augroup("ClassLayout", { clear = true }) | ||
|
|
||
| --- @class ClassLayoutOpts | ||
| --- @field args? string[] | ||
| --- @field compile_commands? boolean | ||
| --- @field compiler? string | ||
| --- @field keymap? string | ||
|
|
||
| ---@return ClassLayoutOpts defaults | ||
| local function get_defaults() | ||
| return { | ||
| keymap = "<leader>cl", | ||
| compiler = "clang", | ||
| args = {}, | ||
| compile_commands = true, -- auto-detect flags from compile_commands.json | ||
| } | ||
| end |
There was a problem hiding this comment.
I'll explain my reasoning: If you wish to have default values, they should be as immutable as possible (i.e. users shouldn't be able to tamper with it). Best solution is to make a wrapper that returns the table.
| local dir = vim.fn.fnamemodify(start_path, ":h") | ||
| local prev = nil | ||
| while dir and dir ~= prev do | ||
| local candidate = vim.fs.joinpath(dir, "compile_commands.json") |
There was a problem hiding this comment.
Using vim.fs.joinpath() is a saner solution, in my opinion.
Signed-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
| prev = dir | ||
| dir = vim.fn.fnamemodify(dir, ":h") | ||
| end | ||
| return nil |
There was a problem hiding this comment.
Doing return nil on its own is redundant and unnecessary. This of course doesn't apply to, say, multiple returs:
function foo()
-- ...
return nil, 1, "foo"
endSigned-off-by: Guennadi Maximov C <g.maxc.fox@protonmail.com>
Changes
ClassLayout), as recommended.The plugin works as intended, no errors have been introduced, to my knowledge.
Any feedback would be appreciated!
classlayout.mp4