-
Notifications
You must be signed in to change notification settings - Fork 468
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- decouple go, json, and yaml to extras/lang/ - move nvim-ufo to extras/editor/ - /init.lua loads extras/lang/{go,json,yaml}.lua
- Loading branch information
Showing
9 changed files
with
360 additions
and
225 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
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,110 @@ | ||
return { | ||
{ | ||
'neovim/nvim-lspconfig', | ||
opts = { | ||
capabilities = { | ||
textDocument = { | ||
foldingRange = { | ||
dynamicRegistration = false, | ||
lineFoldingOnly = true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
{ | ||
'kevinhwang91/nvim-ufo', | ||
event = { 'BufReadPost', 'BufNewFile' }, | ||
-- stylua: ignore | ||
keys = { | ||
{ 'zR', function() require('ufo').openAllFolds() end }, | ||
{ 'zM', function() require('ufo').closeAllFolds() end }, | ||
-- { 'zr', function() require('ufo').openFoldsExceptKinds() end }, | ||
-- { 'zm', function() require('ufo').closeFoldsWith() end }, | ||
}, | ||
dependencies = { | ||
'kevinhwang91/promise-async', | ||
'nvim-treesitter/nvim-treesitter', | ||
'neovim/nvim-lspconfig', | ||
}, | ||
opts = function() | ||
-- lsp->treesitter->indent | ||
---@param bufnr number | ||
---@return table | ||
local function customizeSelector(bufnr) | ||
local function handleFallbackException(err, providerName) | ||
if type(err) == 'string' and err:match('UfoFallbackException') then | ||
return require('ufo').getFolds(bufnr, providerName) | ||
else | ||
return require('promise').reject(err) | ||
end | ||
end | ||
|
||
return require('ufo') | ||
.getFolds(bufnr, 'lsp') | ||
:catch(function(err) | ||
return handleFallbackException(err, 'treesitter') | ||
end) | ||
:catch(function(err) | ||
return handleFallbackException(err, 'indent') | ||
end) | ||
end | ||
|
||
local ft_providers = { | ||
vim = 'indent', | ||
python = { 'indent' }, | ||
git = '', | ||
help = '', | ||
qf = '', | ||
fugitive = '', | ||
fugitiveblame = '', | ||
['neo-tree'] = '', | ||
} | ||
|
||
return { | ||
open_fold_hl_timeout = 0, | ||
preview = { | ||
win_config = { | ||
border = { '', '─', '', '', '', '─', '', '' }, | ||
winhighlight = 'Normal:Folded', | ||
winblend = 10, | ||
}, | ||
mappings = { | ||
scrollU = '<C-u>', | ||
scrollD = '<C-d>', | ||
jumpTop = '[', | ||
jumpBot = ']', | ||
}, | ||
}, | ||
|
||
-- Select the fold provider. | ||
provider_selector = function(_, filetype, _) | ||
return ft_providers[filetype] or customizeSelector | ||
end, | ||
|
||
-- Display text for folded lines. | ||
---@param text table | ||
---@param lnum integer | ||
---@param endLnum integer | ||
---@param width integer | ||
---@return table | ||
fold_virt_text_handler = function(text, lnum, endLnum, width) | ||
local suffix = ' ' | ||
local lines = (' %d '):format(endLnum - lnum) | ||
|
||
local cur_width = 0 | ||
for _, section in ipairs(text) do | ||
cur_width = cur_width + vim.fn.strdisplaywidth(section[1]) | ||
end | ||
|
||
suffix = suffix | ||
.. (' '):rep(width - cur_width - vim.fn.strdisplaywidth(lines) - 3) | ||
|
||
table.insert(text, { suffix, 'UfoFoldedEllipsis' }) | ||
table.insert(text, { lines, 'Folded' }) | ||
return text | ||
end, | ||
} | ||
end, | ||
}, | ||
} |
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,147 @@ | ||
-- This is part of LazyVim's code, with my modifications. | ||
-- See: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/lang/go.lua | ||
|
||
return { | ||
|
||
{ | ||
'nvim-treesitter/nvim-treesitter', | ||
opts = function(_, opts) | ||
if type(opts.ensure_installed) == 'table' then | ||
vim.list_extend(opts.ensure_installed, { | ||
'go', | ||
'gomod', | ||
'gosum', | ||
'gowork', | ||
}) | ||
end | ||
end, | ||
}, | ||
|
||
{ | ||
'neovim/nvim-lspconfig', | ||
opts = { | ||
servers = { | ||
gopls = { | ||
settings = { | ||
gopls = { | ||
semanticTokens = true, | ||
}, | ||
}, | ||
}, | ||
}, | ||
setup = { | ||
gopls = function(_, opts) | ||
-- workaround for gopls not supporting semanticTokensProvider | ||
-- https://github.com/golang/go/issues/54531#issuecomment-1464982242 | ||
require('rafi.config').on_attach(function(client, _) | ||
if client.name == 'gopls' then | ||
if not client.server_capabilities.semanticTokensProvider then | ||
local semantic = client.config.capabilities.textDocument.semanticTokens | ||
client.server_capabilities.semanticTokensProvider = { | ||
full = true, | ||
legend = { | ||
tokenTypes = semantic.tokenTypes, | ||
tokenModifiers = semantic.tokenModifiers, | ||
}, | ||
range = true, | ||
} | ||
end | ||
end | ||
end) | ||
-- end workaround | ||
opts.settings = { | ||
-- https://github.com/golang/tools/blob/master/gopls/doc/settings.md | ||
gopls = { | ||
gofumpt = true, | ||
usePlaceholders = true, | ||
completeUnimported = true, | ||
staticcheck = true, | ||
directoryFilters = { '-.git', '-.vscode', '-.idea', '-.vscode-test', '-node_modules' }, | ||
semanticTokens = true, | ||
codelenses = { | ||
gc_details = false, | ||
generate = true, | ||
regenerate_cgo = true, | ||
run_govulncheck = true, | ||
test = true, | ||
tidy = true, | ||
upgrade_dependency = true, | ||
vendor = true, | ||
}, | ||
hints = { | ||
assignVariableTypes = true, | ||
compositeLiteralFields = true, | ||
compositeLiteralTypes = true, | ||
constantValues = true, | ||
functionTypeParameters = true, | ||
parameterNames = true, | ||
rangeVariableTypes = true, | ||
}, | ||
-- https://github.com/golang/tools/blob/master/gopls/doc/analyzers.md | ||
analyses = { | ||
fieldalignment = true, | ||
nilness = true, | ||
unusedparams = true, | ||
unusedwrite = true, | ||
useany = true, | ||
-- fillreturns = true, | ||
-- nonewvars = true, | ||
-- shadow = true, | ||
-- undeclaredname = true, | ||
-- unusedvariable = true, | ||
-- ST1000 = false, | ||
-- ST1005 = false, | ||
}, | ||
}, | ||
} | ||
end, | ||
}, | ||
}, | ||
}, | ||
|
||
{ | ||
'jose-elias-alvarez/null-ls.nvim', | ||
opts = function(_, opts) | ||
local nls = require('null-ls') | ||
local sources = { | ||
nls.builtins.code_actions.gomodifytags, | ||
nls.builtins.code_actions.impl, | ||
nls.builtins.formatting.gofumpt, | ||
-- nls.builtins.formatting.goimports_reviser, | ||
} | ||
for _, source in ipairs(sources) do | ||
table.insert(opts.sources, source) | ||
end | ||
end, | ||
}, | ||
|
||
{ | ||
'mfussenegger/nvim-dap', | ||
optional = true, | ||
dependencies = { | ||
{ | ||
'mason.nvim', | ||
opts = function(_, opts) | ||
opts.ensure_installed = opts.ensure_installed or {} | ||
table.insert(opts.ensure_installed, 'delve') | ||
end, | ||
}, | ||
}, | ||
}, | ||
|
||
{ | ||
'nvim-neotest/neotest', | ||
optional = true, | ||
dependencies = { | ||
'nvim-neotest/neotest-go', | ||
}, | ||
opts = { | ||
adapters = { | ||
['neotest-go'] = { | ||
-- Here we can set options for neotest-go, e.g. | ||
-- args = { '-tags=integration' } | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
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,40 @@ | ||
-- This is part of LazyVim's code, with my modifications. | ||
-- See: https://github.com/LazyVim/LazyVim/blob/main/lua/lazyvim/plugins/extras/lang/json.lua | ||
|
||
return { | ||
|
||
{ | ||
'nvim-treesitter/nvim-treesitter', | ||
opts = function(_, opts) | ||
if type(opts.ensure_installed) == 'table' then | ||
vim.list_extend(opts.ensure_installed, { 'json', 'json5', 'jsonc' }) | ||
end | ||
end, | ||
}, | ||
|
||
{ | ||
'neovim/nvim-lspconfig', | ||
dependencies = { 'b0o/SchemaStore.nvim', version = false }, | ||
opts = { | ||
servers = { | ||
jsonls = { | ||
-- lazy-load schemastore when needed | ||
on_new_config = function(new_config) | ||
new_config.settings.json.schemas = new_config.settings.json.schemas | ||
or {} | ||
vim.list_extend( | ||
new_config.settings.json.schemas, | ||
require('schemastore').json.schemas() | ||
) | ||
end, | ||
settings = { | ||
json = { | ||
format = { enable = true }, | ||
validate = { enable = true }, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
}, | ||
} |
Oops, something went wrong.