Skip to content

Commit

Permalink
📝 lua formatting and diagnostics
Browse files Browse the repository at this point in the history
  • Loading branch information
nimueller committed Feb 2, 2024
1 parent fbc8484 commit 404703f
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 111 deletions.
69 changes: 0 additions & 69 deletions config/nvim/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -97,75 +97,6 @@ vim.api.nvim_create_autocmd('TextYankPost', {
pattern = '*',
})

-- [[ Configure Treesitter ]]
-- See `:help nvim-treesitter`
-- Defer Treesitter setup after first render to improve startup time of 'nvim {filename}'
vim.defer_fn(function()
require('nvim-treesitter.configs').setup {
-- Add languages to be installed here that you want installed for treesitter
ensure_installed = { 'c', 'cpp', 'go', 'lua', 'python', 'rust', 'tsx', 'javascript', 'typescript', 'vimdoc', 'vim', 'bash' },

-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
auto_install = true,

highlight = { enable = true },
indent = { enable = true },
incremental_selection = {
enable = true,
keymaps = {
init_selection = '<c-space>',
node_incremental = '<c-space>',
scope_incremental = '<c-s>',
node_decremental = '<M-space>',
},
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
['aa'] = '@parameter.outer',
['ia'] = '@parameter.inner',
['af'] = '@function.outer',
['if'] = '@function.inner',
['ac'] = '@class.outer',
['ic'] = '@class.inner',
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
[']m'] = '@function.outer',
[']]'] = '@class.outer',
},
goto_next_end = {
[']M'] = '@function.outer',
[']['] = '@class.outer',
},
goto_previous_start = {
['[m'] = '@function.outer',
['[['] = '@class.outer',
},
goto_previous_end = {
['[M'] = '@function.outer',
['[]'] = '@class.outer',
},
},
swap = {
enable = true,
swap_next = {
['<leader>a'] = '@parameter.inner',
},
swap_previous = {
['<leader>A'] = '@parameter.inner',
},
},
},
}
end, 0)
--
-- document existing key chains
require('which-key').register {
['<leader>c'] = { name = '[C]ode', _ = 'which_key_ignore' },
Expand Down
148 changes: 112 additions & 36 deletions config/nvim/lua/plugins/editor.lua
Original file line number Diff line number Diff line change
@@ -1,43 +1,119 @@
return {
{
-- Highlight, edit, and navigate code
'nvim-treesitter/nvim-treesitter',
dependencies = {
'nvim-treesitter/nvim-treesitter-textobjects',
},
build = ':TSUpdate',
},
{
-- Highlight, edit, and navigate code
"nvim-treesitter/nvim-treesitter",
dependencies = {
"luckasRanarison/tree-sitter-hyprlang",
"nvim-treesitter/nvim-treesitter-textobjects",
"windwp/nvim-ts-autotag",
},
opts = {
-- Add languages to be installed here that you want installed for treesitter
ensure_installed = {
"c",
"cpp",
"go",
"lua",
"python",
"rust",
"tsx",
"javascript",
"typescript",
"vimdoc",
"vim",
"bash",
},

{
"luckasRanarison/tree-sitter-hyprlang",
dependencies = { "nvim-treesitter/nvim-treesitter" },
},
-- Autoinstall languages that are not installed. Defaults to false (but you can change for yourself!)
auto_install = true,

-- Non-LSP linters and formatters
'nvimtools/none-ls.nvim',
highlight = { enable = true },
indent = { enable = true },
incremental_selection = {
enable = true,
keymaps = {
init_selection = "<c-space>",
node_incremental = "<c-space>",
scope_incremental = "<c-s>",
node_decremental = "<M-space>",
},
},
textobjects = {
select = {
enable = true,
lookahead = true, -- Automatically jump forward to textobj, similar to targets.vim
keymaps = {
-- You can use the capture groups defined in textobjects.scm
["aa"] = "@parameter.outer",
["ia"] = "@parameter.inner",
["af"] = "@function.outer",
["if"] = "@function.inner",
["ac"] = "@class.outer",
["ic"] = "@class.inner",
},
},
move = {
enable = true,
set_jumps = true, -- whether to set jumps in the jumplist
goto_next_start = {
["]m"] = "@function.outer",
["]]"] = "@class.outer",
},
goto_next_end = {
["]M"] = "@function.outer",
["]["] = "@class.outer",
},
goto_previous_start = {
["[m"] = "@function.outer",
["[["] = "@class.outer",
},
goto_previous_end = {
["[M"] = "@function.outer",
["[]"] = "@class.outer",
},
},
swap = {
enable = true,
swap_next = {
["<leader>a"] = "@parameter.inner",
},
swap_previous = {
["<leader>A"] = "@parameter.inner",
},
},
},
autotag = {
enable = true,
},
},
build = ":TSUpdate",
},

-- Easily surround text
{
"kylechui/nvim-surround",
version = "*", -- Use for stability; omit to use `main` branch for the latest features
event = "VeryLazy",
config = function()
require("nvim-surround").setup({
-- Configuration here, or leave empty to use defaults
})
end
},
-- Non-LSP linters and formatters
"nvimtools/none-ls.nvim",

-- Add indentation guides even on blank lines
{
'lukas-reineke/indent-blankline.nvim',
main = 'ibl',
opts = {},
},
-- Easily surround text
{
"kylechui/nvim-surround",
version = "*", -- Use for stability; omit to use `main` branch for the latest features
event = "VeryLazy",
config = function()
require("nvim-surround").setup({
-- Configuration here, or leave empty to use defaults
})
end,
},

-- "gc" to comment visual regions/lines
{
'numToStr/Comment.nvim',
opts = {}
},
-- Add indentation guides even on blank lines
{
"lukas-reineke/indent-blankline.nvim",
main = "ibl",
opts = {},
},

-- "gc" to comment visual regions/lines
{
"numToStr/Comment.nvim",
opts = {},
},
}
22 changes: 17 additions & 5 deletions config/nvim/lua/settings/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,15 @@ local servers = {
bashls = {},
texlab = {},
ltex = {},

lemminx = {},
jdtls = {},
kotlin_language_server = {}
}

local on_attach = function(_, bufnr)
local augroup = vim.api.nvim_create_augroup("LspFormatting", {})

local on_attach = function(client, bufnr)
local nmap = function(keys, func, desc)
if desc then
desc = 'LSP: ' .. desc
Expand Down Expand Up @@ -49,10 +53,16 @@ local on_attach = function(_, bufnr)
print(vim.inspect(vim.lsp.buf.list_workspace_folders()))
end, '[W]orkspace [L]ist Folders')

