Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(structure): structurize nvim config #458

Merged
merged 41 commits into from
Feb 6, 2023

Conversation

CharlesChiuGit
Copy link
Collaborator

Firstly, sorry about forgot to create a new branch.
I structured the config in my own sense, @ayamir @Jint-lzxy please let me know if I need to change anything!

@CharlesChiuGit
Copy link
Collaborator Author

Some files are being capitalized are due the module conflicting. Wellcome to suggest a better strategy!

@Jint-lzxy
Copy link
Collaborator

Will push some changes later 👍

@Jint-lzxy
Copy link
Collaborator

Some files are being capitalized are due the module conflicting. Wellcome to suggest a better strategy!

It doesn't matter (also this would have no effect on case-insensitive systems like macOS). We can ensure that the relative path is unique, and the user config is always in the first place 👍

@CharlesChiuGit
Copy link
Collaborator Author

But the lsp will show warning? Or it's safe to ignore?

@Jint-lzxy
Copy link
Collaborator

But the lsp will show warning? Or it's safe to ignore?

Because it assumes that the current directory is also part of rtp. But yes it would be safer to have a different file name 👍

@ayamir
Copy link
Owner

ayamir commented Jan 31, 2023

The new structure is ok 👍. In this way, users can setup configured plugins with their own config easily without modifying default config.

@Jint-lzxy
Copy link
Collaborator

IMO this structure would be cleaner and could avoid the warnings in #458 (comment).

lua/
└── modules/
    ├── plugins/ <-- Set `lazy.nvim`'s load dir to this **string** and it will automatically load all specs
    │   ├── completion.lua
    │   ├── editor.lua
    │   ├── lang.lua
    │   ├── tools.lua
    │   └── ui.lua
    ├── configs/
    │   ├── completion/
    │   ├── editor/
    │   ├── lang/
    │   ├── tools/
    │   └── ui/
    └── utils/
        ├── icons.lua
        └── init.lua

any ideas?

@CharlesChiuGit
Copy link
Collaborator Author

CharlesChiuGit commented Jan 31, 2023

So the config files in configs/completion/, for example, would be the exact same name as the actual module name? Like configs/completion/cmp.lua would be auto-loaded by lazy.nvim for cmp?

@Jint-lzxy
Copy link
Collaborator

So the config files in configs/completion/, for example, would be the exact same name as the actual module name? Like configs/completion/cmp.lua would be auto-loaded by lazy.nvim?

Since we've required that file in the spec, then it would behave like lazy.nvim auto-loaded this config to memory.

@CharlesChiuGit
Copy link
Collaborator Author

If this would work, then I think it's indeed a more sensible structure than my original one.

@Jint-lzxy
Copy link
Collaborator

completion["hrsh7th/nvim-cmp"] = {
	event = "InsertEnter",
	config = require("modules.configs.completion.cmp"), <- This line loads the config
	dependencies = {
		.....
	}
}

As this file (plugins/completion.lua) would be automatically required by lazy.nvim then "it would behave like lazy.nvim auto-loaded this config to memory."

@ayamir
Copy link
Owner

ayamir commented Jan 31, 2023

IMO this structure would be cleaner and could avoid the warnings in #458 (comment).

Agree.

@CharlesChiuGit
Copy link
Collaborator Author

CharlesChiuGit commented Jan 31, 2023

I'm still a bit confuse tho. If we still need to specify config = require("modules.configs.completion.cmp"), then what does "auto-loaded" means? Or did I misunderstand sth?

For me, "auto-loaded" means lazy.nvim would load the config files without specifying it.

@Jint-lzxy
Copy link
Collaborator

I'm still a bit confuse tho. If we still need to specify config = require("modules.configs.completion.cmp"), then what does "auto-loaded" means? Or I misunderstand sth?

Actually, this is not auto-load. It behaves like auto-load. "Auto-load" here means:

Some users may want to split their plugin specs in multiple files.
Instead of passing a spec table to setup(), you can use a Lua module.

The specs from the module and any top-level sub-modules will be
merged together in the final spec, so it is not needed to add require
calls in your main plugin file to the other files.

As "The specs from the module and any top-level sub-modules will be merged together in the final spec", this auto-merging process (i.e., requiring all files inside modules.plugins) would also require the requires inside each plugin spec (*.lua). Then, all configs would be auto-loaded to memory since we've required it's parent plugins/<spec-name>.lua.

Here we supply a string to the setup function, not a table:

require("lazy").setup("modules.plugins")

@Jint-lzxy
Copy link
Collaborator

