-
Notifications
You must be signed in to change notification settings - Fork 2
Custom command to run test in terminal #24
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
Conversation
b66074a
to
da9d990
Compare
@@ -180,6 +180,16 @@ ruby_lsp.setup = function(config) | |||
|
|||
local server_started = false | |||
|
|||
-- TODO: Do I like this here? | |||
vim.api.nvim_create_autocmd('LspAttach', { |
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 example given in the nvim docs triggers a refresh on BufEnter,CursorHold,InsertLeave
. I'm not sure how much of a performance hit this would be. If you go this route, it would make sense to create buffer-local autocmds, or use a pattern filter.
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.
Somthing like
vim.api.nvim_create_autocmd({ 'BufEnter', 'CursorHold', 'InsertLeave' }, {
pattern = { '*.rb' },
callback = function(args)
vim.lsp.codelens.refresh({ bufnr = args.buf })
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.
This is likely more appropriate. Let's go with it!
end | ||
|
||
vim.lsp.commands['rubyLsp.debugTest'] = function(command) | ||
vim.cmd(':terminal ' .. command.arguments[3]) |
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.
How about, for now:
vim.notify('"Debug" is not yet implemented', vim.log.levels.INFO)
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.
Alternately, we could filter out unsupported commands. I think having "run" and "run in terminal" as two different commands doesn't make sense in nvim the way it does in VS Code. This seems to be working for me, only displaying the "run" virtual text, and running the command when I do vim.lsp.codelens.run()
, without asking me to choose a command:
local original_codelens_handler = vim.lsp.codelens.on_codelens
local supported_commands = {
["rubyLsp.runTest"] = true,
}
vim.lsp.codelens.on_codelens = function(err, result, ctx)
local client = vim.lsp.get_client_by_id(ctx.client_id)
if client.name ~= "ruby_lsp" then return original_codelens_handler(err, result, ctx) end
local filtered_result = vim.tbl_filter(function(lens)
return lens.command and supported_commands[lens.command.command]
end, result or {})
return original_codelens_handler(err, filtered_result, ctx)
end
What do you think?
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.
Filtering supported commands is a great idea.
We can also support the migration task: vim.lsp.commands["rubyLsp.runTask"] = function(command)
vim.cmd(":split | terminal " .. command.arguments[1])
end |
Then on a test