|
1 | 1 | local M = {} |
2 | 2 |
|
3 | | -local config = require("astrolsp").config |
4 | | -local features = config.features |
| 3 | +local features = require("astrolsp").config.features |
5 | 4 |
|
6 | | -local notify = vim.notify |
| 5 | +local function ui_notify(silent, ...) return not silent and vim.notify(...) end |
7 | 6 | local function bool2str(bool) return bool and "on" or "off" end |
8 | 7 |
|
9 | 8 | --- Toggle auto format |
|
14 | 13 |
|
15 | 14 | --- Toggle buffer local auto format |
16 | 15 | ---@param bufnr? number The buffer to toggle the autoformatting of, default the current buffer |
17 | | -function M.buffer_autoformat(bufnr) |
| 16 | +---@param silent? boolean if true then don't sent a notification |
| 17 | +function M.buffer_autoformat(bufnr, silent) |
18 | 18 | bufnr = bufnr or 0 |
19 | 19 | local old_val = vim.b[bufnr].autoformat |
20 | 20 | if old_val == nil then old_val = features.autoformat end |
21 | 21 | vim.b[bufnr].autoformat = not old_val |
22 | | - notify(string.format("Buffer autoformatting %s", bool2str(vim.b[bufnr].autoformat))) |
| 22 | + ui_notify(silent, string.format("Buffer autoformatting %s", bool2str(vim.b[bufnr].autoformat))) |
23 | 23 | end |
24 | 24 |
|
25 | 25 | --- Toggle buffer LSP inlay hints |
26 | 26 | ---@param bufnr? number the buffer to toggle the clients on |
27 | | -function M.buffer_inlay_hints(bufnr) |
| 27 | +---@param silent? boolean if true then don't sent a notification |
| 28 | +function M.buffer_inlay_hints(bufnr, silent) |
28 | 29 | bufnr = bufnr or 0 |
29 | 30 | vim.b[bufnr].inlay_hints = not vim.b[bufnr].inlay_hints |
30 | 31 | -- TODO: remove check after dropping support for Neovim v0.9 |
31 | 32 | if vim.lsp.inlay_hint then |
32 | 33 | vim.lsp.inlay_hint(bufnr, vim.b[bufnr].inlay_hints) |
33 | | - notify(string.format("Inlay hints %s", bool2str(vim.b[bufnr].inlay_hints))) |
| 34 | + ui_notify(silent, string.format("Inlay hints %s", bool2str(vim.b[bufnr].inlay_hints))) |
34 | 35 | end |
35 | 36 | end |
36 | 37 |
|
37 | 38 | --- Toggle buffer semantic token highlighting for all language servers that support it |
38 | 39 | ---@param bufnr? number the buffer to toggle the clients on |
39 | | -function M.buffer_semantic_tokens(bufnr) |
| 40 | +---@param silent? boolean if true then don't sent a notification |
| 41 | +function M.buffer_semantic_tokens(bufnr, silent) |
40 | 42 | bufnr = bufnr or 0 |
41 | 43 | vim.b[bufnr].semantic_tokens = not vim.b[bufnr].semantic_tokens |
42 | | - for _, client in ipairs((vim.lsp.get_clients or vim.lsp.get_active_clients)()) do |
| 44 | + for _, client in ipairs(vim.lsp.get_clients()) do |
43 | 45 | if client.server_capabilities.semanticTokensProvider then |
44 | 46 | vim.lsp.semantic_tokens[vim.b[bufnr].semantic_tokens and "start" or "stop"](bufnr, client.id) |
45 | | - notify(string.format("Buffer lsp semantic highlighting %s", bool2str(vim.b[bufnr].semantic_tokens))) |
| 47 | + ui_notify(silent, string.format("Buffer lsp semantic highlighting %s", bool2str(vim.b[bufnr].semantic_tokens))) |
46 | 48 | end |
47 | 49 | end |
48 | 50 | end |
49 | 51 |
|
50 | 52 | --- Toggle codelens |
51 | | -function M.codelens() |
| 53 | +---@param silent? boolean if true then don't sent a notification |
| 54 | +function M.codelens(silent) |
52 | 55 | features.codelens = not features.codelens |
53 | 56 | if not features.codelens then vim.lsp.codelens.clear() end |
54 | | - notify(string.format("CodeLens %s", bool2str(features.codelens))) |
| 57 | + ui_notify(silent, string.format("CodeLens %s", bool2str(features.codelens))) |
55 | 58 | end |
56 | 59 |
|
57 | 60 | --- Toggle diagnostics |
58 | | -function M.diagnostics() |
| 61 | +---@param silent? boolean if true then don't sent a notification |
| 62 | +function M.diagnostics(silent) |
59 | 63 | features.diagnostics_mode = (features.diagnostics_mode - 1) % 4 |
60 | 64 | vim.diagnostic.config(require("astrolsp").diagnostics[features.diagnostics_mode]) |
61 | 65 | if features.diagnostics_mode == 0 then |
62 | | - notify "diagnostics off" |
| 66 | + ui_notify(silent, "diagnostics off") |
63 | 67 | elseif features.diagnostics_mode == 1 then |
64 | | - notify "only status diagnostics" |
| 68 | + ui_notify(silent, "only status diagnostics") |
65 | 69 | elseif features.diagnostics_mode == 2 then |
66 | | - notify "virtual text off" |
| 70 | + ui_notify(silent, "virtual text off") |
67 | 71 | else |
68 | | - notify "all diagnostics on" |
| 72 | + ui_notify(silent, "all diagnostics on") |
69 | 73 | end |
70 | 74 | end |
71 | 75 |
|
|
0 commit comments