Skip to content

Commit

Permalink
feat(texlab): add change environments workspace command (#3227)
Browse files Browse the repository at this point in the history
* feat(texlab): add change environments workspace command

* feat(texlab): correct tostring placement
  • Loading branch information
DimitrisDimitropoulos authored Jul 3, 2024
1 parent 53a3c64 commit 9c9470f
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions lua/lspconfig/server_configurations/texlab.lua
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,28 @@ local function buf_find_envs(bufnr)
end, bufnr)
end

local function buf_change_env(bufnr)
bufnr = util.validate_bufnr(bufnr)
if not util.get_active_client_by_name(bufnr, 'texlab') then
return vim.notify('Texlab client not found', vim.log.levels.ERROR)
end
local new = vim.fn.input 'Enter the new environment name: '
if not new or new == '' then
return vim.notify('No environment name provided', vim.log.levels.WARN)
end
local pos = vim.api.nvim_win_get_cursor(0)
vim.lsp.buf.execute_command {
command = 'texlab.changeEnvironment',
arguments = {
{
textDocument = { uri = vim.uri_from_bufnr(bufnr) },
position = { line = pos[1] - 1, character = pos[2] },
newName = tostring(new),
},
},
}
end

-- bufnr isn't actually required here, but we need a valid buffer in order to
-- be able to find the client for buf_request.
-- TODO find a client by looking through buffers for a valid client?
Expand Down Expand Up @@ -214,6 +236,12 @@ return {
end,
description = 'Find the environments at current position',
},
TexlabChangeEnvironment = {
function()
buf_change_env(0)
end,
description = 'Change the environment at current position',
},
},
docs = {
description = [[
Expand Down

0 comments on commit 9c9470f

Please sign in to comment.