Jint-lzxy commented Jan 31, 2023

Auto-load here means we don't need to fetch and merge all plugin specs before lazy.nvim (specifically all plugin.luas). It'll handle this for us. It's indeed rather winding :(

@CharlesChiuGit
Copy link
Collaborator Author

CharlesChiuGit commented Jan 31, 2023

Aha, got it. So it's more like a "auto-merge", even if each completion.lua, editor.lua, etc, are not lua tables?

That would be great! When we were using packer.nvim, we need to merge the tables by ourselves. But now lazy.nvim will handle this for us, nice!

@Jint-lzxy
Copy link
Collaborator

Aha, got it. So it's more like a "auto-merge"?

That would be great! When we were using packer.nvim, we need to merge the tables by ourselves. But now lazy.nvim will handle this for us, nice!

Yup that's it ;)

@CharlesChiuGit
Copy link
Collaborator Author

CharlesChiuGit commented Jan 31, 2023

For user specific plugins, I think it should be like this.

lua/
└── modules/
    ├── plugins/
    │   ├── user.lua <--- user plugins
    │   ├── completion.lua
    │   ├── editor.lua
    │   ├── lang.lua
    │   ├── tools.lua
    │   └── ui.lua
    ├── configs/
    │   ├── user/ <--- user plugins' config files
    │   ├── completion/
    │   ├── editor/
    │   ├── lang/
    │   ├── tools/
    │   └── ui/
    └── utils/
        ├── icons.lua
        └── init.lua

@CharlesChiuGit
Copy link
Collaborator Author

CharlesChiuGit commented Jan 31, 2023

Also, one more question. I'm always curious about why we make extra wrapper functions when setting keymaps?
Isn't that build up the difficultly for users to modify their own keymaps and more error prone?

Why not just do sth like this?
https://github.com/CharlesChiuGit/nvimdots.lua/blob/main/lua/keymap/init.lua

I think it's more native to neovim?

@Jint-lzxy
Copy link
Collaborator

Jint-lzxy commented Feb 1, 2023

To be short, it allows users to set [mode|keybinding] on one side, and use lua's colon syntax to chain specials on the other side.

Long answer:

        ┌─ sep     ┌── map_type (saving a lot of keystrokes)
     ["n|gb"] = map_cr("BufferLinePick"):with_noremap():with_silent(),
       │  └── map_key          │              └── special1    │
       └──── map_mode          └── map_content                └── special2 (chained)

This should be more intuitive one you get used to this.

The special part is similar to:

std::ostream& operator<<(std::ostream& out, Obj& obj)
    ^^^                    ^^^^^ return value can be reused / chained output

If you use C++.

@ayamir
Copy link
Owner

ayamir commented Feb 6, 2023

Personally, I think https://github.com/ayamir/nvimdots/wiki/Plugins shouldn't use table as a display format, and there's not need to explain the effect of each plugin. ppl can just click on the links and read it's README.

Whether to remove the explanation of the effect or not is optional. The purpose I added it is explain the plugins' function briefly.

I think using indents to display the relations of the plugins would be better, like in #458 (comment).

Maybe this format is clearer? It's ok.

@ayamir
Copy link
Owner

ayamir commented Feb 6, 2023

We could consider adding after/ftplugin and after/syntax.

This change can be introduced in #459.

@Jint-lzxy
Copy link
Collaborator

@CharlesChiuGit I plan to put plugins.md directly to wiki. This way users can get all information in one place.

I think using indents to display the relations of the plugins would be better, like in #458 (comment).

We can adopt those changes using - **<plugin-name> (bold)**: <simple-description>

@ayamir
Copy link
Owner

ayamir commented Feb 6, 2023

We can adopt those changes using - (bold):

So maybe CONTRIBUTING.md and commit style check should be created?

@CharlesChiuGit
Copy link
Collaborator Author

CharlesChiuGit commented Feb 6, 2023

So maybe CONTRIBUTING.md and commit style check should be created?

Could be helpful if there's new plugins coming in from PRs.
And yeah, right now we're just yolo our commit style haha.

@ayamir
Copy link
Owner

ayamir commented Feb 6, 2023

I will implement it in next pr if ok.

@Jint-lzxy
Copy link
Collaborator

https://github.com/ayamir/nvimdots/wiki/Usage. I rewrote the first two parts. Hope this can be easily understood @CharlesChiuGit @ayamir

@ayamir
Copy link
Owner

ayamir commented Feb 6, 2023

