Skip to content

Instantly share code, notes, and snippets.

@semanticart
Created December 31, 2021 16:34
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save semanticart/7f2f838b41521a6d20ca50eda6458969 to your computer and use it in GitHub Desktop.
An example code action for null-ls.nvim
local frozen_string_actions = {
method = null_ls.methods.CODE_ACTION,
filetypes = {"ruby"},
generator = {
fn = function(context)
frozen_string_literal_comment = "# frozen_string_literal: true"
first_line = context.content[1]
if first_line ~= frozen_string_literal_comment then
return {
{
title = "🥶Add frozen string literal comment",
action = function()
lines = {
frozen_string_literal_comment, "", first_line
}
vim.api.nvim_buf_set_lines(context.bufnr, 0, 1,
false, lines)
end
}
}
end
end
}
}
null_ls.register(frozen_string_actions)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment