Skip to content
This repository has been archived by the owner on Jan 3, 2024. It is now read-only.

Commit

Permalink
feat: Allow custom func for handling snippet text edits
Browse files Browse the repository at this point in the history
  • Loading branch information
simrat39 committed Sep 9, 2022
1 parent c89096b commit 95a6f90
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 3 deletions.
3 changes: 3 additions & 0 deletions lua/rust-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ local defaults = {
-- options right now: termopen / quickfix
executor = require("rust-tools/executors").termopen,

-- function to expand snippets
snippet_func = nil,

-- callback to execute once rust-analyzer is done initializing the workspace
-- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error"
on_initialized = nil,
Expand Down
17 changes: 14 additions & 3 deletions lua/rust-tools/utils/utils.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
local rt = require("rust-tools")

local M = {}

function M.is_windows()
Expand Down Expand Up @@ -65,10 +67,20 @@ function M.resize(vertical, amount)
end

function M.override_apply_text_edits()
local override = nil
if rt.config.options.tools.snippet_func then
print("here")
override = rt.config.options.tools.snippet_func
else
override = function(edits, bufnr, offset_encoding, old)
M.snippet_text_edits_to_text_edits(edits)
old(edits, bufnr, offset_encoding)
end
end

local old_func = vim.lsp.util.apply_text_edits
vim.lsp.util.apply_text_edits = function(edits, bufnr, offset_encoding)
M.snippet_text_edits_to_text_edits(edits)
old_func(edits, bufnr, offset_encoding)
override(edits, bufnr, offset_encoding, old_func)
end
end

Expand Down Expand Up @@ -132,7 +144,6 @@ function M.is_ra_server(client)
or client.name == "rust_analyzer-standalone"
end


-- sanitize_command_for_debugging substitudes the command arguments so it can be used to run a
-- debugger.
--
Expand Down

0 comments on commit 95a6f90

Please sign in to comment.