Skip to content

Commit

Permalink
refactor (user custom): Proposal for enhancing user customization exp…
Browse files Browse the repository at this point in the history
…erience (#931)

* feat(utils): Add `load_plugin` function

* feat(pack.lua): Added loading of user custom plugins

* feat(ui): Changes to `load_plugin()`

* feat(tool): Changes to `load_plugin()`

* feat(editor): Changes to `load_plugin()`

* feat(lang): Changes to `load_plugin()`

* feat(completion): Changes to `load_plugin()`

* feat(keymap): Adding user overrides for keymap

* feat(pack): Add `lua/user/modules/configs` to package.path (WARNING: Don't create a file with the same name as `lua/modules/configs`)

* feat(event): Supports user-defined events

* feat(options): Supports user-defined options

* feat(settings): Supports user-defined settings

* hotfix(pack): Incorrect value is added when there is no user-defined plugin

* Revert "feat(keymap): Adding user overrides for keymap"

This reverts commit b127042.

* feat(keymap): Defining user keymaps with the override function introduced in 372d3c9

* feat(keymap): Support unset keymap.

* Apply suggestions from code review

Co-authored-by: 冷酔閑吟 <[email protected]>
Signed-off-by: MiSumiSumi <[email protected]>

* fix(pack): Change user_module_dir location and implement 'string:sub' according to module location

* hotfix(utils): Fixed a bug that could not be loaded when vimscript plugins were overridden.

* feat(utils): Create `config_extend` function

* add(user): Create user config directory

* feat(keymap): add `keymap.replace` function

* add(user/keymap): Create user config directory for keymap

* fix: cleanups & fixups

* chore: remove unused function

* feat(pack): add custom loader for user plugin config

* feat(pack): add `disabled_plugins` to settings

* update(.gitignore): add `lua/user`

* fix(utils): Fixed an issue where lists with values were replaced instead of expanded

* feat(lsp): Support user override for lsp settings

* feat(utils): add `load_config()` to resolve and load `user.configs`

* Revert "feat(utils): add `load_config()` to resolve and load `user.configs`"

This reverts commit f95d110.

* feat(modules/keymap): just remove the keymap

* refactor(mason-*): Separating `mason-*` from `lspconfig` and `null-ls`

* feat(mason_*_handler): If there is a user definition, it is read with priority

* fix(pack): Abolish custom loader and add `lua/user` to rtp

* add(user): Make `lsp-servers` and `dap-clients` directory

* fix(user/keymap): Add override `core.keymap`

* rename: Move `lsp-servers` and `dap-clients` under `user/configs`

* chore: update comments

Signed-off-by: Charles Chiu <[email protected]>

* chore: update comments

Signed-off-by: Charles Chiu <[email protected]>

* chore: cleanup

* style: Change position of user override

* feat(issue template): add user config debug template

Signed-off-by: Charles Chiu <[email protected]>

* chore(issue template): fix new template

Signed-off-by: Charles Chiu <[email protected]>

* fix template

Signed-off-by: Charles Chiu <[email protected]>

* test fix

Signed-off-by: Charles Chiu <[email protected]>

* fix(issue template): syntax error

Signed-off-by: Charles Chiu <[email protected]>

* fix(issue template): syntax error 

Signed-off-by: Charles Chiu <[email protected]>

* fixup(ISSUE_TEMPLATE): fix formatting&linting issues

* fixup(IS_TEMPL): proper redirections to correct template

* fix merge conflicts

* feat: add colorscheme setting to example user settings.

Signed-off-by: ayamir <[email protected]>

* feat: update tutor and settings.

Signed-off-by: ayamir <[email protected]>

---------

Signed-off-by: MiSumiSumi <[email protected]>
Signed-off-by: Charles Chiu <[email protected]>
Signed-off-by: ayamir <[email protected]>
Co-authored-by: 冷酔閑吟 <[email protected]>
Co-authored-by: Charles Chiu <[email protected]>
Co-authored-by: ayamir <[email protected]>
  • Loading branch information
4 people authored Aug 25, 2023
1 parent 8631738 commit 188a73e
Show file tree
Hide file tree
Showing 87 changed files with 642 additions and 238 deletions.
11 changes: 10 additions & 1 deletion .github/ISSUE_TEMPLATE/bug_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ body:
options:
- label: "Confirm"
required: true
- type: checkboxes
id: not-user-config-issue
attributes:
label: "Not a user config issue"
description: "This issue _persists_ after removing ALL user configs. If this is not the case, you should open a [Custom (User) Config Issue](https://github.com/ayamir/nvimdots/issues/new?assignees=&labels=usage&projects=&template=custom_config.yml) instead."
options:
- label: "Confirm"
required: true

- type: input
id: nvim-version
attributes:
label: "Neovim version"
description: "Paste the output of `nvim --version` here"
placeholder: "NVIM v0.8.0-dev+199-g2875d45e7"
placeholder: "NVIM v0.10.0-dev-873+g71ad771ea"
validations:
required: true
- type: input
Expand Down Expand Up @@ -61,6 +69,7 @@ body:
- main (Default/Latest)
- 0.8 (Legacy)
- 0.7 (Deprecated)
- 0.10 (Nightly)
validations:
required: true
- type: dropdown
Expand Down
110 changes: 110 additions & 0 deletions .github/ISSUE_TEMPLATE/custom_config.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
name: Custom (User) Config Issue
description: Problems when trying to implement your custom config
labels: [usage]
body:
- type: markdown
attributes:
value: |
_Before requesting:_ Make sure you've read through our [Wiki: Usage](https://github.com/ayamir/nvimdots/wiki/Usage) before you start to add things to nvimdots!
- type: checkboxes
id: is-latest-commit
attributes:
label: "Version confirmation"
description: "The local configuration is up-to-date in the current branch and this issue _persists_."
options:
- label: "Confirm"
required: true
- type: checkboxes
id: prerequisites-done
attributes:
label: "Following prerequisites"
description: "I've checked everything mentioned in [Wiki: Prerequisites](https://github.com/ayamir/nvimdots/wiki/Prerequisites)."
options:
- label: "Confirm"
required: true

- type: input
id: nvim-version
attributes:
label: "Neovim version"
description: "Paste the output of `nvim --version` here"
placeholder: "NVIM v0.10.0-dev-873+g71ad771ea"
validations:
required: true
- type: dropdown
id: branch-info
attributes:
label: "Branch info"
description: "This issue template mainly targets `main` branch. Check the output of `git rev-parse --abbrev-ref HEAD` if you're not sure."
options:
- main (Default/Latest)
- 0.8 (Legacy)
- 0.7 (Deprecated)
- 0.10 (Nightly)
validations:
required: true

- type: textarea
id: folder-structure-ta
attributes:
label: "Minimal (user) folder structure required to reproduce the issue"
description: "Note: You only need to describe where the *new/modified files* are. This section will be automatically formatted."
render: console
placeholder: |
└── lua/
├── core/
├── keymap/ default keymaps
├── modules/ default plugins and plugin configs
└── user custom configs root directory
├── configs/ custom plugin config folder
│ ├── dap-clients/ custom dap client config folder
│ ├── lsp-servers/ custom lsp server config folder
│ └── your-config.lua your plugin configs (if applicable)
├── keymap/ custom keymap folder
│ └── your-config.lua your keymap overrides (if applicable)
├── plugins/ custom plugin folder
│ └── your-config.lua your plugins (if applicable)
├── event.lua custom `core/events.lua` overrides
├── options.lua custom `core/options.lua` overrides
└── settings.lua custom `core/settings.lua` overrides
validations:
required: true

- type: textarea
id: repro-steps
attributes:
label: "Minimal config with steps on how to reproduce the issue"
description: "Note: Issues without any information will be closed directly"
placeholder: |
This is my custom config (`specs.lua`):
```lua
return {
popup = {
delay_ms = 20,
}
}
```
Steps to reproduce the behavior:
1. Go to '...'
2. Click on '....'
3. Scroll down to '....'
4. See error
validations:
required: true

- type: textarea
id: expected-behavior
attributes:
label: "Expected behavior"
description: "Describe the behavior you expect"
validations:
required: true
- type: textarea
id: extras
attributes:
label: Additional information
description: If applicable, you may include logs, images, or videos to help explain your problem
validations:
required: false
11 changes: 10 additions & 1 deletion .github/ISSUE_TEMPLATE/lsp_issue_report.yml
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,21 @@ body:
options:
- label: "Confirm"
required: true
- type: checkboxes
id: not-user-config-issue
attributes:
label: "Not a user config issue"
description: "This issue _persists_ after removing ALL user configs. If this is not the case, you should open a [Custom (User) Config Issue](https://github.com/ayamir/nvimdots/issues/new?assignees=&labels=usage&projects=&template=custom_config.yml) instead."
options:
- label: "Confirm"
required: true

- type: input
id: nvim-version
attributes:
label: "Neovim version"
description: "Paste the output of `nvim --version` here"
placeholder: "NVIM v0.8.0-dev+199-g2875d45e7"
placeholder: "NVIM v0.10.0-dev-873+g71ad771ea"
validations:
required: true
- type: input
Expand Down Expand Up @@ -61,6 +69,7 @@ body:
- main (Default/Latest)
- 0.8 (Legacy)
- 0.7 (Deprecated)
- 0.10 (Nightly)
validations:
required: true
- type: dropdown
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
lua/modules/plugins/custom.lua
lua/modules/configs/custom
lua/user
4 changes: 2 additions & 2 deletions lua/core/event.lua
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ function autocmd.nvim_create_augroups(definitions)
end
end

-- defer setting LSP-related keymaps till LspAttach
local mapping = require("keymap.completion")
vim.api.nvim_create_autocmd("LspAttach", {
group = vim.api.nvim_create_augroup("LspKeymapLoader", { clear = true }),
Expand Down Expand Up @@ -151,8 +152,7 @@ function autocmd.load_autocmds()
},
},
}

autocmd.nvim_create_augroups(definitions)
autocmd.nvim_create_augroups(require("modules.utils").extend_config(definitions, "user.event"))
end

autocmd.load_autocmds()
13 changes: 7 additions & 6 deletions lua/core/options.lua
Original file line number Diff line number Diff line change
Expand Up @@ -121,19 +121,20 @@ local function load_options()
vim.g.python3_host_prog = use_if_defined(vim.g.python3_host_prog, "python3")
end

for name, value in pairs(global_local) do
vim.o[name] = value
end

-- custom sqlite3 provider
local sqlite_clib_path = os.getenv("SQLITE_CLIB_PATH")
-- Try environment variable first
if not isempty(sqlite_clib_path) then
-- Try environment variable first
vim.g.sqlite_clib_path = sqlite_clib_path
-- Fix sqlite3 missing-lib issue on Windows
elseif global.is_windows then
-- Fix sqlite3 missing-lib issue on Windows
-- Download the DLLs form https://www.sqlite.org/download.html
vim.g.sqlite_clib_path = global.home .. "/Documents/sqlite-dll-win64-x64-3400200/sqlite3.dll"
end

for name, value in pairs(require("modules.utils").extend_config(global_local, "user.options")) do
vim.o[name] = value
end
end

load_options()
29 changes: 18 additions & 11 deletions lua/core/pack.lua
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ local vim_path = global.vim_path
local data_dir = global.data_dir
local lazy_path = data_dir .. "lazy/lazy.nvim"
local modules_dir = vim_path .. "/lua/modules"
local user_config_dir = vim_path .. "/lua/user"

local settings = require("core.settings")
local use_ssh = settings.use_ssh
Expand All @@ -24,35 +25,41 @@ function Lazy:load_plugins()

local append_nativertp = function()
package.path = package.path
.. string.format(";%s;%s", modules_dir .. "/configs/?.lua", modules_dir .. "/configs/?/init.lua")
.. string.format(
";%s;%s;%s",
modules_dir .. "/configs/?.lua",
modules_dir .. "/configs/?/init.lua",
user_config_dir
)
end

local get_plugins_list = function()
local list = {}
local plugins_list = vim.split(fn.glob(modules_dir .. "/plugins/*.lua"), "\n")
if type(plugins_list) == "table" then
for _, f in ipairs(plugins_list) do
-- fill list with `plugins/*.lua`'s path used for later `require` like this:
-- list[#list + 1] = "plugins/completion.lua"
list[#list + 1] = f:sub(#modules_dir - 6, -1)
end
local user_plugins_list = vim.split(fn.glob(user_config_dir .. "/plugins/*.lua"), "\n", { trimempty = true })
vim.list_extend(plugins_list, user_plugins_list)
for _, f in ipairs(plugins_list) do
-- aggregate the plugins from `/plugins/*.lua` and `/user/plugins/*.lua` to a plugin list of a certain field for later `require` action.
-- current fields contains: completion, editor, lang, tool, ui
list[#list + 1] = f:find(modules_dir) and f:sub(#modules_dir - 6, -1) or f:sub(#user_config_dir - 3, -1)
end
return list
end

append_nativertp()

local plugins_file = get_plugins_list()
for _, m in ipairs(plugins_file) do
-- require modules which returned in previous operation like this:
-- local modules = require("modules/plugins/completion.lua")
for _, m in ipairs(get_plugins_list()) do
-- require modules returned from `get_plugins_list()` function.
local modules = require(m:sub(0, #m - 4))
if type(modules) == "table" then
for name, conf in pairs(modules) do
self.modules[#self.modules + 1] = vim.tbl_extend("force", { name }, conf)
end
end
end
for _, name in ipairs(settings.disabled_plugins) do
self.modules[#self.modules + 1] = { name, enabled = false }
end
end

function Lazy:load_lazy()
Expand Down
7 changes: 6 additions & 1 deletion lua/core/settings.lua
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,11 @@ settings["format_disabled_dirs"] = {
"~/format_disabled_dir",
}

-- Set the plugins to disable here.
-- Example: "Some-User/A-Repo"
---@type string[]
settings["disabled_plugins"] = {}

-- Set it to false if you don't use nvim to open big files.
---@type boolean
settings["load_big_files_faster"] = true
Expand Down Expand Up @@ -118,4 +123,4 @@ settings["dap_deps"] = {
"python", -- Python (debugpy)
}

return settings
return require("modules.utils").extend_config(settings, "user.settings")
7 changes: 6 additions & 1 deletion lua/keymap/completion.lua
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ local mapping = {}

function mapping.lsp(buf)
local map = {
-- LSP-related keymaps, work only when event = { "InsertEnter", "LspStart" }
-- LSP-related keymaps, ONLY effective in buffers with LSP(s) attached
["n|<leader>li"] = map_cr("LspInfo"):with_buffer(buf):with_desc("lsp: Info"),
["n|<leader>lr"] = map_cr("LspRestart"):with_buffer(buf):with_nowait():with_desc("lsp: Restart"),
["n|go"] = map_cr("SymbolsOutline"):with_buffer(buf):with_desc("lsp: Toggle outline"),
Expand All @@ -35,6 +35,11 @@ function mapping.lsp(buf)
["n|<leader>co"] = map_cr("Lspsaga outgoing_calls"):with_buffer(buf):with_desc("lsp: Show outgoing calls"),
}
bind.nvim_load_mapping(map)

local ok, user_mappings = pcall(require, "user.keymap.completion")
if ok and type(user_mappings.lsp) == "function" then
require("modules.utils.keymap").replace(user_mappings.lsp(buf))
end
end

return mapping
6 changes: 6 additions & 0 deletions lua/keymap/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,9 @@ require("keymap.editor")
require("keymap.lang")
require("keymap.tool")
require("keymap.ui")

-- User keymaps
local ok, mappings = pcall(require, "user.keymap.init")
if ok then
require("modules.utils.keymap").replace(mappings)
end
2 changes: 1 addition & 1 deletion lua/modules/configs/completion/cmp.lua
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ return function()
}

local cmp = require("cmp")
cmp.setup({
require("modules.utils").load_plugin("cmp", {
preselect = cmp.PreselectMode.Item,
window = {
completion = {
Expand Down
2 changes: 1 addition & 1 deletion lua/modules/configs/completion/codeium.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
return function()
require("codeium").setup({})
require("modules.utils").load_plugin("codeium", {})
end
2 changes: 1 addition & 1 deletion lua/modules/configs/completion/copilot-cmp.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
return function()
require("copilot_cmp").setup({})
require("modules.utils").load_plugin("copilot_cmp", {})
end
2 changes: 1 addition & 1 deletion lua/modules/configs/completion/copilot.lua
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
return function()
vim.defer_fn(function()
require("copilot").setup({
require("modules.utils").load_plugin("copilot", {
cmp = {
enabled = true,
method = "getCompletionsCycling",
Expand Down
5 changes: 2 additions & 3 deletions lua/modules/configs/completion/glance.lua
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
return function()
local icons = { ui = require("modules.utils.icons").get("ui", true) }
local glance = require("glance")
local actions = glance.actions
local actions = require("glance").actions

glance.setup({
require("modules.utils").load_plugin("glance", {
height = 20,
zindex = 50,
preview_win_opts = {
Expand Down
2 changes: 1 addition & 1 deletion lua/modules/configs/completion/lsp-signature.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
return function()
require("lsp_signature").setup({
require("modules.utils").load_plugin("lsp_signature", {
bind = true,
-- TODO: Remove the following line when nvim-cmp#1613 gets resolved
check_completion_visible = false,
Expand Down
Loading

0 comments on commit 188a73e

Please sign in to comment.