forked from craftzdog/dotfiles-public
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(nvim): use built-in LSP, tree-sitter, and lua remote plugin host
- Loading branch information
Showing
26 changed files
with
613 additions
and
719 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
if !exists('g:loaded_completion') | finish | endif | ||
|
||
set completeopt=menuone,noinsert,noselect | ||
|
||
" Use <Tab> and <S-Tab> to navigate through popup menu | ||
inoremap <expr> <Tab> pumvisible() ? "\<C-n>" : "\<Tab>" | ||
inoremap <expr> <S-Tab> pumvisible() ? "\<C-p>" : "\<S-Tab>" | ||
let g:completion_confirm_key = "" | ||
imap <expr> <cr> pumvisible() ? complete_info()["selected"] != "-1" ? | ||
\ "\<Plug>(completion_confirm_completion)" : "\<c-e>\<CR>" : "\<CR>" |
2 changes: 2 additions & 0 deletions
2
.config/nvim/plugins/defx.rc.vim → .config/nvim/after/plugin/defx.rc.vim
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
" Status line | ||
if !exists('*fugitive#statusline') | ||
set statusline=%F\ %m%r%h%w%y%{'['.(&fenc!=''?&fenc:&enc).':'.&ff.']'}[L%l/%L,C%03v] | ||
set statusline+=%= | ||
set statusline+=%{fugitive#statusline()} | ||
endif | ||
|
||
cnoreabbrev g Git | ||
cnoreabbrev gopen GBrowse |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
"let g:lexima_enable_basic_rules = 2 | ||
"let g:lexima_enable_newline_rules = 1 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
if !exists('#LspColors') | finish | endif | ||
|
||
lua << EOF | ||
require("lsp-colors").setup({ | ||
Error = "#db4b4b", | ||
Warning = "#e0af68", | ||
Information = "#0db9d7", | ||
Hint = "#10B981" | ||
}) | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,178 @@ | ||
if !exists('g:lspconfig') | ||
finish | ||
endif | ||
|
||
lua << EOF | ||
--vim.lsp.set_log_level("debug") | ||
EOF | ||
|
||
lua << EOF | ||
local nvim_lsp = require('lspconfig') | ||
local protocol = require'vim.lsp.protocol' | ||
|
||
-- Use an on_attach function to only map the following keys | ||
-- after the language server attaches to the current buffer | ||
local on_attach = function(client, bufnr) | ||
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end | ||
local function buf_set_option(...) vim.api.nvim_buf_set_option(bufnr, ...) end | ||
|
||
--Enable completion triggered by <c-x><c-o> | ||
buf_set_option('omnifunc', 'v:lua.vim.lsp.omnifunc') | ||
|
||
-- Mappings. | ||
local opts = { noremap=true, silent=true } | ||
-- See `:help vim.lsp.*` for documentation on any of the below functions | ||
buf_set_keymap('n', 'gD', '<Cmd>lua vim.lsp.buf.declaration()<CR>', opts) | ||
buf_set_keymap('n', 'gd', '<Cmd>lua vim.lsp.buf.definition()<CR>', opts) | ||
--buf_set_keymap('n', 'K', '<Cmd>lua vim.lsp.buf.hover()<CR>', opts) | ||
buf_set_keymap('n', 'gi', '<cmd>lua vim.lsp.buf.implementation()<CR>', opts) | ||
buf_set_keymap('n', '<C-k>', '<cmd>lua vim.lsp.buf.signature_help()<CR>', opts) | ||
buf_set_keymap('n', '<space>wa', '<cmd>lua vim.lsp.buf.add_workspace_folder()<CR>', opts) | ||
buf_set_keymap('n', '<space>wr', '<cmd>lua vim.lsp.buf.remove_workspace_folder()<CR>', opts) | ||
buf_set_keymap('n', '<space>wl', '<cmd>lua print(vim.inspect(vim.lsp.buf.list_workspace_folders()))<CR>', opts) | ||
buf_set_keymap('n', '<space>D', '<cmd>lua vim.lsp.buf.type_definition()<CR>', opts) | ||
buf_set_keymap('n', '<space>rn', '<cmd>lua vim.lsp.buf.rename()<CR>', opts) | ||
buf_set_keymap('n', '<space>ca', '<cmd>lua vim.lsp.buf.code_action()<CR>', opts) | ||
buf_set_keymap('n', 'gr', '<cmd>lua vim.lsp.buf.references()<CR>', opts) | ||
buf_set_keymap('n', '<space>e', '<cmd>lua vim.lsp.diagnostic.show_line_diagnostics()<CR>', opts) | ||
--buf_set_keymap('n', '<C-j>', '<cmd>lua vim.lsp.diagnostic.goto_prev()<CR>', opts) | ||
buf_set_keymap('n', '<S-C-j>', '<cmd>lua vim.lsp.diagnostic.goto_next()<CR>', opts) | ||
buf_set_keymap('n', '<space>q', '<cmd>lua vim.lsp.diagnostic.set_loclist()<CR>', opts) | ||
buf_set_keymap("n", "<space>f", "<cmd>lua vim.lsp.buf.formatting()<CR>", opts) | ||
|
||
-- formatting | ||
if client.resolved_capabilities.document_formatting then | ||
vim.api.nvim_command [[augroup Format]] | ||
vim.api.nvim_command [[autocmd! * <buffer>]] | ||
vim.api.nvim_command [[autocmd BufWritePost <buffer> lua vim.lsp.buf.formatting()]] | ||
vim.api.nvim_command [[augroup END]] | ||
end | ||
|
||
require'completion'.on_attach(client, bufnr) | ||
|
||
--protocol.SymbolKind = { } | ||
protocol.CompletionItemKind = { | ||
'', -- Text | ||
'\u{f09a}', -- Method | ||
'\u{0192}', -- Function | ||
'\u{0192}', -- Constructor | ||
'', -- Field | ||
'', -- Variable | ||
'', -- Class | ||
'\u{f417}', -- Interface | ||
'\u{f40d}', -- Module | ||
'', -- Property | ||
'', -- Unit | ||
'\u{f89f}', -- Value | ||
'', -- Enum | ||
'\u{f1de}', -- Keyword | ||
'\u{e60b}', -- Snippet | ||
'', -- Color | ||
'', -- File | ||
'\u{fa46}', -- Reference | ||
'', -- Folder | ||
'', -- EnumMember | ||
'\u{f8fe}', -- Constant | ||
'', -- Struct | ||
'', -- Event | ||
'ﬦ', -- Operator | ||
'', -- TypeParameter | ||
} | ||
end | ||
|
||
nvim_lsp.flow.setup { | ||
on_attach = on_attach | ||
} | ||
|
||
nvim_lsp.tsserver.setup { | ||
on_attach = on_attach, | ||
filetypes = { "typescript", "typescriptreact", "typescript.tsx" } | ||
} | ||
|
||
nvim_lsp.diagnosticls.setup { | ||
on_attach = on_attach, | ||
filetypes = { 'javascript', 'javascriptreact', 'json', 'typescript', 'typescriptreact', 'css', 'less', 'scss', 'markdown', 'pandoc' }, | ||
init_options = { | ||
linters = { | ||
eslint = { | ||
command = 'eslint', | ||
rootPatterns = { '.git' }, | ||
debounce = 100, | ||
args = { '--stdin', '--stdin-filename', '%filepath', '--format', 'json' }, | ||
sourceName = 'eslint', | ||
parseJson = { | ||
errorsRoot = '[0].messages', | ||
line = 'line', | ||
column = 'column', | ||
endLine = 'endLine', | ||
endColumn = 'endColumn', | ||
message = '[eslint] ${message} [${ruleId}]', | ||
security = 'severity' | ||
}, | ||
securities = { | ||
[2] = 'error', | ||
[1] = 'warning' | ||
} | ||
}, | ||
}, | ||
filetypes = { | ||
javascript = 'eslint', | ||
javascriptreact = 'eslint', | ||
typescript = 'eslint', | ||
typescriptreact = 'eslint', | ||
}, | ||
formatters = { | ||
prettierEslint = { | ||
command = 'prettier-eslint', | ||
args = { '--stdin', '--stdin-filepath', '%filename' }, | ||
rootPatterns = { '.git' }, | ||
}, | ||
prettier = { | ||
command = 'prettier', | ||
args = { '--stdin-filepath', '%filename' } | ||
} | ||
}, | ||
formatFiletypes = { | ||
css = 'prettier', | ||
javascript = 'prettierEslint', | ||
javascriptreact = 'prettierEslint', | ||
json = 'prettier', | ||
scss = 'prettier', | ||
less = 'prettier', | ||
typescript = 'prettierEslint', | ||
typescriptreact = 'prettierEslint', | ||
json = 'prettier', | ||
markdown = 'prettier', | ||
} | ||
} | ||
} | ||
|
||
-- formatting | ||
vim.lsp.handlers["textDocument/formatting"] = function(err, _, result, _, bufnr) | ||
if err ~= nil or result == nil then | ||
return | ||
end | ||
if not vim.api.nvim_buf_get_option(bufnr, "modified") then | ||
local view = vim.fn.winsaveview() | ||
vim.lsp.util.apply_text_edits(result, bufnr) | ||
vim.fn.winrestview(view) | ||
if bufnr == nil or bufnr == vim.api.nvim_get_current_buf() then | ||
vim.api.nvim_command("noautocmd :update") | ||
end | ||
end | ||
end | ||
|
||
-- icon | ||
vim.lsp.handlers["textDocument/publishDiagnostics"] = vim.lsp.with( | ||
vim.lsp.diagnostic.on_publish_diagnostics, { | ||
underline = true, | ||
-- This sets the spacing and the prefix, obviously. | ||
virtual_text = { | ||
spacing = 4, | ||
prefix = '' | ||
} | ||
} | ||
) | ||
|
||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
if !exists('g:loaded_lspsaga') | finish | endif | ||
|
||
lua << EOF | ||
local saga = require 'lspsaga' | ||
|
||
saga.init_lsp_saga { | ||
error_sign = '', | ||
warn_sign = '', | ||
hint_sign = '', | ||
infor_sign = '', | ||
border_style = "round", | ||
} | ||
|
||
EOF | ||
|
||
nnoremap <silent> <C-j> :Lspsaga diagnostic_jump_next<CR> | ||
nnoremap <silent>K :Lspsaga hover_doc<CR> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
local status, lualine = pcall(require, "lualine") | ||
if (not status) then return end | ||
|
||
lualine.setup { | ||
options = { | ||
icons_enabled = true, | ||
theme = 'solarized_dark', | ||
section_separators = {'', ''}, | ||
component_separators = {'', ''}, | ||
disabled_filetypes = {} | ||
}, | ||
sections = { | ||
lualine_a = {'mode'}, | ||
lualine_b = {'branch'}, | ||
lualine_c = {'filename'}, | ||
lualine_x = { | ||
{ 'diagnostics', sources = {"nvim_lsp"}, symbols = {error = ' ', warn = ' ', info = ' ', hint = ' '} }, | ||
'encoding', | ||
'filetype' | ||
}, | ||
lualine_y = {'progress'}, | ||
lualine_z = {'location'} | ||
}, | ||
inactive_sections = { | ||
lualine_a = {}, | ||
lualine_b = {}, | ||
lualine_c = {'filename'}, | ||
lualine_x = {'location'}, | ||
lualine_y = {}, | ||
lualine_z = {} | ||
}, | ||
tabline = {}, | ||
extensions = {'fugitive'} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
" Description: My custom tabline settings | ||
|
||
function MyTabLine() | ||
let s = '' | ||
for i in range(tabpagenr('$')) | ||
" select the highlighting | ||
if i + 1 == tabpagenr() | ||
let s .= '%#TabLineSel#' | ||
else | ||
let s .= '%#TabLine#' | ||
endif | ||
|
||
" set the tab page number (for mouse clicks) | ||
let s .= '%' . (i + 1) . 'T' | ||
|
||
" the label is made by MyTabLabel() | ||
let s .= ' %{MyTabLabel(' . (i + 1) . ')} ' | ||
|
||
if i + 1 == tabpagenr() | ||
let s .= '%#TabLineSep#' | ||
elseif i + 2 == tabpagenr() | ||
let s .= '%#TabLineSep2#' | ||
else | ||
let s .= '' | ||
endif | ||
endfor | ||
|
||
" after the last tab fill with TabLineFill and reset tab page nr | ||
let s .= '%#TabLineFill#%T' | ||
|
||
" right-align the label to close the current tab page | ||
if tabpagenr('$') > 1 | ||
let s .= '%=%#TabLine#%999X' | ||
endif | ||
|
||
return s | ||
endfunction | ||
|
||
function MyTabLabel(n) | ||
let buflist = tabpagebuflist(a:n) | ||
let winnr = tabpagewinnr(a:n) | ||
let name = bufname(buflist[winnr - 1]) | ||
let label = fnamemodify(name, ':t') | ||
return len(label) == 0 ? '[No Name]' : label | ||
endfunction | ||
|
||
set tabline=%!MyTabLine() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
if !exists('g:loaded_telescope') | finish | endif | ||
|
||
nnoremap <silent> ;f <cmd>Telescope find_files<cr> | ||
nnoremap <silent> ;r <cmd>Telescope live_grep<cr> | ||
nnoremap <silent> \\ <cmd>Telescope buffers<cr> | ||
nnoremap <silent> ;; <cmd>Telescope help_tags<cr> | ||
lua << EOF | ||
local actions = require('telescope.actions') | ||
-- Global remapping | ||
------------------------------ | ||
require('telescope').setup{ | ||
defaults = { | ||
mappings = { | ||
n = { | ||
["q"] = actions.close | ||
}, | ||
}, | ||
} | ||
} | ||
EOF | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
if !exists('g:loaded_nvim_treesitter') | ||
echom "Not loaded treesitter" | ||
finish | ||
endif | ||
|
||
lua <<EOF | ||
require'nvim-treesitter.configs'.setup { | ||
highlight = { | ||
enable = true, | ||
disable = {}, | ||
}, | ||
indent = { | ||
enable = false, | ||
disable = {}, | ||
}, | ||
ensure_installed = { | ||
"tsx", | ||
"toml", | ||
"fish", | ||
"php", | ||
"json", | ||
"yaml", | ||
"swift", | ||
"html", | ||
"scss" | ||
}, | ||
} | ||
|
||
local parser_config = require "nvim-treesitter.parsers".get_parser_configs() | ||
parser_config.tsx.used_by = { "javascript", "typescript.tsx" } | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
if !exists('g:loaded_devicons') | finish | endif | ||
|
||
lua << EOF | ||
require'nvim-web-devicons'.setup { | ||
-- your personnal icons can go here (to override) | ||
-- DevIcon will be appended to `name` | ||
override = { | ||
}; | ||
-- globally enable default icons (default to false) | ||
-- will get overriden by `get_icons` option | ||
default = true; | ||
} | ||
EOF |
Oops, something went wrong.