-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathusercommands.nix
76 lines (72 loc) · 2.15 KB
/
usercommands.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
{
userCommands = {
FormatDisable = {
bang = true;
command.__raw = ''
function(args)
if args.bang then
-- FormatDisable! will disable formatting just for this buffer
vim.b.disable_autoformat = true
else
vim.g.disable_autoformat = true
end
end
'';
desc = "Disable automatic formatting on save";
};
FormatEnable = {
bang = true;
command.__raw = ''
function(args)
if args.bang then
-- FormatEnable! will enable formatting just for this buffer
vim.b.disable_autoformat = false
else
vim.g.disable_autoformat = false
end
end
'';
desc = "Enable automatic formatting on save";
};
FormatToggle = {
bang = true;
command.__raw = ''
function(args)
if args.bang then
-- Toggle formatting for current buffer
vim.b.disable_autoformat = not vim.b.disable_autoformat
else
-- Toggle formatting globally
vim.g.disable_autoformat = not vim.g.disable_autoformat
end
end
'';
desc = "Toggle automatic formatting on save";
};
# Takes an argument that determines what method to use for buf_request
PeekDefinition = {
nargs = 1;
command.__raw = ''
function(opts)
local function preview_location_callback(_, result)
if result == nil or vim.tbl_isempty(result) then
vim.notify('No location found to preview')
return nil
end
if not result[1] then
vim.notify('Cant peek location')
return nil
end
local buf, _ = vim.lsp.util.preview_location(result[1])
if buf then
local cur_buf = vim.api.nvim_get_current_buf()
vim.bo[buf].filetype = vim.bo[cur_buf].filetype
end
end
local params = vim.lsp.util.make_position_params()
return vim.lsp.buf_request(0, opts.fargs[1], params, preview_location_callback)
end
'';
};
};
}