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

Commit 892004f

Browse files
authored
Merge pull request #139 from m-lima/on_initialized
Add on_initialized hook
2 parents b94d8bb + e3de082 commit 892004f

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

README.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ local opts = {
141141
-- options right now: termopen / quickfix
142142
executor = require("rust-tools/executors").termopen,
143143

144+
-- callback to execute once rust-analyzer is done initializing the workspace
145+
-- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error"
146+
on_initialized = nil,
147+
144148
runnables = {
145149
-- whether to use telescope for selection menu or not
146150
use_telescope = true

lua/rust-tools/config.lua

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@ local defaults = {
2525
-- options right now: termopen / quickfix
2626
executor = require("rust-tools/executors").termopen,
2727

28+
-- callback to execute once rust-analyzer is done initializing the workspace
29+
-- The callback receives one parameter indicating the `health` of the server: "ok" | "warning" | "error"
30+
on_initialized = nil,
31+
2832
-- These apply to the default RustSetInlayHints command
2933
inlay_hints = {
3034

lua/rust-tools/server_status.lua

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,14 @@ local inlay = require("rust-tools.inlay_hints")
44
local M = {}
55

66
function M.handler(_, result)
7-
if result.quiescent and config.options.tools.autoSetHints and not M.ran_once then
8-
inlay.set_inlay_hints()
9-
require("rust-tools.inlay_hints").setup_autocmd()
7+
if result.quiescent and not M.ran_once then
8+
if config.options.tools.autoSetHints then
9+
inlay.set_inlay_hints()
10+
require("rust-tools.inlay_hints").setup_autocmd()
11+
end
12+
if config.options.tools.on_initialized then
13+
config.options.tools.on_initialized(result)
14+
end
1015
M.ran_once = true
1116
end
1217
end

0 commit comments

Comments
 (0)