mirror of
https://github.com/LunarVim/LunarVim.git
synced 2025-08-01 16:45:00 +02:00
prettier and eslint configured
This commit is contained in:
parent
b3f2348d97
commit
7eea23bb6c
9 changed files with 123 additions and 93 deletions
51
README.md
51
README.md
|
@ -26,20 +26,24 @@ sudo rm -r neovim
|
|||
|
||||
## VSCode support
|
||||
|
||||
After installing the Neovim extension in VSCode
|
||||
After installing the [Neovim extension](https://github.com/asvetliakov/vscode-neovim) in VSCode
|
||||
|
||||
I recommend using this alongside the VSCode which-key extension
|
||||
|
||||
Along with some of my config files you can find in utils/vscode_config
|
||||
|
||||
Point the nvim path to your `nvim` binary
|
||||
|
||||
Point your `init.vim` path to:
|
||||
Point your `init.lua` path to:
|
||||
|
||||
```vim
|
||||
$HOME/.config/nvim/lua/nv-vscode/init.vim
|
||||
$HOME/.config/nvim/lua/nv-vscode/init.lua
|
||||
```
|
||||
|
||||
or if you are using this config alongside your own:
|
||||
|
||||
```vim
|
||||
$HOME/.config/nvim/lua/nv-vscode/init.vim
|
||||
$HOME/.config/nvim/lua/nv-vscode/init.lua
|
||||
```
|
||||
|
||||
## efm server is slow on close
|
||||
|
@ -50,6 +54,44 @@ Install the latest with:
|
|||
go get github.com/mattn/efm-langserver@HEAD
|
||||
```
|
||||
|
||||
## Useful Programs
|
||||
|
||||
```
|
||||
ranger
|
||||
ueberzug
|
||||
fd
|
||||
ripgrep
|
||||
jq
|
||||
fzf
|
||||
lazygit
|
||||
lazydocker
|
||||
ncdu
|
||||
```
|
||||
|
||||
**Python**
|
||||
|
||||
```
|
||||
pyright
|
||||
flake8
|
||||
yapf
|
||||
```
|
||||
|
||||
**Lua**
|
||||
|
||||
```
|
||||
ninja
|
||||
lua-format
|
||||
sumneko-lua
|
||||
```
|
||||
|
||||
## Vim Gists
|
||||
|
||||
To use vim-gists you will need to configure the following:
|
||||
|
||||
```
|
||||
git config --global github.user <username>
|
||||
```
|
||||
|
||||
## TODO
|
||||
|
||||
**HIGH PRIORITY**
|
||||
|
@ -62,6 +104,7 @@ go get github.com/mattn/efm-langserver@HEAD
|
|||
- for vsnip :h vim-vsnip, also figure out what integr does
|
||||
|
||||
**LOW PRIORITY**
|
||||
- add utf8 line col and spaces (maybe blame)
|
||||
- potentially switch to dashboard
|
||||
- make java code actions prettier
|
||||
- figure out how to customize java formatting
|
||||
|
|
1
init.lua
1
init.lua
|
@ -1,6 +1,7 @@
|
|||
if vim.g.vscode then
|
||||
vim.cmd('source ~/.config/nvim/vimscript/nv-vscode/init.vim')
|
||||
require('settings')
|
||||
require('nv-quickscope')
|
||||
else
|
||||
-- General mappings
|
||||
require('plugins')
|
||||
|
|
|
@ -1,25 +1,40 @@
|
|||
-- Example configuations here: https://github.com/mattn/efm-langserver
|
||||
-- python
|
||||
local flake8 = {
|
||||
LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -",
|
||||
lintStdin = true,
|
||||
lintFormats = {"%f:%l:%c: %m"}
|
||||
}
|
||||
local isort = {formatCommand = "isort --quiet -", formatStdin = true}
|
||||
local yapf = {formatCommand = "yapf --quiet", formatStdin = true}
|
||||
-- lua
|
||||
local luaFormat = {
|
||||
formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=120",
|
||||
formatStdin = true
|
||||
}
|
||||
-- JavaScript/React/TypeScript
|
||||
local prettier = {formatCommand = "./node_modules/.bin/prettier --stdin-filepath ${INPUT}", formatStdin = true}
|
||||
|
||||
local eslint = {
|
||||
lintCommand = "./node_modules/.bin/eslint -f unix --stdin --stdin-filename ${INPUT}",
|
||||
lintIgnoreExitCode = true,
|
||||
lintStdin = true,
|
||||
lintFormats = {"%f:%l:%c: %m"},
|
||||
formatCommand = "./node_modules/.bin/eslint --fix-to-stdout --stdin --stdin-filename=${INPUT}",
|
||||
formatStdin = true
|
||||
}
|
||||
|
||||
require"lspconfig".efm.setup {
|
||||
init_options = {documentFormatting = true},
|
||||
filetypes = {"lua", "python"},
|
||||
-- init_options = {initializationOptions},
|
||||
init_options = {documentFormatting = true, codeAction = false},
|
||||
filetypes = {"lua", "python", "javascriptreact", "javascript"},
|
||||
settings = {
|
||||
rootMarkers = {".git/"},
|
||||
languages = {
|
||||
lua = {
|
||||
{
|
||||
formatCommand = "lua-format -i --no-keep-simple-function-one-line --column-limit=100",
|
||||
formatStdin = true
|
||||
}
|
||||
},
|
||||
python = {
|
||||
{
|
||||
LintCommand = "flake8 --ignore=E501 --stdin-display-name ${INPUT} -",
|
||||
lintStdin = true,
|
||||
lintFormats = {"%f:%l:%c: %m"},
|
||||
formatCommand = "yapf --quiet",
|
||||
formatStdin = true
|
||||
}
|
||||
}
|
||||
lua = {luaFormat},
|
||||
python = {isort, yapf},
|
||||
javascriptreact = {prettier, eslint},
|
||||
javascript = {prettier, eslint}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -28,32 +43,3 @@ require"lspconfig".efm.setup {
|
|||
-- TODO also shellcheck and shell formatting
|
||||
-- Also find way to toggle format on save
|
||||
-- maybe this will help: https://superuser.com/questions/439078/how-to-disable-autocmd-or-augroup-in-vim
|
||||
-- {
|
||||
-- lintCommand = "eslint_d -f unix --stdin --stdin-filename ${INPUT}",
|
||||
-- lintIgnoreExitCode = true,
|
||||
-- lintStdin = true,
|
||||
-- lintFormats = {"%f:%l:%c: %m"},
|
||||
-- }
|
||||
|
||||
|
||||
-- local eslint = {
|
||||
-- lintCommand = './node_modules/.bin/eslint -f compact --stdin',
|
||||
-- lintStdin = true,
|
||||
-- lintFormats = {'%f: line %l, col %c, %trror - %m', '%f: line %l, col %c, %tarning - %m'},
|
||||
-- lintIgnoreExitCode = true,
|
||||
-- formatCommand = './node_modules/.bin/prettier-eslint --stdin --single-quote --print-width 120',
|
||||
-- formatStdin = true,
|
||||
-- }
|
||||
--
|
||||
-- nvim_lsp.efm.setup({
|
||||
-- init_options = { documentFormatting = true },
|
||||
-- root_dir = nvim_lsp.util.root_pattern('.git/'),
|
||||
-- filetypes = {'javascript', 'javascriptreact'},
|
||||
-- settings = {
|
||||
-- rootMarkers = {'.git/'},
|
||||
-- languages = {
|
||||
-- javascript = {eslint},
|
||||
-- javascriptreact = {eslint},
|
||||
-- }
|
||||
-- }
|
||||
-- })
|
||||
|
|
|
@ -1,24 +1,12 @@
|
|||
-- TODO figure out why this don't work
|
||||
vim.fn.sign_define("LspDiagnosticsSignError", {
|
||||
texthl = "LspDiagnosticsSignError",
|
||||
text = "",
|
||||
numhl = "LspDiagnosticsSignError"
|
||||
})
|
||||
vim.fn.sign_define("LspDiagnosticsSignWarning", {
|
||||
texthl = "LspDiagnosticsSignWarning",
|
||||
text = "",
|
||||
numhl = "LspDiagnosticsSignWarning"
|
||||
})
|
||||
vim.fn.sign_define("LspDiagnosticsSignInformation", {
|
||||
texthl = "LspDiagnosticsSignInformation",
|
||||
text = "",
|
||||
numhl = "LspDiagnosticsSignInformation"
|
||||
})
|
||||
vim.fn.sign_define("LspDiagnosticsSignHint", {
|
||||
texthl = "LspDiagnosticsSignHint",
|
||||
text = "",
|
||||
numhl = "LspDiagnosticsSignHint"
|
||||
})
|
||||
vim.fn.sign_define("LspDiagnosticsSignError",
|
||||
{texthl = "LspDiagnosticsSignError", text = "", numhl = "LspDiagnosticsSignError"})
|
||||
vim.fn.sign_define("LspDiagnosticsSignWarning",
|
||||
{texthl = "LspDiagnosticsSignWarning", text = "", numhl = "LspDiagnosticsSignWarning"})
|
||||
vim.fn.sign_define("LspDiagnosticsSignInformation",
|
||||
{texthl = "LspDiagnosticsSignInformation", text = "", numhl = "LspDiagnosticsSignInformation"})
|
||||
vim.fn.sign_define("LspDiagnosticsSignHint",
|
||||
{texthl = "LspDiagnosticsSignHint", text = "", numhl = "LspDiagnosticsSignHint"})
|
||||
|
||||
vim.cmd('nnoremap <silent> gd <cmd>lua vim.lsp.buf.definition()<CR>')
|
||||
vim.cmd('nnoremap <silent> gD <cmd>lua vim.lsp.buf.declaration()<CR>')
|
||||
|
@ -42,10 +30,7 @@ autocmd BufWritePre *.lua lua vim.lsp.buf.formatting_sync(nil, 100) ]]
|
|||
-- Java
|
||||
-- autocmd FileType java nnoremap ca <Cmd>lua require('jdtls').code_action()<CR>
|
||||
|
||||
local lsp_config = {}
|
||||
|
||||
function lsp_config.common_on_attach(client, bufnr)
|
||||
|
||||
local function documentHighlight(client, bufnr)
|
||||
-- Set autocommands conditional on server_capabilities
|
||||
if client.resolved_capabilities.document_highlight then
|
||||
vim.api.nvim_exec([[
|
||||
|
@ -58,7 +43,19 @@ function lsp_config.common_on_attach(client, bufnr)
|
|||
autocmd CursorMoved <buffer> lua vim.lsp.buf.clear_references()
|
||||
augroup END
|
||||
]], false)
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
local lsp_config = {}
|
||||
|
||||
function lsp_config.common_on_attach(client, bufnr)
|
||||
documentHighlight(client, bufnr)
|
||||
end
|
||||
|
||||
function lsp_config.tsserver_on_attach(client, bufnr)
|
||||
lsp_config.common_on_attach(client, bufnr)
|
||||
client.resolved_capabilities.document_formatting = false
|
||||
end
|
||||
|
||||
-- Use a loop to conveniently both setup defined servers
|
||||
|
|
|
@ -7,4 +7,9 @@
|
|||
-- require'completion'.on_attach(client)
|
||||
-- require'illuminate'.on_attach(client)
|
||||
-- end
|
||||
require'lspconfig'.tsserver.setup {on_attach = require'lsp'.common_on_attach}
|
||||
require'lspconfig'.tsserver.setup {
|
||||
on_attach = require'lsp'.tsserver_on_attach,
|
||||
-- This makes sure tsserver is not used for formatting (I prefer prettier)
|
||||
-- on_attach = require'lsp'.common_on_attach,
|
||||
settings = {documentFormatting = false}
|
||||
}
|
||||
|
|
|
@ -55,6 +55,8 @@ gls.left[1] = {
|
|||
highlight = {colors.red, colors.bg, 'bold'}
|
||||
}
|
||||
}
|
||||
print(vim.fn.getbufvar(0,'ts'))
|
||||
vim.fn.getbufvar(0,'ts')
|
||||
|
||||
gls.left[2] = {
|
||||
GitIcon = {
|
||||
|
|
|
@ -7,6 +7,7 @@ local pairs_map = {
|
|||
['['] = ']',
|
||||
['{'] = '}',
|
||||
['`'] = '`',
|
||||
['```'] = '```',
|
||||
}
|
||||
local disable_filetype = { "TelescopePrompt" }
|
||||
local break_line_filetype = nil -- mean all file type
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
require'nvim-treesitter.configs'.setup {
|
||||
ensure_installed = "all", -- one of "all", "maintained" (parsers with maintainers), or a list of languages
|
||||
highlight = {
|
||||
enable = true, -- false will disable the whole extension
|
||||
enable = true -- false will disable the whole extension
|
||||
},
|
||||
playground = {
|
||||
enable = true,
|
||||
|
@ -9,13 +9,7 @@ require'nvim-treesitter.configs'.setup {
|
|||
updatetime = 25, -- Debounced time for highlighting nodes in the playground from source code
|
||||
persist_queries = false -- Whether the query persists across vim sessions
|
||||
},
|
||||
rainbow = {
|
||||
enable = false
|
||||
},
|
||||
refactor = {
|
||||
highlight_definitions = {
|
||||
enable = false
|
||||
}
|
||||
}
|
||||
rainbow = {enable = false},
|
||||
-- refactor = {highlight_definitions = {enable = true}}
|
||||
}
|
||||
|
||||
|
|
|
@ -48,6 +48,7 @@ return require('packer').startup(function(use)
|
|||
|
||||
-- Treesitter
|
||||
use {'nvim-treesitter/nvim-treesitter', run = ':TSUpdate'}
|
||||
use 'nvim-treesitter/nvim-treesitter-refactor'
|
||||
use 'nvim-treesitter/playground'
|
||||
use 'p00f/nvim-ts-rainbow'
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue