summaryrefslogtreecommitdiff
path: root/.config/nvim/lua/_utils/init.lua
blob: 4d5c890fe4f4550f243a886445e1ba9b5c77ef82 (plain)
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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
local nv_utils = {}

function nv_utils.define_augroups(definitions) -- {{{1
    -- Create autocommand groups based on the passed definitions
    --
    -- The key will be the name of the group, and each definition
    -- within the group should have:
    --    1. Trigger
    --    2. Pattern
    --    3. Text
    -- just like how they would normally be defined from Vim itself
    for group_name, definition in pairs(definitions) do
        vim.cmd('augroup ' .. group_name)
        vim.cmd('autocmd!')

        for _, def in pairs(definition) do
            local command = table.concat(vim.tbl_flatten {'autocmd', def}, ' ')
            vim.cmd(command)
        end

        vim.cmd('augroup END')
    end
end

-- lsp

function nv_utils.add_to_workspace_folder()
    vim.lsp.buf.add_workspace_folder()
end

function nv_utils.clear_references()
    vim.lsp.buf.clear_references()
end

function nv_utils.code_action()
    vim.lsp.buf.code_action()
end

function nv_utils.declaration()
    vim.lsp.buf.declaration()
    vim.lsp.buf.clear_references()
end

function nv_utils.definition()
    vim.lsp.buf.definition()
    vim.lsp.buf.clear_references()
end

function nv_utils.document_highlight()
    vim.lsp.buf.document_highlight()
end

function nv_utils.document_symbol()
    vim.lsp.buf.document_symbol()
end

function nv_utils.formatting()
    vim.lsp.buf.formatting()
end

function nv_utils.formatting_sync()
    vim.lsp.buf.formatting_sync()
end

function nv_utils.hover()
    vim.lsp.buf.hover()
end

function nv_utils.implementation()
    vim.lsp.buf.implementation()
end

function nv_utils.incoming_calls()
    vim.lsp.buf.incoming_calls()
end

function nv_utils.list_workspace_folders()
    vim.lsp.buf.list_workspace_folders()
end

function nv_utils.outgoing_calls()
    vim.lsp.buf.outgoing_calls()
end

function nv_utils.range_code_action()
    vim.lsp.buf.range_code_action()
end

function nv_utils.range_formatting()
    vim.lsp.buf.range_formatting()
end

function nv_utils.references()
    vim.lsp.buf.references()
    vim.lsp.buf.clear_references()
end

function nv_utils.remove_workspace_folder()
    vim.lsp.buf.remove_workspace_folder()
end

function nv_utils.rename()
    vim.lsp.buf.rename()
end

function nv_utils.signature_help()
    vim.lsp.buf.signature_help()
end

function nv_utils.type_definition()
    vim.lsp.buf.type_definition()
end

function nv_utils.workspace_symbol()
    vim.lsp.buf.workspace_symbol()
end

-- diagnostic

function nv_utils.get_all()
    vim.lsp.diagnostic.get_all()
end

function nv_utils.get_next()
    vim.lsp.diagnostic.get_next()
end

function nv_utils.get_prev()
    vim.lsp.diagnostic.get_prev()
end

function nv_utils.goto_next()
    vim.lsp.diagnostic.goto_next()
end

function nv_utils.goto_prev()
    vim.lsp.diagnostic.goto_prev()
end

function nv_utils.show_line_diagnostics()
    vim.lsp.diagnostic.show_line_diagnostics()
end

-- git signs

function nv_utils.next_hunk()
    require('gitsigns').next_hunk()
end

function nv_utils.prev_hunk()
    require('gitsigns').prev_hunk()
end

function nv_utils.stage_hunk()
    require('gitsigns').stage_hunk()
end

function nv_utils.undo_stage_hunk()
    require('gitsigns').undo_stage_hunk()
end

function nv_utils.reset_hunk()
    require('gitsigns').reset_hunk()
end

function nv_utils.reset_buffer()
    require('gitsigns').reset_buffer()
end

function nv_utils.preview_hunk()
    require('gitsigns').preview_hunk()
end

function nv_utils.blame_line()
    require('gitsigns').blame_line()
end

-- misc
function nv_utils.file_exists(name)
    local f = io.open(name, "r")
    if f ~= nil then
        io.close(f)
        return true
    else
        return false
    end
end

return nv_utils