Added autocomplete + terminal and lazygit floating term
This commit is contained in:
parent
0383a26c91
commit
e227f2f5f5
97
init.lua
97
init.lua
@ -15,6 +15,31 @@ require("lazy").setup({
|
|||||||
{ "neovim/nvim-lspconfig" },
|
{ "neovim/nvim-lspconfig" },
|
||||||
{ "folke/which-key.nvim", event = "VeryLazy" },
|
{ "folke/which-key.nvim", event = "VeryLazy" },
|
||||||
{ "nvim-tree/nvim-tree.lua", dependencies = { "nvim-tree/nvim-web-devicons" } },
|
{ "nvim-tree/nvim-tree.lua", dependencies = { "nvim-tree/nvim-web-devicons" } },
|
||||||
|
|
||||||
|
-- [NEW] Autocomplete & Snippets
|
||||||
|
{
|
||||||
|
"hrsh7th/nvim-cmp",
|
||||||
|
dependencies = {
|
||||||
|
"hrsh7th/cmp-nvim-lsp", -- Connects LSP to completion
|
||||||
|
"L3MON4D3/LuaSnip", -- Snippet engine (Required for arguments)
|
||||||
|
"saadparwaiz1/cmp_luasnip",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
|
{
|
||||||
|
'akinsho/toggleterm.nvim',
|
||||||
|
version = "*",
|
||||||
|
config = function()
|
||||||
|
require("toggleterm").setup({
|
||||||
|
size = 20,
|
||||||
|
open_mapping = [[<leader>t]], -- This sets the trigger
|
||||||
|
direction = 'float', -- This makes it floating
|
||||||
|
float_opts = {
|
||||||
|
border = 'curved', -- Options: 'single', 'double', 'shadow', 'curved'
|
||||||
|
},
|
||||||
|
})
|
||||||
|
end
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
-- 3. Theme & Settings
|
-- 3. Theme & Settings
|
||||||
@ -24,25 +49,77 @@ vim.opt.relativenumber = true
|
|||||||
|
|
||||||
-- 4. Tree Setup (Small & Minimal)
|
-- 4. Tree Setup (Small & Minimal)
|
||||||
require("nvim-tree").setup({
|
require("nvim-tree").setup({
|
||||||
view = {
|
view = { width = 30, side = "left" },
|
||||||
width = 30, -- Small width
|
filters = { dotfiles = false, custom = { ".git", "zig-cache", "zig-out" } },
|
||||||
side = "left",
|
})
|
||||||
|
|
||||||
|
-- 5. Autocomplete Setup
|
||||||
|
local cmp = require('cmp')
|
||||||
|
local luasnip = require('luasnip')
|
||||||
|
|
||||||
|
-- This is the "secret sauce" that tells ZLS your editor can handle
|
||||||
|
-- the advanced "return ." and "self." completion data.
|
||||||
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||||
|
|
||||||
|
cmp.setup({
|
||||||
|
snippet = {
|
||||||
|
expand = function(args) luasnip.lsp_expand(args.body) end,
|
||||||
},
|
},
|
||||||
filters = {
|
completion = {
|
||||||
dotfiles = false,
|
autocomplete = { cmp.TriggerEvent.TextChanged },
|
||||||
custom = { ".git", "zig-cache", "zig-out" }, -- Hide build clutter
|
keyword_length = 1,
|
||||||
|
},
|
||||||
|
mapping = cmp.mapping.preset.insert({
|
||||||
|
['<CR>'] = cmp.mapping.confirm({ select = true }),
|
||||||
|
["<Tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_next_item()
|
||||||
|
elseif luasnip.expand_or_jumpable() then
|
||||||
|
luasnip.expand_or_jump()
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
["<S-Tab>"] = cmp.mapping(function(fallback)
|
||||||
|
if cmp.visible() then
|
||||||
|
cmp.select_prev_item()
|
||||||
|
elseif luasnip.jumpable(-1) then
|
||||||
|
luasnip.jump(-1)
|
||||||
|
else
|
||||||
|
fallback()
|
||||||
|
end
|
||||||
|
end, { "i", "s" }),
|
||||||
|
}),
|
||||||
|
sources = cmp.config.sources({
|
||||||
|
{ name = 'nvim_lsp' },
|
||||||
|
{ name = 'luasnip' },
|
||||||
|
}),
|
||||||
|
window = {
|
||||||
|
completion = cmp.config.window.bordered(),
|
||||||
|
documentation = cmp.config.window.bordered(),
|
||||||
},
|
},
|
||||||
})
|
})
|
||||||
|
|
||||||
-- 5. Modern LSP Setup (Neovim 0.11+)
|
-- 6. Modern LSP Setup (Neovim 0.11 native)
|
||||||
|
-- We define the config, then enable it.
|
||||||
|
vim.lsp.enable('zls')
|
||||||
vim.lsp.config('zls', {
|
vim.lsp.config('zls', {
|
||||||
cmd = { 'zls' },
|
cmd = { 'zls' },
|
||||||
filetypes = { 'zig', 'zir' },
|
filetypes = { 'zig', 'zir' },
|
||||||
root_markers = { 'build.zig', 'zls.json', '.git' },
|
root_markers = { 'build.zig', '.git' },
|
||||||
|
-- Pass the capabilities and ZLS-specific settings here:
|
||||||
|
capabilities = capabilities,
|
||||||
|
settings = {
|
||||||
|
zls = {
|
||||||
|
enable_snippets = true,
|
||||||
|
enable_argument_placeholders = true,
|
||||||
|
operator_completions = true,
|
||||||
|
enable_autofix = true,
|
||||||
|
},
|
||||||
|
},
|
||||||
})
|
})
|
||||||
vim.lsp.enable('zls')
|
|
||||||
|
|
||||||
-- 6. Auto-format
|
-- 7. Auto-format on Save
|
||||||
vim.api.nvim_create_autocmd("BufWritePre", {
|
vim.api.nvim_create_autocmd("BufWritePre", {
|
||||||
pattern = "*.zig",
|
pattern = "*.zig",
|
||||||
callback = function() vim.lsp.buf.format() end,
|
callback = function() vim.lsp.buf.format() end,
|
||||||
|
|||||||
@ -1,10 +1,15 @@
|
|||||||
{
|
{
|
||||||
|
"LuaSnip": { "branch": "master", "commit": "dae4f5aaa3574bd0c2b9dd20fb9542a02c10471c" },
|
||||||
"catppuccin": { "branch": "main", "commit": "beaf41a30c26fd7d6c386d383155cbd65dd554cd" },
|
"catppuccin": { "branch": "main", "commit": "beaf41a30c26fd7d6c386d383155cbd65dd554cd" },
|
||||||
|
"cmp-nvim-lsp": { "branch": "main", "commit": "cbc7b02bb99fae35cb42f514762b89b5126651ef" },
|
||||||
|
"cmp_luasnip": { "branch": "master", "commit": "98d9cb5c2c38532bd9bdb481067b20fea8f32e90" },
|
||||||
"lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" },
|
"lazy.nvim": { "branch": "main", "commit": "306a05526ada86a7b30af95c5cc81ffba93fef97" },
|
||||||
|
"nvim-cmp": { "branch": "main", "commit": "da88697d7f45d16852c6b2769dc52387d1ddc45f" },
|
||||||
"nvim-lspconfig": { "branch": "master", "commit": "f4e9d367d4e067d7a5fabc9fd3f1349b291eb718" },
|
"nvim-lspconfig": { "branch": "master", "commit": "f4e9d367d4e067d7a5fabc9fd3f1349b291eb718" },
|
||||||
"nvim-tree.lua": { "branch": "master", "commit": "c0b18e4879f7b29a17a240ad49f733af7a7fb348" },
|
"nvim-tree.lua": { "branch": "master", "commit": "c0b18e4879f7b29a17a240ad49f733af7a7fb348" },
|
||||||
"nvim-web-devicons": { "branch": "master", "commit": "746ffbb17975ebd6c40142362eee1b0249969c5c" },
|
"nvim-web-devicons": { "branch": "master", "commit": "746ffbb17975ebd6c40142362eee1b0249969c5c" },
|
||||||
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
|
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
|
||||||
"telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
|
"telescope.nvim": { "branch": "master", "commit": "d90956833d7c27e73c621a61f20b29fdb7122709" },
|
||||||
|
"toggleterm.nvim": { "branch": "main", "commit": "50ea089fc548917cc3cc16b46a8211833b9e3c7c" },
|
||||||
"which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" }
|
"which-key.nvim": { "branch": "main", "commit": "3aab2147e74890957785941f0c1ad87d0a44c15a" }
|
||||||
}
|
}
|
||||||
|
|||||||
71
lua/autocomplete.lua
Normal file
71
lua/autocomplete.lua
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
-- REQUIRED PLUGINS (via your plugin manager, e.g., Packer/Lazy):
|
||||||
|
-- 1. 'hrsh7th/nvim-cmp' (The completion engine)
|
||||||
|
-- 2. 'hrsh7th/cmp-nvim-lsp' (Bridge between LSP and cmp)
|
||||||
|
-- 3. 'neovim/nvim-lspconfig' (Configs for ZLS)
|
||||||
|
-- 4. 'L3MON4D3/LuaSnip' (Snippet engine, required by cmp)
|
||||||
|
|
||||||
|
local cmp = require('cmp')
|
||||||
|
local lspconfig = require('lspconfig')
|
||||||
|
local luasnip = require('luasnip')
|
||||||
|
|
||||||
|
-- 1. SETUP THE COMPLETION ENGINE
|
||||||
|
cmp.setup({
|
||||||
|
-- Snippet expansion is required for arguments to populate correctly
|
||||||
|
snippet = {
|
||||||
|
expand = function(args)
|
||||||
|
luasnip.lsp_expand(args.body)
|
||||||
|
end,
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Window styling for the suggestion box and documentation float
|
||||||
|
window = {
|
||||||
|
completion = cmp.config.window.bordered(),
|
||||||
|
documentation = cmp.config.window.bordered(),
|
||||||
|
},
|
||||||
|
|
||||||
|
-- Key mappings
|
||||||
|
mapping = cmp.mapping.preset.insert({
|
||||||
|
['<C-b>'] = cmp.mapping.scroll_docs(-4),
|
||||||
|
['<C-f>'] = cmp.mapping.scroll_docs(4),
|
||||||
|
['<C-Space>'] = cmp.mapping.complete(), -- Force trigger completion
|
||||||
|
['<CR>'] = cmp.mapping.confirm({ select = true }), -- Accept suggestion
|
||||||
|
}),
|
||||||
|
|
||||||
|
-- Sources: 'nvim_lsp' is what provides the intelligent 'self' data
|
||||||
|
sources = cmp.config.sources({
|
||||||
|
{ name = 'nvim_lsp' },
|
||||||
|
{ name = 'luasnip' },
|
||||||
|
{ name = 'buffer' },
|
||||||
|
}),
|
||||||
|
|
||||||
|
-- formatting: This adds the "Method", "Field", "Text" icons
|
||||||
|
formatting = {
|
||||||
|
format = function(entry, vim_item)
|
||||||
|
vim_item.menu = ({
|
||||||
|
nvim_lsp = "[LSP]",
|
||||||
|
luasnip = "[Snippet]",
|
||||||
|
buffer = "[Buffer]",
|
||||||
|
})[entry.source.name]
|
||||||
|
return vim_item
|
||||||
|
end
|
||||||
|
},
|
||||||
|
})
|
||||||
|
|
||||||
|
-- 2. SETUP ZIG LANGUAGE SERVER (ZLS)
|
||||||
|
-- This captures the capabilities of nvim-cmp to send to ZLS
|
||||||
|
local capabilities = require('cmp_nvim_lsp').default_capabilities()
|
||||||
|
|
||||||
|
lspconfig.zls.setup({
|
||||||
|
capabilities = capabilities,
|
||||||
|
|
||||||
|
-- ZLS Specific Settings to ensure you get arguments and details
|
||||||
|
settings = {
|
||||||
|
zls = {
|
||||||
|
enable_snippets = true, -- Auto-fill arguments
|
||||||
|
enable_argument_placeholders = true, -- Placeholders like (a: i32, b: bool)
|
||||||
|
highlight_global_var_declarations = true,
|
||||||
|
operator_completions = true,
|
||||||
|
include_at_in_builtins = true, -- Suggest @import, @cImport
|
||||||
|
},
|
||||||
|
},
|
||||||
|
})
|
||||||
@ -1,7 +1,29 @@
|
|||||||
local wk = require("which-key")
|
local wk = require("which-key")
|
||||||
local builtin = require('telescope.builtin')
|
local builtin = require('telescope.builtin')
|
||||||
|
|
||||||
|
local Terminal = require('toggleterm.terminal').Terminal
|
||||||
|
local lazygit = Terminal:new({
|
||||||
|
cmd = "lazygit",
|
||||||
|
dir = "git_dir",
|
||||||
|
direction = "float",
|
||||||
|
float_opts = {
|
||||||
|
border = "double",
|
||||||
|
},
|
||||||
|
-- function to run on opening the terminal
|
||||||
|
on_open = function(term)
|
||||||
|
vim.cmd("startinsert!")
|
||||||
|
vim.api.nvim_buf_set_keymap(term.bufnr, "n", "q", "<cmd>close<CR>", {noremap = true, silent = true})
|
||||||
|
end,
|
||||||
|
})
|
||||||
|
|
||||||
|
function _lazygit_toggle()
|
||||||
|
lazygit:toggle()
|
||||||
|
end
|
||||||
|
|
||||||
wk.add({
|
wk.add({
|
||||||
|
{ "<leader>t", "<cmd>ToggleTerm<cr>", desc = "Toggle Floating Terminal"},
|
||||||
|
{"<leader>g", "<cmd>lua _lazygit_toggle()<CR>", desc = "Toggle LazyGit"},
|
||||||
|
|
||||||
-- Essentials
|
-- Essentials
|
||||||
{ "<leader>w", "<cmd>w<cr>", desc = "Save File" },
|
{ "<leader>w", "<cmd>w<cr>", desc = "Save File" },
|
||||||
{ "<leader>q", "<cmd>q<cr>", desc = "Quit" },
|
{ "<leader>q", "<cmd>q<cr>", desc = "Quit" },
|
||||||
|
|||||||
17
lua/lsp.lua
17
lua/lsp.lua
@ -1,17 +0,0 @@
|
|||||||
local configs = require 'nvim_lsp/configs'
|
|
||||||
local util = require 'nvim_lsp/util'
|
|
||||||
|
|
||||||
configs.zls = {
|
|
||||||
default_config = {
|
|
||||||
cmd = {"/usr/local/bin/zls"};
|
|
||||||
filetypes = {"zig"};
|
|
||||||
root_dir = util.root_pattern("build.zig", ".git");
|
|
||||||
};
|
|
||||||
docs = {
|
|
||||||
description = [[ ]];
|
|
||||||
default_config = {
|
|
||||||
root_dir = [[root_pattern("build.zig", ".git")]];
|
|
||||||
};
|
|
||||||
};
|
|
||||||
}
|
|
||||||
-- vim:et ts=2 sw=2
|
|
||||||
Loading…
x
Reference in New Issue
Block a user