https://github.com/ayamir/nvimdots/wiki/Usage. I rewrote the first two parts. Hope this can be easily understood @CharlesChiuGit @ayamir

We can set user to custom if we use custom in the code.

@Jint-lzxy
Copy link
Collaborator

We can set user to custom if we use custom in the code.

Updated.

@Jint-lzxy
Copy link
Collaborator

Jint-lzxy commented Feb 6, 2023

@ayamir External sites like zhihu also need to be updated. See 36f331f

@ayamir
Copy link
Owner

ayamir commented Feb 6, 2023

Done

@Jint-lzxy
Copy link
Collaborator

@CharlesChiuGit IMO it is unnecessary to introduce two empty files. Users can customize them according to the wiki.

@CharlesChiuGit
Copy link
Collaborator Author

ok i'll revert.

Copy link
Owner

@ayamir ayamir left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be merged once the new release note done.

@Jint-lzxy Jint-lzxy merged commit 29f746e into ayamir:main Feb 6, 2023
vkingw pushed a commit to vkingw/nvimdots that referenced this pull request Feb 7, 2023
* refactor(structure): structurize nvim config

* Merge: #7bc9ca117d2fc3304b61fb7e1d5f0ac4a6a65670 and #5b44cac0ada2d7eed6a948d71dab8a8cffbe7daf

* style: remove extra empty line

* style: remove extra empty line

* fix!: Reorganize assets

* chore: Format with stylua

* chore: Rearrange files

* feat: Save a few keystrokes

* chore: rtp tweaks

* chore: Sync changes with 'main'

* chore: Reorganize / rename assets

* chore: Minor fixes

* chore: Sync changes with 'main'

* chore: Unify code

* fix(sqlite3): add custom path to fix sqlite3 lib issues on Windows

* chore: Sync changes

* chore(script-win): Add sqlite3 dll issue

* chore(lspsaga): Adapt options from v2.3.6

* refactor: reorganize plugins acording to new standard

* chore: rename `tools` to `tool`

* chore: move fugitive to `tool`

* typo

* chore: Sync changes with 'main'

* doc(wiki): add `plugins.md`

* rename: rename `install/` to `scripts`

* rename: rename `my-snippets` to `snips`

* chore: move `wiki` to root

* fix(snips): fix path in `package.json`

* dic(wiki): change `plugins.lua`'s title

* chore: Fixups

* chore: Update release note

* chore: Add line break

* chore: add `plugins/custom.lua` and `configs/custom/example.lua`

* revert: remove custom.lua and `configs/custom`

---------

Co-authored-by: CharlesChiuGit <charleschiu2012@gmail.comn>
Co-authored-by: 冷酔閑吟 <50296129+Jint-lzxy@users.noreply.github.com>
YanTree pushed a commit to YanTree/nvim that referenced this pull request Apr 9, 2023
* refactor(structure): structurize nvim config

* Merge: #c032dcc118f5680f017a742f4ff5c725781c940f and #9c899a0c204387ff3ec6c3ee1f9e86ad6648baf8

* style: remove extra empty line

* style: remove extra empty line

* fix!: Reorganize assets

* chore: Format with stylua

* chore: Rearrange files

* feat: Save a few keystrokes

* chore: rtp tweaks

* chore: Sync changes with 'main'

* chore: Reorganize / rename assets

* chore: Minor fixes

* chore: Sync changes with 'main'

* chore: Unify code

* fix(sqlite3): add custom path to fix sqlite3 lib issues on Windows

* chore: Sync changes

* chore(script-win): Add sqlite3 dll issue

* chore(lspsaga): Adapt options from v2.3.6

* refactor: reorganize plugins acording to new standard

* chore: rename `tools` to `tool`

* chore: move fugitive to `tool`

* typo

* chore: Sync changes with 'main'

* doc(wiki): add `plugins.md`

* rename: rename `install/` to `scripts`

* rename: rename `my-snippets` to `snips`

* chore: move `wiki` to root

* fix(snips): fix path in `package.json`

* dic(wiki): change `plugins.lua`'s title

* chore: Fixups

* chore: Update release note

* chore: Add line break

* chore: add `plugins/custom.lua` and `configs/custom/example.lua`

* revert: remove custom.lua and `configs/custom`

---------

Co-authored-by: CharlesChiuGit <charleschiu2012@gmail.comn>
Co-authored-by: 冷酔閑吟 <50296129+Jint-lzxy@users.noreply.github.com>
@Jint-lzxy Jint-lzxy mentioned this pull request Sep 27, 2023
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants