Compare commits
10 commits
7202fa1911
...
03a37c34ef
| Author | SHA1 | Date | |
|---|---|---|---|
| 03a37c34ef | |||
| d7d8f40a8f | |||
| 526f8bb6e2 | |||
| dbd7e077e5 | |||
| 28a36cfdaa | |||
| 47ca4ed61c | |||
| 69b9480aa1 | |||
| ab34234c83 | |||
| 034a432c8e | |||
| 852ded641a |
7 changed files with 134 additions and 104 deletions
40
flake.lock
generated
40
flake.lock
generated
|
|
@ -53,15 +53,15 @@
|
||||||
"flake-compat": {
|
"flake-compat": {
|
||||||
"flake": false,
|
"flake": false,
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1761588595,
|
"lastModified": 1767039857,
|
||||||
"narHash": "sha256-XKUZz9zewJNUj46b4AJdiRZJAvSZ0Dqj2BNfXvFlJC4=",
|
"narHash": "sha256-vNpUSpF5Nuw8xvDLj2KCwwksIbjua2LZCqhV1LNRDns=",
|
||||||
"owner": "edolstra",
|
"owner": "NixOS",
|
||||||
"repo": "flake-compat",
|
"repo": "flake-compat",
|
||||||
"rev": "f387cd2afec9419c8ee37694406ca490c3f34ee5",
|
"rev": "5edf11c44bc78a0d334f6334cdaf7d60d732daab",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "edolstra",
|
"owner": "NixOS",
|
||||||
"repo": "flake-compat",
|
"repo": "flake-compat",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
|
|
@ -73,11 +73,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1765835352,
|
"lastModified": 1768135262,
|
||||||
"narHash": "sha256-XswHlK/Qtjasvhd1nOa1e8MgZ8GS//jBoTqWtrS1Giw=",
|
"narHash": "sha256-PVvu7OqHBGWN16zSi6tEmPwwHQ4rLPU9Plvs8/1TUBY=",
|
||||||
"owner": "hercules-ci",
|
"owner": "hercules-ci",
|
||||||
"repo": "flake-parts",
|
"repo": "flake-parts",
|
||||||
"rev": "a34fae9c08a15ad73f295041fec82323541400a9",
|
"rev": "80daad04eddbbf5a4d883996a73f3f542fa437ac",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -117,11 +117,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1765911976,
|
"lastModified": 1769069492,
|
||||||
"narHash": "sha256-t3T/xm8zstHRLx+pIHxVpQTiySbKqcQbK+r+01XVKc0=",
|
"narHash": "sha256-Efs3VUPelRduf3PpfPP2ovEB4CXT7vHf8W+xc49RL/U=",
|
||||||
"owner": "cachix",
|
"owner": "cachix",
|
||||||
"repo": "git-hooks.nix",
|
"repo": "git-hooks.nix",
|
||||||
"rev": "b68b780b69702a090c8bb1b973bab13756cc7a27",
|
"rev": "a1ef738813b15cf8ec759bdff5761b027e3e1d23",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -159,11 +159,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1766171975,
|
"lastModified": 1769442288,
|
||||||
"narHash": "sha256-47Ee0bTidhF/3/sHuYnWRuxcCrrm0mBNDxBkOTd3wWQ=",
|
"narHash": "sha256-p+Xqr+P22TYW2RqbwccSd4UlUDEwl7PnoW3qiH8wVoE=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "home-manager",
|
"repo": "home-manager",
|
||||||
"rev": "bb35f07cc95a73aacbaf1f7f46bb8a3f40f265b5",
|
"rev": "384786dc70c4992643f916c7e57f378714fec4f1",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -175,11 +175,11 @@
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1766070988,
|
"lastModified": 1769170682,
|
||||||
"narHash": "sha256-G/WVghka6c4bAzMhTwT2vjLccg/awmHkdKSd2JrycLc=",
|
"narHash": "sha256-oMmN1lVQU0F0W2k6OI3bgdzp2YOHWYUAw79qzDSjenU=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "c6245e83d836d0433170a16eb185cefe0572f8b8",
|
"rev": "c5296fdd05cfa2c187990dd909864da9658df755",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
@ -199,11 +199,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1766242030,
|
"lastModified": 1769444957,
|
||||||
"narHash": "sha256-GdaKIZrzm4fbFf9jBVmeQFZTwYPxUlSTZrSId/JNMAU=",
|
"narHash": "sha256-2VIGLo/Xj7v+ZZqR/k2uoaZ75vpYB1FLa2UAW5ZhIK8=",
|
||||||
"owner": "nix-community",
|
"owner": "nix-community",
|
||||||
"repo": "NUR",
|
"repo": "NUR",
|
||||||
"rev": "30006228925f07c5c2a270bb95dc8da35d9942dc",
|
"rev": "9183819b926f1f58e8af86e86f28cc7d1e87698f",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
||||||
|
|
@ -85,4 +85,18 @@ M.on_attach = function(client, bufnr)
|
||||||
wk.add(keys)
|
wk.add(keys)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
--- list all active LSP clients for specific buffer, or all buffers
|
||||||
|
--- @param bufnr int? buffer number
|
||||||
|
--- @return table all active LSP client names
|
||||||
|
M.list_clients = function(bufnr)
|
||||||
|
local clients = vim.lsp.get_clients({ bufnr = bufnr })
|
||||||
|
local names = {}
|
||||||
|
|
||||||
|
for _, client in ipairs(clients) do
|
||||||
|
table.insert(names, client.name)
|
||||||
|
end
|
||||||
|
|
||||||
|
return names
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
||||||
|
|
@ -7,15 +7,6 @@ M.is_executable = function(cmd)
|
||||||
return cmd and vim.fn.executable(cmd) == 1
|
return cmd and vim.fn.executable(cmd) == 1
|
||||||
end
|
end
|
||||||
|
|
||||||
--- return a function that checks if a given command is executable
|
|
||||||
--- @param cmd string? command to check
|
|
||||||
--- @return fun(): boolean executable
|
|
||||||
M.is_executable_condition = function(cmd)
|
|
||||||
return function()
|
|
||||||
return M.is_executable(cmd)
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
--- whether or not we are currently in an SSH connection
|
--- whether or not we are currently in an SSH connection
|
||||||
--- @return boolean ssh connection
|
--- @return boolean ssh connection
|
||||||
M.is_ssh = function()
|
M.is_ssh = function()
|
||||||
|
|
@ -34,20 +25,6 @@ M.is_ssh = function()
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
|
||||||
--- list all active LSP clients for specific buffer, or all buffers
|
|
||||||
--- @param bufnr int? buffer number
|
|
||||||
--- @return table all active LSP client names
|
|
||||||
M.list_lsp_clients = function(bufnr)
|
|
||||||
local clients = vim.lsp.get_clients({ bufnr = bufnr })
|
|
||||||
local names = {}
|
|
||||||
|
|
||||||
for _, client in ipairs(clients) do
|
|
||||||
table.insert(names, client.name)
|
|
||||||
end
|
|
||||||
|
|
||||||
return names
|
|
||||||
end
|
|
||||||
|
|
||||||
--- partially apply a function with given arguments
|
--- partially apply a function with given arguments
|
||||||
M.partial = function(f, ...)
|
M.partial = function(f, ...)
|
||||||
local a = { ... }
|
local a = { ... }
|
||||||
|
|
|
||||||
|
|
@ -57,12 +57,12 @@ local keys = {
|
||||||
|
|
||||||
local objects = {
|
local objects = {
|
||||||
mode = "o",
|
mode = "o",
|
||||||
{ "ih", gitsigns.select_hunk, desc = "Git hunk" },
|
{ "ih", gitsigns.select_hunk, desc = "git hunk" },
|
||||||
}
|
}
|
||||||
-- Visual
|
-- Visual
|
||||||
local visual = {
|
local visual = {
|
||||||
mode = { "x" },
|
mode = { "x" },
|
||||||
{ "ih", gitsigns.select_hunk, desc = "Git hunk" },
|
{ "ih", gitsigns.select_hunk, desc = "git hunk" },
|
||||||
{ "<leader>g", group = "Git" },
|
{ "<leader>g", group = "Git" },
|
||||||
{ "<leader>gp", gitsigns.preview_hunk, desc = "Preview selection" },
|
{ "<leader>gp", gitsigns.preview_hunk, desc = "Preview selection" },
|
||||||
{ "<leader>gr", make_visual(gitsigns.reset_hunk), desc = "Restore selection" },
|
{ "<leader>gr", make_visual(gitsigns.reset_hunk), desc = "Restore selection" },
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,6 @@
|
||||||
local lualine = require("lualine")
|
local lualine = require("lualine")
|
||||||
local oil = require("oil")
|
local oil = require("oil")
|
||||||
local utils = require("ambroisie.utils")
|
local lsp = require("ambroisie.lsp")
|
||||||
|
|
||||||
local function list_spell_languages()
|
local function list_spell_languages()
|
||||||
if not vim.opt.spell:get() then
|
if not vim.opt.spell:get() then
|
||||||
|
|
@ -11,7 +11,7 @@ local function list_spell_languages()
|
||||||
end
|
end
|
||||||
|
|
||||||
local function list_lsp_clients()
|
local function list_lsp_clients()
|
||||||
local client_names = utils.list_lsp_clients(0)
|
local client_names = lsp.list_clients(0)
|
||||||
|
|
||||||
if #client_names == 0 then
|
if #client_names == 0 then
|
||||||
return ""
|
return ""
|
||||||
|
|
|
||||||
|
|
@ -10,11 +10,11 @@ null_ls.setup({
|
||||||
null_ls.register({
|
null_ls.register({
|
||||||
null_ls.builtins.diagnostics.buildifier.with({
|
null_ls.builtins.diagnostics.buildifier.with({
|
||||||
-- Only used if available
|
-- Only used if available
|
||||||
condition = utils.is_executable_condition("buildifier"),
|
condition = utils.partial(utils.is_executable, "buildifier"),
|
||||||
}),
|
}),
|
||||||
null_ls.builtins.formatting.buildifier.with({
|
null_ls.builtins.formatting.buildifier.with({
|
||||||
-- Only used if available
|
-- Only used if available
|
||||||
condition = utils.is_executable_condition("buildifier"),
|
condition = utils.partial(utils.is_executable, "buildifier"),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -22,7 +22,7 @@ null_ls.register({
|
||||||
null_ls.register({
|
null_ls.register({
|
||||||
null_ls.builtins.formatting.nixpkgs_fmt.with({
|
null_ls.builtins.formatting.nixpkgs_fmt.with({
|
||||||
-- Only used if available
|
-- Only used if available
|
||||||
condition = utils.is_executable_condition("nixpkgs-fmt"),
|
condition = utils.partial(utils.is_executable, "nixpkgs-fmt"),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
@ -30,19 +30,19 @@ null_ls.register({
|
||||||
null_ls.register({
|
null_ls.register({
|
||||||
null_ls.builtins.diagnostics.mypy.with({
|
null_ls.builtins.diagnostics.mypy.with({
|
||||||
-- Only used if available
|
-- Only used if available
|
||||||
condition = utils.is_executable_condition("mypy"),
|
condition = utils.partial(utils.is_executable, "mypy"),
|
||||||
}),
|
}),
|
||||||
null_ls.builtins.diagnostics.pylint.with({
|
null_ls.builtins.diagnostics.pylint.with({
|
||||||
-- Only used if available
|
-- Only used if available
|
||||||
condition = utils.is_executable_condition("pylint"),
|
condition = utils.partial(utils.is_executable, "pylint"),
|
||||||
}),
|
}),
|
||||||
null_ls.builtins.formatting.black.with({
|
null_ls.builtins.formatting.black.with({
|
||||||
extra_args = { "--fast" },
|
extra_args = { "--fast" },
|
||||||
-- Only used if available
|
-- Only used if available
|
||||||
condition = utils.is_executable_condition("black"),
|
condition = utils.partial(utils.is_executable, "black"),
|
||||||
}),
|
}),
|
||||||
null_ls.builtins.formatting.isort.with({
|
null_ls.builtins.formatting.isort.with({
|
||||||
-- Only used if available
|
-- Only used if available
|
||||||
condition = utils.is_executable_condition("isort"),
|
condition = utils.partial(utils.is_executable, "isort"),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
|
|
|
||||||
|
|
@ -1,54 +1,93 @@
|
||||||
local ts_config = require("nvim-treesitter.configs")
|
local treesitter = require("nvim-treesitter")
|
||||||
|
local ts_select = require("nvim-treesitter-textobjects.select")
|
||||||
|
local ts_move = require("nvim-treesitter-textobjects.move")
|
||||||
|
local utils = require("ambroisie.utils")
|
||||||
|
local wk = require("which-key")
|
||||||
|
|
||||||
ts_config.setup({
|
local function select_textobject(query)
|
||||||
highlight = {
|
return utils.partial(ts_select.select_textobject, query)
|
||||||
enable = true,
|
end
|
||||||
-- Avoid duplicate highlighting
|
|
||||||
additional_vim_regex_highlighting = false,
|
local function goto_next_start(query)
|
||||||
|
return utils.partial(ts_move.goto_next_start, query)
|
||||||
|
end
|
||||||
|
local function goto_next_end(query)
|
||||||
|
return utils.partial(ts_move.goto_next_end, query)
|
||||||
|
end
|
||||||
|
local function goto_previous_start(query)
|
||||||
|
return utils.partial(ts_move.goto_previous_start, query)
|
||||||
|
end
|
||||||
|
local function goto_previous_end(query)
|
||||||
|
return utils.partial(ts_move.goto_previous_end, query)
|
||||||
|
end
|
||||||
|
|
||||||
|
local objects = {
|
||||||
|
mode = { "x", "o" },
|
||||||
|
{ "aa", select_textobject("@parameter.outer"), desc = "a parameter" },
|
||||||
|
{ "ia", select_textobject("@parameter.inner"), desc = "inner parameter" },
|
||||||
|
{ "ab", select_textobject("@block.outer"), desc = "a block" },
|
||||||
|
{ "ib", select_textobject("@block.inner"), desc = "inner block" },
|
||||||
|
{ "ac", select_textobject("@class.outer"), desc = "a class" },
|
||||||
|
{ "ic", select_textobject("@class.inner"), desc = "inner class" },
|
||||||
|
{ "af", select_textobject("@function.outer"), desc = "a function" },
|
||||||
|
{ "if", select_textobject("@function.inner"), desc = "inner function" },
|
||||||
|
{ "ak", select_textobject("@comment.outer"), desc = "a comment" },
|
||||||
|
{ "aS", select_textobject("@statement.outer"), desc = "a statement" },
|
||||||
|
}
|
||||||
|
local moves = {
|
||||||
|
mode = { "n", "x", "o" },
|
||||||
|
-- Next start
|
||||||
|
{ "]m", goto_next_start("@function.outer"), desc = "Next method start" },
|
||||||
|
{ "]S", goto_next_start("@statement.outer"), desc = "Next statement start" },
|
||||||
|
{ "]]", goto_next_start("@class.outer"), desc = "Next class start" },
|
||||||
|
-- Next end
|
||||||
|
{ "]M", goto_next_end("@function.outer"), desc = "Next method end" },
|
||||||
|
{ "][", goto_next_end("@class.outer"), desc = "Next class end" },
|
||||||
|
-- Previous start
|
||||||
|
{ "[m", goto_previous_start("@function.outer"), desc = "Previous method start" },
|
||||||
|
{ "[S", goto_previous_start("@statement.outer"), desc = "Previous statement start" },
|
||||||
|
{ "[[", goto_previous_start("@class.outer"), desc = "Previous class start" },
|
||||||
|
-- Previous end
|
||||||
|
{ "[M", goto_previous_end("@function.outer"), desc = "Previous method end" },
|
||||||
|
{ "[]", goto_previous_end("@class.outer"), desc = "Previous class end" },
|
||||||
|
}
|
||||||
|
|
||||||
|
require("nvim-treesitter-textobjects").setup({
|
||||||
|
select = {
|
||||||
|
-- Jump to matching text objects
|
||||||
|
lookahead = true,
|
||||||
},
|
},
|
||||||
indent = {
|
move = {
|
||||||
enable = true,
|
-- Add to jump list
|
||||||
},
|
set_jumps = true,
|
||||||
textobjects = {
|
|
||||||
select = {
|
|
||||||
enable = true,
|
|
||||||
-- Jump to matching text objects
|
|
||||||
lookahead = true,
|
|
||||||
keymaps = {
|
|
||||||
["aa"] = { query = "@parameter.outer", desc = "a parameter" },
|
|
||||||
["ia"] = { query = "@parameter.inner", desc = "inner parameter" },
|
|
||||||
["ab"] = { query = "@block.outer", desc = "a block" },
|
|
||||||
["ib"] = { query = "@block.inner", desc = "inner block" },
|
|
||||||
["ac"] = { query = "@class.outer", desc = "a class" },
|
|
||||||
["ic"] = { query = "@class.inner", desc = "inner class" },
|
|
||||||
["af"] = { query = "@function.outer", desc = "a function" },
|
|
||||||
["if"] = { query = "@function.inner", desc = "inner function" },
|
|
||||||
["ak"] = { query = "@comment.outer", desc = "a comment" },
|
|
||||||
["aS"] = { query = "@statement.outer", desc = "a statement" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
move = {
|
|
||||||
enable = true,
|
|
||||||
-- Add to jump list
|
|
||||||
set_jumps = true,
|
|
||||||
goto_next_start = {
|
|
||||||
["]m"] = { query = "@function.outer", desc = "Next method start" },
|
|
||||||
["]S"] = { query = "@statement.outer", desc = "Next statement start" },
|
|
||||||
["]]"] = { query = "@class.outer", desc = "Next class start" },
|
|
||||||
},
|
|
||||||
goto_next_end = {
|
|
||||||
["]M"] = { query = "@function.outer", desc = "Next method end" },
|
|
||||||
["]["] = { query = "@class.outer", desc = "Next class end" },
|
|
||||||
},
|
|
||||||
goto_previous_start = {
|
|
||||||
["[m"] = { query = "@function.outer", desc = "Previous method start" },
|
|
||||||
["[S"] = { query = "@statement.outer", desc = "Previous statement start" },
|
|
||||||
["[["] = { query = "@class.outer", desc = "Previous class start" },
|
|
||||||
},
|
|
||||||
goto_previous_end = {
|
|
||||||
["[M"] = { query = "@function.outer", desc = "Previous method end" },
|
|
||||||
["[]"] = { query = "@class.outer", desc = "Previous class end" },
|
|
||||||
},
|
|
||||||
},
|
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
|
-- Automatically setup treesitter for supported filetypes
|
||||||
|
local function treesitter_try_attach(buf, language)
|
||||||
|
-- Try to load language
|
||||||
|
-- NOTE: the best way I found to check if a filetype has a grammar
|
||||||
|
if not vim.treesitter.language.add(language) then
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
|
-- Syntax highlighting
|
||||||
|
vim.treesitter.start(buf, language)
|
||||||
|
-- Indentation
|
||||||
|
vim.bo.indentexpr = "v:lua.require('nvim-treesitter').indentexpr()"
|
||||||
|
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
|
vim.api.nvim_create_autocmd("FileType", {
|
||||||
|
pattern = "*",
|
||||||
|
group = vim.api.nvim_create_augroup("treesitter_attach", { clear = true }),
|
||||||
|
callback = function(args)
|
||||||
|
local buf, filetype = args.buf, args.match
|
||||||
|
local language = vim.treesitter.language.get_lang(filetype)
|
||||||
|
if not language then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
treesitter_try_attach(buf, language)
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue