Skip to content

Commit

Permalink
feat(on typing assist): Adds support for r-a's on typing assist
Browse files Browse the repository at this point in the history
  • Loading branch information
Ciel-MC committed Dec 19, 2023
1 parent 9e654bc commit 8982087
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
3 changes: 3 additions & 0 deletions lua/rust-tools/config.lua
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ M.options = {
-- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error"
on_initialized = nil,

-- https://rust-analyzer.github.io/manual.html#on-typing-assists
on_type_formatting = true,

-- automatically call RustReloadWorkspace when writing to a Cargo.toml file.
reload_workspace_from_cargo_toml = true,

Expand Down
4 changes: 4 additions & 0 deletions lua/rust-tools/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ local M = {
join_lines = nil,
lsp = nil,
move_item = nil,
on_type_formatting = nil,
open_cargo_toml = nil,
parent_module = nil,
runnables = nil,
Expand Down Expand Up @@ -107,6 +108,9 @@ function M.setup(opts)
local move_item = require("rust-tools.move_item")
M.move_item = move_item

local on_type_formatting = require("rust-tools.on_type_formatting")
M.on_type_formatting = on_type_formatting

local open_cargo_toml = require("rust-tools.open_cargo_toml")
M.open_cargo_toml = open_cargo_toml

Expand Down
15 changes: 11 additions & 4 deletions lua/rust-tools/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,26 @@ local server_status = require("rust-tools.server_status")

local M = {}

local function setup_autocmds()
local group = vim.api.nvim_create_augroup("RustToolsAutocmds", { clear = true })
M.group = vim.api.nvim_create_augroup("RustToolsAutocmds", { clear = true })

local function setup_autocmds()
if rt.config.options.tools.reload_workspace_from_cargo_toml then
vim.api.nvim_create_autocmd("BufWritePost", {
pattern = "*/Cargo.toml",
callback = require('rust-tools.workspace_refresh')._reload_workspace_from_cargo_toml,
group = group,
group = M.group,
})
end

vim.api.nvim_create_autocmd("VimEnter", {
pattern = "*.rs",
callback = rt.lsp.start_standalone_if_required,
group = group,
group = M.group,
});

if rt.config.options.tools.on_type_formatting then
require("rust-tools.on_type_formatting").setup_on_type_assist()
end
end

local function setup_commands()
Expand Down Expand Up @@ -137,6 +141,9 @@ local function setup_capabilities()

-- snippets
capabilities.textDocument.completion.completionItem.snippetSupport = true
capabilities.textDocument.onTypeFormatting = {
dynamicRegistration = true,
}

-- send actions with hover request
capabilities.experimental = {
Expand Down

0 comments on commit 8982087

Please sign in to comment.