Skip to content

Updates #1569

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open

Updates #1569

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
120 changes: 118 additions & 2 deletions init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ vim.g.mapleader = ' '
vim.g.maplocalleader = ' '

-- Set to true if you have a Nerd Font installed and selected in the terminal
vim.g.have_nerd_font = false
vim.g.have_nerd_font = true

-- [[ Setting options ]]
-- See `:help vim.o`
Expand All @@ -102,6 +102,7 @@ vim.g.have_nerd_font = false
vim.o.number = true
-- You can also add relative line numbers, to help with jumping.
-- Experiment for yourself to see if you like it!

-- vim.o.relativenumber = true

-- Enable mouse mode, can be useful for resizing splits for example!
Expand Down Expand Up @@ -173,7 +174,13 @@ vim.o.confirm = true
-- See `:help hlsearch`
vim.keymap.set('n', '<Esc>', '<cmd>nohlsearch<CR>')

vim.opt.tabstop = 4
vim.opt.shiftwidth = 4

-- Diagnostic keymaps
vim.keymap.set('n', '[d', vim.diagnostic.goto_prev, { desc = 'Go to previous [D]iagnostic message' })
vim.keymap.set('n', ']d', vim.diagnostic.goto_next, { desc = 'Go to next [D]iagnostic message' })
vim.keymap.set('n', '<leader>e', vim.diagnostic.open_float, { desc = 'Show diagnostic [E]rror messages' })
vim.keymap.set('n', '<leader>q', vim.diagnostic.setloclist, { desc = 'Open diagnostic [Q]uickfix list' })

-- Exit terminal mode in the builtin terminal with a shortcut that is a bit easier
Expand Down Expand Up @@ -247,6 +254,7 @@ rtp:prepend(lazypath)
-- NOTE: Here is where you install your plugins.
require('lazy').setup({
-- NOTE: Plugins can be added with a link (or for a github repo: 'owner/repo' link).
'tpope/vim-fugitive', -- Git commands in nvim
'NMAC427/guess-indent.nvim', -- Detect tabstop and shiftwidth automatically

-- NOTE: Plugins can also be added by using a table,
Expand Down Expand Up @@ -357,6 +365,9 @@ require('lazy').setup({
-- you do for a plugin at the top level, you can do for a dependency.
--
-- Use the `dependencies` key to specify the dependencies of a particular plugin
{
'github/copilot.vim',
},

{ -- Fuzzy Finder (files, lsp, etc)
'nvim-telescope/telescope.nvim',
Expand Down Expand Up @@ -683,6 +694,46 @@ require('lazy').setup({
-- But for many setups, the LSP (`ts_ls`) will work just fine
-- ts_ls = {},
--
volar = {},
jedi_language_server = {},
intelephense = {},
terraformls = {},
templ = {
filetypes = { 'templ' },
},
ts_ls = {
settings = {
implicitProjectConfiguration = {
checkJs = true,
},
},
init_options = {
plugins = {
{
name = '@vue/typescript-plugin',
location = '/home/ocxm/.asdf/installs/nodejs/23.2.0/lib/node_modules/@vue/typescript-plugin',
languages = { 'javascript', 'typescript', 'vue' },
},
},
},
filetypes = {
'javascript',
'typescript',
'vue',
},
},
gopls = {
settings = {
gopls = {
analyses = {
unusedparams = true,
},
staticcheck = true,
gofumpt = true,
},
},
},
-- phan = {},

lua_ls = {
-- cmd = { ... },
Expand Down Expand Up @@ -944,7 +995,23 @@ require('lazy').setup({
main = 'nvim-treesitter.configs', -- Sets main module to use for opts
-- [[ Configure Treesitter ]] See `:help nvim-treesitter`
opts = {
ensure_installed = { 'bash', 'c', 'diff', 'html', 'lua', 'luadoc', 'markdown', 'markdown_inline', 'query', 'vim', 'vimdoc' },
ensure_installed = {
'bash',
'c',
'diff',
'go',
'html',
'javascript',
'lua',
'luadoc',
'markdown',
'markdown_inline',
'php',
'query',
'terraform',
'vim',
'vimdoc',
},
-- Autoinstall languages that are not installed
auto_install = true,
highlight = {
Expand Down Expand Up @@ -1014,3 +1081,52 @@ require('lazy').setup({

-- The line beneath this is called `modeline`. See `:help modeline`
-- vim: ts=2 sts=2 sw=2 et

vim.filetype.add {
extension = {
templ = 'templ',
},
}

-- Toggle Auto formatting
vim.api.nvim_create_user_command('FormatDisable', 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 autoformat-on-save',
bang = true,
})
vim.api.nvim_create_user_command('FormatEnable', function()
vim.b.disable_autoformat = false
vim.g.disable_autoformat = false
end, {
desc = 'Re-enable autoformat-on-save',
})

-- Automatically organize imports and format Go code on save
vim.api.nvim_create_autocmd('BufWritePre', {
pattern = '*.go',
callback = function()
local params = vim.lsp.util.make_range_params()
params.context = { only = { 'source.organizeImports' } }
-- buf_request_sync defaults to a 1000ms timeout. Depending on your
-- machine and codebase, you may want longer. Add an additional
-- argument after params if you find that you have to write the file
-- twice for changes to be saved.
-- E.g., vim.lsp.buf_request_sync(0, "textDocument/codeAction", params, 3000)
local result = vim.lsp.buf_request_sync(0, 'textDocument/codeAction', params)
for cid, res in pairs(result or {}) do
for _, r in pairs(res.result or {}) do
if r.edit then
local enc = (vim.lsp.get_client_by_id(cid) or {}).offset_encoding or 'utf-16'
vim.lsp.util.apply_workspace_edit(r.edit, enc)
end
end
end
vim.lsp.buf.format { async = false }
end,
})