Skip to content

Commit

Permalink
go
Browse files Browse the repository at this point in the history
  • Loading branch information
Thiago-Assis-T committed Aug 29, 2023
1 parent e137b01 commit 56d30a0
Show file tree
Hide file tree
Showing 7 changed files with 85 additions and 58 deletions.
109 changes: 56 additions & 53 deletions lua/plugins/lsp/formatter.lua
Original file line number Diff line number Diff line change
Expand Up @@ -4,62 +4,65 @@ local api = vim.api

-- Creating Format on Save functionality:
api.nvim_create_autocmd('BufWritePre', {
callback = function()
vim.schedule(function()
cmd('FormatWrite')
end)
end,
callback = function()
vim.schedule(function()
cmd('FormatWrite')
end)
end,
})

-- Provides the Format, FormatWrite, FormatLock, and FormatWriteLock commands
require('formatter').setup({
-- Enable or disable logging
logging = false,
-- Set the log level
log_level = vim.log.levels.WARN,
-- All formatter configurations are opt-in
filetype = {
-- Formatter configurations for filetype "lua" go here
-- and will be executed in order
lua = {
-- "formatter.filetypes.lua" defines default configurations for the
-- "lua" filetype
require('formatter.filetypes.lua').stylua,
},
html = {
require('formatter.filetypes.html').prettierd,
},
css = {
require('formatter.filetypes.css').prettierd,
},
javascript = {
require('formatter.filetypes.javascript').eslint_d,
},
javascriptreact = {
require('formatter.filetypes.javascriptreact').eslint_d,
},
typescript = {
require('formatter.filetypes.typescript').eslint_d,
},
typescriptreact = {
require('formatter.filetypes.typescriptreact').eslint_d,
},
json = {
require('formatter.filetypes.json').prettierd,
},
bash = {
require('formatter.filetypes.sh').shfmt,
},
yaml = {
require('formatter.filetypes.yaml').yamlfmt,
},
-- Enable or disable logging
logging = false,
-- Set the log level
log_level = vim.log.levels.WARN,
-- All formatter configurations are opt-in
filetype = {
-- Formatter configurations for filetype "lua" go here
-- and will be executed in order
lua = {
-- "formatter.filetypes.lua" defines default configurations for the
-- "lua" filetype
require('formatter.filetypes.lua').stylua,
},
html = {
require('formatter.filetypes.html').prettierd,
},
css = {
require('formatter.filetypes.css').prettierd,
},
javascript = {
require('formatter.filetypes.javascript').eslint_d,
},
javascriptreact = {
require('formatter.filetypes.javascriptreact').eslint_d,
},
typescript = {
require('formatter.filetypes.typescript').eslint_d,
},
typescriptreact = {
require('formatter.filetypes.typescriptreact').eslint_d,
},
json = {
require('formatter.filetypes.json').prettierd,
},
bash = {
require('formatter.filetypes.sh').shfmt,
},
yaml = {
require('formatter.filetypes.yaml').yamlfmt,
},
go = {
require('formatter.filetypes.go').gofumpt,
},

-- Use the special "*" filetype for defining formatter configurations on
-- any filetype
['*'] = {
-- "formatter.filetypes.any" defines default configurations for any
-- filetype
require('formatter.filetypes.any').remove_trailing_whitespace,
},
},
-- Use the special "*" filetype for defining formatter configurations on
-- any filetype
['*'] = {
-- "formatter.filetypes.any" defines default configurations for any
-- filetype
require('formatter.filetypes.any').remove_trailing_whitespace,
},
},
})
1 change: 1 addition & 0 deletions lua/plugins/lsp/mason.lua
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require('mason').setup({
require('mason-lspconfig').setup({})
require('mason-tool-installer').setup({
ensure_installed = {
'gopls',
'yamlls',
'yamllint',
'eslint_d',
Expand Down
22 changes: 22 additions & 0 deletions lua/plugins/lsp/servers/gopls.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
vim.api.nvim_create_autocmd('BufWritePre', {
pattern = '*.go',
callback = function()
vim.lsp.buf.code_action({
context = { only = { 'source.organizeImports' } },
})
end,
})

require('lspconfig').gopls.setup({
cmd = { 'gopls', 'serve' },
filetypes = { 'go', 'gomod' },
root_dir = require('lspconfig/util').root_pattern('go.work', 'go.mod', '.git'),
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
},
},
})
1 change: 1 addition & 0 deletions lua/plugins/lsp/servers/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ require('plugins.lsp.servers.json-lsp')
require('plugins.lsp.servers.bash-lsp')
require('plugins.lsp.servers.eslint-lsp')
require('plugins.lsp.servers.tsserver-lsp')
require('plugins.lsp.servers.gopls')
2 changes: 1 addition & 1 deletion lua/plugins/treesitter.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require('nvim-treesitter.configs').setup({
modules = { 'none' },
-- A list of parser names, or 'all' (the five listed parsers should always be installed)
ensure_installed = { 'lua', 'html', 'css', 'javascript', 'typescript', 'markdown', 'c', 'make' },
ensure_installed = { 'go', 'lua', 'html', 'css', 'javascript', 'typescript', 'markdown', 'c', 'make' },

-- Install parsers synchronously (only applied to `ensure_installed`)
sync_install = true,
Expand Down
6 changes: 3 additions & 3 deletions lua/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ vim.opt.numberwidth = 3
vim.opt.signcolumn = 'yes'
vim.opt.laststatus = 3

vim.opt.tabstop = 2
vim.opt.softtabstop = 2
vim.opt.shiftwidth = 2
vim.opt.tabstop = 3
vim.opt.softtabstop = 3
vim.opt.shiftwidth = 3
vim.opt.expandtab = true

vim.opt.smartindent = true
Expand Down
2 changes: 1 addition & 1 deletion stylua.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
column_width = 120
line_endings = 'Unix'
indent_type = 'Spaces'
indent_width = 3
indent_width = 2
quote_style = 'AutoPreferSingle'
call_parentheses = 'Always'
collapse_simple_statement = 'Never'
Expand Down

0 comments on commit 56d30a0

Please sign in to comment.