Skip to content

Commit

Permalink
oil, copilot
Browse files Browse the repository at this point in the history
  • Loading branch information
dlants committed May 25, 2024
1 parent 52845d7 commit 4bb6d86
Show file tree
Hide file tree
Showing 12 changed files with 333 additions and 106 deletions.
20 changes: 20 additions & 0 deletions alacritty.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import:
- ~/.alacritty-colorscheme/themes/doom_one.yaml

# Font configuration (changes require restart)
font:
normal:
family: "JetBrainsMono Nerd Font Mono"
style: Regular
bold:
family: "JetBrainsMono Nerd Font Mono"
style: Bold
italic:
family: "JetBrainsMono Nerd Font Mono"
style: Italic

env:
TERM: xterm-256color

window:
option_as_alt: Both
26 changes: 26 additions & 0 deletions helix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
theme = "ayu_dark"

[editor]
line-number = "relative"
auto-pairs = false
cursorline = true
mouse = true
auto-format = true
auto-save = true
rulers = [80]
bufferline = "multiple"

[editor.cursor-shape]
insert = "bar"
normal = "block"
select = "underline"

[editor.statusline]
left = ["mode", "spinner", "version-control", "file-name"]

[editor.lsp]
display-messages = true

[keys.normal]
"]"= {j = "jump_forward"}
"[" = {j = "jump_backward"}
4 changes: 4 additions & 0 deletions init.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ ln -sf ~/src/dotfiles/digrc ~/.digrc
ln -sf ~/src/dotfiles/zpreztorc ~/.zpreztorc
ln -sf ~/src/dotfiles/nvim/init.lua ~/.config/nvim/init.lua
ln -sf ~/src/dotfiles/nvim/lua ~/.config/nvim/lua
mkdir -p ~/.config/alacritty
ln -sf ~/src/dotfiles/alacritty.yml ~/.config/alacritty/
mkdir -p ~/.config/helix
ln -sf ~/src/dotfiles/helix.yml ~/.config/helix/config.toml

ln -sf ~/src/dotfiles/scripts/start-tmux /usr/local/bin/start-tmux
ln -sf ~/src/dotfiles/scripts/tmux-session-using-fzf /usr/local/bin/tmux-session-using-fzf
Expand Down
9 changes: 9 additions & 0 deletions npm.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#! /bin/bash

npm install -g \
lua-fmt \
bash-language-server \
typescript \
typescript-language-server \
yaml-language-server \
vscode-langservers-extracted
288 changes: 200 additions & 88 deletions nvim/lua/config/completion-and-snippets.lua
Original file line number Diff line number Diff line change
@@ -1,60 +1,9 @@
-- vim.g.coq_settings = {
-- ['auto_start'] = 'shut-up',
-- ['display.ghost_text.enabled'] = false
-- }

-- nvim-cmp supports additional completion capabilities
-- local capabilities = vim.lsp.protocol.make_client_capabilities()
-- capabilities = require('cmp_nvim_lsp').update_capabilities(capabilities)
-- borrows heavily from
-- https://github.com/MunifTanjim/dotfiles/tree/3d81d787b5a7a745598e623d6cdbd61fb10cef97/private_dot_config/nvim/lua/plugins

-- luasnip setup
local luasnip = require "luasnip"

-- nvim-cmp setup
local cmp = require "cmp"
vim.o.completeopt = "menu,menuone,noselect"
cmp.setup {
snippet = {
expand = function(args)
require("luasnip").lsp_expand(args.body)
end
},
mapping = {
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true
},
["<Tab>"] = function(fallback)
if cmp.visible() then
cmp.select_next_item()
else
fallback()
end
end,
["<S-Tab>"] = function(fallback)
if cmp.visible() then
cmp.select_prev_item()
else
fallback()
end
end
},
sources = {
{name = "nvim_lsp"},
{name = "luasnip"},
{name = "buffer"},
{name = "path"}
}
}

