Skip to content

Commit a94e3eb

Browse files
author
RahatMelsov
committed
feat: golang lsp
1 parent dd80e39 commit a94e3eb

File tree

3 files changed

+75
-85
lines changed

3 files changed

+75
-85
lines changed

init.lua

Lines changed: 23 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,7 @@ require('lazy').setup({
380380
vim.keymap.set('n', '<leader>wl', '<C-w>l', { desc = '[W]indow Right' })
381381
vim.keymap.set('n', '<leader>wq', '<C-w>q', { desc = '[W]indow Quit' })
382382
vim.keymap.set('n', '<leader>w=', '<C-w>=', { desc = '[W]indow Equalize' })
383+
vim.keymap.set('n', '<leader>e', ':Neotree toggle<CR>', { desc = 'Toggle Neotree' })
383384

384385
-- Slightly advanced example of overriding default behavior and theme
385386
vim.keymap.set('n', '<leader>/', function()
@@ -423,57 +424,18 @@ require('lazy').setup({
423424
-- Main LSP Configuration
424425
'neovim/nvim-lspconfig',
425426
dependencies = {
426-
-- Automatically install LSPs and related tools to stdpath for Neovim
427-
-- Mason must be loaded before its dependents so we need to set it up here.
428-
-- NOTE: `opts = {}` is the same as calling `require('mason').setup({})`
429427
{ 'mason-org/mason.nvim', opts = {} },
430428
'mason-org/mason-lspconfig.nvim',
431429
'WhoIsSethDaniel/mason-tool-installer.nvim',
432430

433-
-- Useful status updates for LSP.
434431
{ 'j-hui/fidget.nvim', opts = {} },
435432

436-
-- Allows extra capabilities provided by blink.cmp
437433
'saghen/blink.cmp',
438434
},
439435
config = function()
440-
-- Brief aside: **What is LSP?**
441-
--
442-
-- LSP is an initialism you've probably heard, but might not understand what it is.
443-
--
444-
-- LSP stands for Language Server Protocol. It's a protocol that helps editors
445-
-- and language tooling communicate in a standardized fashion.
446-
--
447-
-- In general, you have a "server" which is some tool built to understand a particular
448-
-- language (such as `gopls`, `lua_ls`, `rust_analyzer`, etc.). These Language Servers
449-
-- (sometimes called LSP servers, but that's kind of like ATM Machine) are standalone
450-
-- processes that communicate with some "client" - in this case, Neovim!
451-
--
452-
-- LSP provides Neovim with features like:
453-
-- - Go to definition
454-
-- - Find references
455-
-- - Autocompletion
456-
-- - Symbol Search
457-
-- - and more!
458-
--
459-
-- Thus, Language Servers are external tools that must be installed separately from
460-
-- Neovim. This is where `mason` and related plugins come into play.
461-
--
462-
-- If you're wondering about lsp vs treesitter, you can check out the wonderfully
463-
-- and elegantly composed help section, `:help lsp-vs-treesitter`
464-
465-
-- This function gets run when an LSP attaches to a particular buffer.
466-
-- That is to say, every time a new file is opened that is associated with
467-
-- an lsp (for example, opening `main.rs` is associated with `rust_analyzer`) this
468-
-- function will be executed to configure the current buffer
469436
vim.api.nvim_create_autocmd('LspAttach', {
470437
group = vim.api.nvim_create_augroup('kickstart-lsp-attach', { clear = true }),
471438
callback = function(event)
472-
-- NOTE: Remember that Lua is a real programming language, and as such it is possible
473-
-- to define small helper and utility functions so you don't have to repeat yourself.
474-
--
475-
-- In this case, we create a function that lets us more easily define mappings specific
476-
-- for LSP related items. It sets the mode, buffer and description for us each time.
477439
local map = function(keys, func, desc, mode)
478440
mode = mode or 'n'
479441
vim.keymap.set(mode, keys, func, { buffer = event.buf, desc = 'LSP: ' .. desc })
@@ -543,12 +505,24 @@ require('lazy').setup({
543505
callback = vim.lsp.buf.document_highlight,
544506
})
545507

508+
vim.api.nvim_create_autocmd('BufWritePre', {
509+
pattern = '*.go',
510+
callback = function()
511+
vim.cmd 'silent! !gofmt -w %'
512+
end,
513+
})
546514
vim.api.nvim_create_autocmd({ 'CursorMoved', 'CursorMovedI' }, {
547515
buffer = event.buf,
548516
group = highlight_augroup,
549517
callback = vim.lsp.buf.clear_references,
550518
})
551519

520+
vim.api.nvim_create_autocmd('CursorHold', {
521+
callback = function()
522+
vim.diagnostic.open_float(nil, { focusable = false })
523+
end,
524+
})
525+
552526
vim.api.nvim_create_autocmd('LspDetach', {
553527
group = vim.api.nvim_create_augroup('kickstart-lsp-detach', { clear = true }),
554528
callback = function(event2)
@@ -616,18 +590,6 @@ require('lazy').setup({
616590
-- For example, to see the options for `lua_ls`, you could go to: https://luals.github.io/wiki/settings/
617591
local servers = {
618592
-- clangd = {},
619-
-- gopls = {},
620-
-- pyright = {},
621-
-- rust_analyzer = {},
622-
-- ... etc. See `:help lspconfig-all` for a list of all the pre-configured LSPs
623-
--
624-
-- Some languages (like typescript) have entire language plugins that can be useful:
625-
-- https://github.com/pmizio/typescript-tools.nvim
626-
--
627-
-- But for many setups, the LSP (`ts_ls`) will work just fine
628-
-- ts_ls = {},
629-
--
630-
631593
lua_ls = {
632594
-- cmd = { ... },
633595
-- filetypes = { ... },
@@ -828,11 +790,11 @@ require('lazy').setup({
828790
-- change the command in the config to whatever the name of that colorscheme is.
829791
--
830792
-- If you want to see what colorschemes are already installed, you can use `:Telescope colorscheme`.
831-
'folke/tokyonight.nvim',
793+
'thesimonho/kanagawa-paper.nvim',
832794
priority = 1000, -- Make sure to load this before all the other start plugins.
833795
config = function()
834796
---@diagnostic disable-next-line: missing-fields
835-
require('tokyonight').setup {
797+
require('kanagawa-paper').setup {
836798
styles = {
837799
comments = { italic = false }, -- Disable italics in comments
838800
},
@@ -841,7 +803,14 @@ require('lazy').setup({
841803
-- Load the colorscheme here.
842804
-- Like many other themes, this one has different styles, and you could load
843805
-- any other, such as 'tokyonight-storm', 'tokyonight-moon', or 'tokyonight-day'.
844-
vim.cmd.colorscheme 'tokyonight-night'
806+
vim.cmd.colorscheme 'kanagawa-paper'
807+
808+
vim.api.nvim_set_hl(0, 'Normal', { bg = 'none' })
809+
vim.api.nvim_set_hl(0, 'NormalNC', { bg = 'none' })
810+
vim.api.nvim_set_hl(0, 'NormalFloat', { bg = 'none' })
811+
vim.api.nvim_set_hl(0, 'FloatBorder', { bg = 'none' })
812+
vim.api.nvim_set_hl(0, 'SignColumn', { bg = 'none' })
813+
vim.api.nvim_set_hl(0, 'VertSplit', { bg = 'none' })
845814
end,
846815
},
847816

lua/custom/plugins/init.lua

Lines changed: 39 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -5,38 +5,46 @@
55
-- Bootstrap lazy.nvim
66
return {
77
{
8-
{
9-
'ray-x/go.nvim',
10-
dependencies = {
11-
'ray-x/guihua.lua', -- required UI library
12-
'nvim-treesitter/nvim-treesitter',
13-
'neovim/nvim-lspconfig',
14-
},
15-
ft = { 'go', 'gomod' },
16-
config = function()
17-
require('go').setup {
18-
lsp_cfg = true, -- auto-setup gopls
19-
lsp_on_attach = function(client, bufnr)
20-
-- Auto format on save
21-
if client.server_capabilities.documentFormattingProvider then
22-
vim.api.nvim_create_autocmd('BufWritePre', {
23-
group = vim.api.nvim_create_augroup('GoFormat', { clear = true }),
24-
buffer = bufnr,
25-
callback = function()
26-
vim.lsp.buf.format { async = false }
27-
end,
28-
})
29-
end
30-
end,
31-
}
32-
end,
8+
'nvim-neo-tree/neo-tree.nvim',
9+
branch = 'v3.x',
10+
dependencies = {
11+
'nvim-lua/plenary.nvim',
12+
'MunifTanjim/nui.nvim',
13+
'nvim-tree/nvim-web-devicons', -- optional, but recommended
3314
},
34-
{
35-
'windwp/nvim-autopairs',
36-
event = 'InsertEnter',
37-
config = true,
38-
-- use opts = {} for passing setup options
39-
-- this is equivalent to setup({}) function
15+
lazy = false, -- neo-tree will lazily load itself
16+
},
17+
{
18+
'ray-x/go.nvim',
19+
dependencies = {
20+
'ray-x/guihua.lua', -- required UI library
21+
'nvim-treesitter/nvim-treesitter',
22+
'neovim/nvim-lspconfig',
4023
},
24+
ft = { 'go', 'gomod' },
25+
config = function()
26+
require('go').setup {
27+
lsp_cfg = true, -- auto-setup gopls
28+
lsp_on_attach = function(client, bufnr)
29+
-- Auto format on save
30+
if client.server_capabilities.documentFormattingProvider then
31+
vim.api.nvim_create_autocmd('BufWritePre', {
32+
group = vim.api.nvim_create_augroup('GoFormat', { clear = true }),
33+
buffer = bufnr,
34+
callback = function()
35+
vim.lsp.buf.format { async = false }
36+
end,
37+
})
38+
end
39+
end,
40+
}
41+
end,
42+
},
43+
{
44+
'windwp/nvim-autopairs',
45+
event = 'InsertEnter',
46+
config = true,
47+
-- use opts = {} for passing setup options
48+
-- this is equivalent to setup({}) function
4149
},
4250
}

lua/kickstart/plugins/lsp.lua

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
lspconfig.gopls.setup {
2+
capabilities = capabilities,
3+
on_attach = on_attach,
4+
settings = {
5+
gopls = {
6+
completeUnimported = true,
7+
usePlaceholders = true,
8+
analyses = {
9+
unusedparams = true,
10+
},
11+
},
12+
},
13+
}

0 commit comments

Comments
 (0)