aboutsummaryrefslogtreecommitdiff
path: root/env/.config/nvim/after/plugin/lsp.lua
blob: fe82dbced3a6d1696653522e9bc3f2dc0a28fa3e (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
190
191
192
193
194
195
196
197
198
199
local on_atk = function(ev)
    local opts = {buffer = ev.buf, remap = false}

    vim.keymap.set("n", "gd", function() vim.lsp.buf.definition() end, opts)
    vim.keymap.set("n", "K", function() vim.lsp.buf.hover() end, opts)
    vim.keymap.set("n", "<leader>vws", function() vim.lsp.buf.workspace_symbol() end, opts)
    vim.keymap.set("n", "<leader>vd", function() vim.diagnostic.open_float() end, opts)
    vim.keymap.set("n", "[d", function() vim.diagnostic.goto_next() end, opts)
    vim.keymap.set("n", "]d", function() vim.diagnostic.goto_prev() end, opts)
    vim.keymap.set("n", "<leader>vca", function() vim.lsp.buf.code_action() end, opts)
    vim.keymap.set("n", "<leader>vrr", function() vim.lsp.buf.references() end, opts)
    vim.keymap.set("n", "<leader>vrn", function() vim.lsp.buf.rename() end, opts)
    vim.keymap.set("i", "<C-h>", function() vim.lsp.buf.signature_help() end, opts)
end

local ok, trouble = pcall(require, 'trouble')
if ok then
    trouble.setup({ icons = {} })
    vim.keymap.set("n", "<leader>tt", "<cmd>Trouble diagnostics toggle<cr>")

    vim.keymap.set("n", "[t", function()
        trouble.next({skip_groups = true, jump = true})
    end)

    vim.keymap.set("n", "]t", function()
        trouble.prev({skip_groups = true, jump = true})
    end)
end


local ok, cmp = pcall(require, 'cmp')
if ok then
    local cmp_select = {behavior = cmp.SelectBehavior.Select}
    cmp.setup({
        snippet = {
            expand = function(args)
                require('luasnip').lsp_expand(args.body)
            end,
        },
        window = {
            completion = cmp.config.window.bordered(),
            documentation = cmp.config.window.bordered(),
        },
        mapping = cmp.mapping.preset.insert({
            ['<C-b>'] = cmp.mapping.scroll_docs(-4),
            ['<C-f>'] = cmp.mapping.scroll_docs(4),
            ['<C-e>'] = cmp.mapping.abort(),
            ['<C-p>'] = cmp.mapping.select_prev_item(cmp_select),
            ['<C-n>'] = cmp.mapping.select_next_item(cmp_select),
            ['<C-y>'] = cmp.mapping.confirm({ select = true }),
            ["<C-Space>"] = cmp.mapping.complete(),
            -- ['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept currently selected item. Set `select` to `false` to only confirm explicitly selected items.
        }),
        sources = cmp.config.sources({
            { name = 'nvim_lsp' },
            { name = 'luasnip' },
        }, {
            { name = 'buffer' },
        })
    })

    -- To use git you need to install the plugin petertriho/cmp-git and uncomment lines below
    -- Set configuration for specific filetype.
    --[[ cmp.setup.filetype('gitcommit', {
        sources = cmp.config.sources({
            { name = 'git' },
        }, {
            { name = 'buffer' },
        })
    })
    require("cmp_git").setup() ]]-- 

    -- Use buffer source for `/` and `?` (if you enabled `native_menu`, this won't work anymore).
    cmp.setup.cmdline({ '/', '?' }, {
        mapping = cmp.mapping.preset.cmdline(),
        sources = {
            { name = 'buffer' }
        }
    })

    -- Use cmdline & path source for ':' (if you enabled `native_menu`, this won't work anymore).
    cmp.setup.cmdline(':', {
        mapping = cmp.mapping.preset.cmdline(),
        sources = cmp.config.sources({
            { name = 'path' }
        }, {
            { name = 'cmdline' }
        }),
        matching = { disallow_symbol_nonprefix_matching = false }
    })
end



local ok, lsp = pcall(require, 'lspconfig')
if ok then
    vim.api.nvim_create_autocmd("FileType", {
        pattern = "src",
        callback = function()
            print("LSP should now be active for src files")
        end,
    })


    vim.diagnostic.config({
        update_in_insert = true,
        float = {
            focusable = false,
            style = "minimal",
            border = "rounded",
            source = "always",
            header = "",
            prefix = "",
        }
    })

    vim.diagnostic.config({ virtual_text = true })

    local lsp_configurations = require('lspconfig.configs')

    if not lsp_configurations.greybel then
        lsp_configurations.greybel = {
            default_config = {
                cmd = { "/bin/greybel-languageserver", "--stdio" },
                filetypes = { "greyscript" },
                root_dir = require('lspconfig.util').root_pattern(".git", vim.fn.getcwd()),
                settings = {},
            }
        }
    end


    local capabilities = vim.tbl_deep_extend(
        "force",
        {},
        vim.lsp.protocol.make_client_capabilities(),
        require('cmp_nvim_lsp').default_capabilities()
    )

    require('mason').setup({
        registries = {
            "github:mason-org/mason-registry",
        },
    })
    require('mason-nvim-dap').setup({
        ensure_installed = {
            "codelldb",
        },
        handlers = {
            function(config)
                require("mason-nvim-dap").default_setup(config)
            end,
        }
    })
    require('mason-lspconfig').setup({
        ensure_installed = {
            --"markdownlint",
            --"markdown-toc",
            "bashls",
            "clangd",
            "html",
            "cssls",
            "lua_ls",
            "rust_analyzer",
            "ts_ls",
        },
        handlers = {
            function(server_name)
                lsp[server_name].setup{capabilities = capabilities}
            end,
            ["lua_ls"] = function ()
                lsp.lua_ls.setup {
                    capabilities = capabilities,
                    settings = {
                        Lua ={
                            diagnostics = {
                                globasl = { "vim" }
                            }
                        }
                    }
                }
            end
        }
    })


    vim.filetype.add({
        extension = {
            src = "greyscript"
        }
    })

    lsp.greybel.setup({})

    vim.api.nvim_create_autocmd('LspAttach', {
        group = vim.api.nvim_create_augroup('my.lsp', {}),
        callback = on_atk
    })
end