-- Create a command `:Format` local to the LSP buffer
vim.api.nvim_buf_create_user_command(bufnr, 'Format', function(_)
vim.lsp.buf.format()
end, { desc = 'Format current buffer with LSP' })
if client.supports_method("textDocument/formatting") then
vim.api.nvim_clear_autocmds({ group = augroup, buffer = bufnr })
vim.api.nvim_create_autocmd("BufWritePre", {
group = augroup,
buffer = bufnr,
callback = function()
vim.lsp.buf.format({ bufnr = bufnr })
end,
})
end
end

-- Setup neovim lua configuration
Expand All @@ -70,6 +80,8 @@ end
local null_ls = require 'null-ls'
null_ls.setup({
sources = {
null_ls.builtins.diagnostics.luacheck,
null_ls.builtins.formatting.stylua,
null_ls.builtins.diagnostics.ktlint,
null_ls.builtins.formatting.ktlint
}
Expand Down
7 changes: 6 additions & 1 deletion home-manager/headless/neovim.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,17 @@

## language servers
# Lua
luaPackages.luacheck
lua-language-server
stylua

# Nix
# nixd
nil
statix

# XML
lemminx

# Kotlin/Java
jdt-language-server
kotlin-language-server
Expand Down
1 change: 1 addition & 0 deletions nixos/common-configuration.nix
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,7 @@
nodejs_latest
cargo
gradle
maven

# CLI programs
neovim
Expand Down

0 comments on commit 404703f

Please sign in to comment.