-
Notifications
You must be signed in to change notification settings - Fork 87
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: Add format instead of only prefix for labels #46
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,13 +7,33 @@ local namespace = api.nvim_create_namespace("flutter_tools_closing_labels") | |
local function render_labels(labels, opts) | ||
api.nvim_buf_clear_namespace(0, namespace, 0, -1) | ||
opts = opts or {} | ||
local highlight = opts and opts.highlight or "Comment" | ||
local prefix = opts and opts.prefix or "// " | ||
local highlight = opts.highlight or "Comment" | ||
|
||
-- Have ot use `rawget` to override what the default format is that we provide in config. | ||
local user_format = rawget(opts, "format") | ||
|
||
local prefix = opts.prefix | ||
if prefix and user_format then | ||
error( | ||
"[flutter-tools.labels] Cannot have both prefix and format specified" .. vim.inspect(opts) | ||
) | ||
end | ||
|
||
-- A bit complicated, but basically just keeps backwards compat of passing "prefix" | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'd actually rather break this (mean as that sounds) whilst this plugin is still fairly small/doesn't have that many users so I can keep things as simple as possible. I think if the user has overridden |
||
-- while still allowing users to pass "format" instead. | ||
local format | ||
if user_format then | ||
format = user_format | ||
elseif prefix then | ||
format = prefix .. "%s" | ||
else | ||
format = opts.format | ||
end | ||
|
||
for _, item in ipairs(labels) do | ||
local line = item.range["end"].line | ||
api.nvim_buf_set_virtual_text(0, namespace, tonumber(line), { | ||
{ prefix .. item.label, highlight }, | ||
{ string.format(format, item.label), highlight }, | ||
}, {}) | ||
end | ||
end | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The
config
module actually already has a mechanism for deprecations, you just need to specify what the fallback key is and the message to show the userhttps://github.com/akinsho/flutter-tools.nvim/blob/a2a67dae9ff43d95caddf4d68cf5afcd4cb9d65d/lua/flutter-tools/config.lua#L61