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

Commit 95a6f90

Browse files
committed
feat: Allow custom func for handling snippet text edits
1 parent c89096b commit 95a6f90

File tree

2 files changed

+17
-3
lines changed

2 files changed

+17
-3
lines changed

lua/rust-tools/config.lua

+3
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,9 @@ local defaults = {
1414
-- options right now: termopen / quickfix
1515
executor = require("rust-tools/executors").termopen,
1616

17+
-- function to expand snippets
18+
snippet_func = nil,
19+
1720
-- callback to execute once rust-analyzer is done initializing the workspace
1821
-- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error"
1922
on_initialized = nil,

lua/rust-tools/utils/utils.lua

+14-3
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
local rt = require("rust-tools")
2+
13
local M = {}
24

35
function M.is_windows()
@@ -65,10 +67,20 @@ function M.resize(vertical, amount)
6567
end
6668

6769
function M.override_apply_text_edits()
70+
local override = nil
71+
if rt.config.options.tools.snippet_func then
72+
print("here")
73+
override = rt.config.options.tools.snippet_func
74+
else
75+
override = function(edits, bufnr, offset_encoding, old)
76+
M.snippet_text_edits_to_text_edits(edits)
77+
old(edits, bufnr, offset_encoding)
78+
end
79+
end
80+
6881
local old_func = vim.lsp.util.apply_text_edits
6982
vim.lsp.util.apply_text_edits = function(edits, bufnr, offset_encoding)
70-
M.snippet_text_edits_to_text_edits(edits)
71-
old_func(edits, bufnr, offset_encoding)
83+
override(edits, bufnr, offset_encoding, old_func)
7284
end
7385
end
7486

@@ -132,7 +144,6 @@ function M.is_ra_server(client)
132144
or client.name == "rust_analyzer-standalone"
133145
end
134146

135-
136147
-- sanitize_command_for_debugging substitudes the command arguments so it can be used to run a
137148
-- debugger.
138149
--

0 commit comments

Comments
 (0)