--[[
local cmp = require "cmp"
local lspkind = require("lspkind")

local has_words_before = function()
if vim.api.nvim_buf_get_option(0, "buftype") == "prompt" then
Expand All @@ -64,57 +13,220 @@ local has_words_before = function()
return col ~= 0 and vim.api.nvim_buf_get_lines(0, line - 1, line, true)[1]:sub(col, col):match("%s") == nil
end

local feedkey = function(key, mode)
vim.api.nvim_feedkeys(vim.api.nvim_replace_termcodes(key, true, true, true), mode, true)
end
-- nvim-cmp setup
local cmp = require "cmp"

vim.o.completeopt = "menu,menuone,noselect"
cmp.setup {
snippet = {
expand = function(args)
vim.fn["vsnip#anonymous"](args.body)
end
-- snippet = {
-- expand = function(args)
-- require("luasnip").lsp_expand(args.body)
-- end
-- },
completion = {
autocomplete = false,
completeopt = vim.o.completeopt
},
exprimental = {
ghost_text = true
},
formatting = {
format = lspkind.cmp_format(
{
with_text = true,
menu = {
buffer = "[buf]",
luasnip = "[snip]",
nvim_lsp = "[lsp]",
nvim_lua = "[vim]",
path = "[path]"
}
}
)
},
mapping = {
["<C-p>"] = cmp.mapping.select_prev_item(),
["<C-n>"] = cmp.mapping.select_next_item(),
["<C-d>"] = cmp.mapping.scroll_docs(-4),
["<C-f>"] = cmp.mapping.scroll_docs(4),
["<C-Space>"] = cmp.mapping.complete(),
["<C-e>"] = cmp.mapping.close(),
["<CR>"] = cmp.mapping.confirm {
behavior = cmp.ConfirmBehavior.Replace,
select = true
},
["<C-Space>"] = cmp.mapping(cmp.mapping.complete(), {"i", "c"}),
["<Tab>"] = cmp.mapping(
function(fallback)
if vim.fn.pumvisible() == 1 then
feedkey("<C-n>", "n")
elseif vim.fn["vsnip#available"]() == 1 then
feedkey("<Plug>(vsnip-expand-or-jump)", "")
if require("copilot.suggestion").is_visible() then
require("copilot.suggestion").accept()
elseif cmp.visible() then
cmp.select_next_item({behavior = cmp.SelectBehavior.Insert})
elseif luasnip.expandable() then
luasnip.expand()
elseif has_words_before() then
cmp.complete()
else
fallback() -- The fallback function sends a already mapped key. In this case, it's probably `<Tab>`.
fallback()
end
end,
{"i", "s"}
{
"i",
"s"
}
),
["<S-Tab>"] = cmp.mapping(
function()
if vim.fn.pumvisible() == 1 then
feedkey("<C-p>", "n")
elseif vim.fn["vsnip#jumpable"](-1) == 1 then
feedkey("<Plug>(vsnip-jump-prev)", "")
if cmp.visible() then
cmp.select_prev_item({behavior = cmp.SelectBehavior.Insert})
end
end,
{"i", "s"}
{
"i",
"s"
}
),
["<CR>"] = cmp.mapping(cmp.mapping.confirm({select = true}), {"i", "c"}),
-- ["<Esc>"] = cmp.mapping.abort(),
["<C-Down>"] = cmp.mapping(cmp.mapping.scroll_docs(3), {"i", "c"}),
["<C-Up>"] = cmp.mapping(cmp.mapping.scroll_docs(-3), {"i", "c"})
},
sources = cmp.config.sources(
{
{name = "nvim_lsp", priority = 3},
{name = "luasnip", priority = 1}
},
{
{name = "buffer"},
{name = "path"}
}
)
}

cmp.setup.cmdline(
"/",
{
sources = {
{name = "buffer"}
}
}
)

cmp.setup.cmdline(
":",
{
sources = cmp.config.sources(
{
{name = "path"}
},
{
{name = "cmdline"}
}
)
}
)

cmp.event:on(
"menu_opened",
function()
vim.b.copilot_suggestion_hidden = true
end
)

cmp.event:on(
"menu_closed",
function()
vim.b.copilot_suggestion_hidden = false
end
)

require("copilot").setup(
{
panel = {
auto_refresh = false,
keymap = {
accept = "<CR>",
jump_prev = "[[",
jump_next = "]]",
refresh = "gr",
open = "<M-CR>"
}
},
suggestion = {
auto_trigger = false,
keymap = {
accept = false,
accept_word = "<M-Right>",
accept_line = "<M-Down>",
prev = "<M-[>",
next = "<M-]>",
dismiss = "<C-]>"
}
}
}
)

local suggestion = require("copilot.suggestion")

---@param mode string|string[]
---@param lhs string
---@param rhs string|fun():nil
---@param desc_or_opts string|table
---@param opts? table
function set_keymap(mode, lhs, rhs, desc_or_opts, opts)
if not opts then
opts = type(desc_or_opts) == "table" and desc_or_opts or {desc = desc_or_opts}
else
opts.desc = desc_or_opts
end
vim.keymap.set(mode, lhs, rhs, opts)
end

set_keymap(
"i",
"<M-l>",
function()
if suggestion.is_visible() then
suggestion.accept()
else
suggestion.next()
end
end,
"[copilot] accept or next suggestion"
)

-- init CopilotChat
require("CopilotChat").setup {
prompts = {
Explain = {
prompt = '/COPILOT_EXPLAIN Write an explanation for the active selection as paragraphs of text.',
mapping = '<leader>ce',
description = 'Explain how the selection works.',
selection = require('CopilotChat.select').visual
},
},
sources = {
{name = "nvim_lsp"},
{name = "buffer"},
{name = "path"},
{name = "vsnip"}

mappings = {
reset = {
normal = "<C-r>",
insert = "<C-r>"
}
},

window = {
width = 0.5,
height = 0.5
}
}
]] --

-- keybindings for neovim CopilotChat
set_keymap(
"n",
"<leader>cc",
function()
require("CopilotChat").toggle()
end,
"toggle CopilotChat"
)

set_keymap(
"n",
"<leader>cq",
function()
local input = vim.fn.input("Quick Chat: ")
if input ~= "" then
require("CopilotChat").ask(input, {selection = require("CopilotChat.select").buffer})
end
end,
"ask a quick question about the buffer"
)
2 changes: 1 addition & 1 deletion nvim/lua/config/lsp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ local on_attach = function(client, bufnr)
}
end

local servers = {"dockerls", "bashls", "jsonls", "terraformls", "tflint"}
local servers = {"dockerls", "bashls", "jsonls", "terraformls", "tflint", "eslint", "yamlls"}
for _, server in ipairs(servers) do
lsp[server].setup {
on_attach = on_attach,
Expand Down
Loading

0 comments on commit 4bb6d86

Please sign in to comment.