Skip to content

docs: add types for user configuration #1689

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

Merged
merged 38 commits into from
Mar 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
d26d4a4
feat(config): add types
pynappo Feb 11, 2025
07be10e
Reorganize
pynappo Feb 15, 2025
496772e
type common containers
pynappo Feb 15, 2025
e2e5ddb
add workflows
pynappo Feb 15, 2025
10c3147
fix version
pynappo Feb 15, 2025
40ad74d
Merge branch 'main' into typed-config
pynappo Feb 16, 2025
2a113ac
format defaults.lua and fix types
pynappo Feb 17, 2025
79d2ff3
comment out example
pynappo Feb 17, 2025
e603187
only typecheck defaults
pynappo Feb 17, 2025
eb83d22
use llscheck (wip)
pynappo Feb 17, 2025
2243fca
fix version
pynappo Feb 17, 2025
23a1587
reduce versions for llscheck
pynappo Feb 20, 2025
64b7a94
Use more makefile
pynappo Feb 20, 2025
410ef58
allow ci to be manually run
pynappo Feb 20, 2025
2295b9f
update test script
pynappo Feb 20, 2025
e963be9
update gitignore
pynappo Feb 20, 2025
f6b4fa9
Update makefile & workflows, add luvit-meta dependency
pynappo Feb 21, 2025
dead593
ignore .lua/.luarocks in llscheck
pynappo Feb 21, 2025
2020146
change llscheck config
pynappo Feb 21, 2025
fcd7c2a
fix llscheck makefile targetg
pynappo Feb 21, 2025
70bc6fc
remove current dir from github workflow luarc
pynappo Feb 21, 2025
0391c6f
refine types
pynappo Feb 22, 2025
d5f77da
remove unused highlight fields
pynappo Feb 24, 2025
d5f2b04
use lua ls's new check format instead of llscheck
pynappo Feb 25, 2025
f13e7ba
finish a rename
pynappo Feb 25, 2025
3792977
update all luarc
pynappo Feb 26, 2025
9282a80
fix typo
pynappo Feb 27, 2025
45e2622
no need for luvit-meta
pynappo Mar 2, 2025
46d7259
Merge branch 'main' into typed-config
pynappo Mar 2, 2025
be91ecc
type components
pynappo Mar 2, 2025
9f1e223
simplify component types
pynappo Mar 3, 2025
b3fc6ce
fix component types
pynappo Mar 4, 2025
6d71a3a
make more fields optional
pynappo Mar 4, 2025
0d74570
update types
pynappo Mar 5, 2025
f7713f1
make all config optional
pynappo Mar 5, 2025
1d6326e
restore defaults.lua for now
pynappo Mar 5, 2025
7aee6c5
remove unused local
pynappo Mar 5, 2025
78e2320
update event type
pynappo Mar 5, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions .github/workflows/.luarc-5.1.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"diagnostics.libraryFiles": "Disable",
"runtime": {
"version": "Lua 5.1",
"path": [
"lua/?.lua",
"lua/?/init.lua",
"library/?.lua",
"library/?/init.lua"
]
},
"workspace": {
"checkThirdParty": "Disable",
"library": [
"$PWD/.dependencies/site/pack/vendor/start/plenary.nvim",
"$PWD/.dependencies/site/pack/vendor/start/nui.nvim",
"$PWD/.dependencies/site/pack/vendor/start/nvim-web-devicons",
"${3rd}/luassert",
"${3rd}/busted",
"${3rd}/luv",
"$VIMRUNTIME"
],
"ignoreDir": [
".dependencies",
".luarocks"
]
}
}
29 changes: 29 additions & 0 deletions .github/workflows/.luarc-luajit-master.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
{
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"diagnostics.libraryFiles": "Disable",
"runtime": {
"version": "LuaJIT",
"path": [
"lua/?.lua",
"lua/?/init.lua",
"library/?.lua",
"library/?/init.lua"
]
},
"workspace": {
"checkThirdParty": "Disable",
"library": [
"$PWD/.dependencies/site/pack/vendor/start/plenary.nvim",
"$PWD/.dependencies/site/pack/vendor/start/nui.nvim",
"$PWD/.dependencies/site/pack/vendor/start/nvim-web-devicons",
"${3rd}/luassert",
"${3rd}/busted",
"${3rd}/luv",
"$VIMRUNTIME"
],
"ignoreDir": [
".dependencies",
".luarocks"
]
}
}
4 changes: 3 additions & 1 deletion .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ on:
- v2.x
- v3.x
pull_request:
workflow_dispatch:

jobs:
stylua-check:
Expand Down Expand Up @@ -76,7 +77,8 @@ jobs:
- name: Run tests
run: |
export PATH="${PWD}/build/bin:${PATH}"
./scripts/test.sh
make setup
make test

# - name: Upload coverage to Codecov
# uses: codecov/codecov-action@v2
36 changes: 36 additions & 0 deletions .github/workflows/luals-check.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
name: Lua Language Server Diagnostics
on:
pull_request: ~
push:
branches:
- '*'

jobs:
luals-check:
strategy:
matrix:
neovim: ["0.10"]
lua: ["5.1", "luajit-master"]
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v4

- uses: luarocks/gh-actions-lua@v10
with:
luaVersion: ${{matrix.lua}}

- name: Install lua-language-server
uses: jdx/mise-action@v2
with:
mise_toml: |
[tools]
neovim = "${{ matrix.neovim }}"
lua-language-server = "latest"

- name: Run lua-language-server check
continue-on-error: true
run: |
LUARC=".github/workflows/.luarc-${{ matrix.lua }}.json"
make luals-check CONFIGURATION="$LUARC"
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -44,4 +44,5 @@ tags

# Others
.testcache
.dependencies
luacov.*.out
28 changes: 27 additions & 1 deletion .luarc.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,29 @@
{
"diagnostics.globals": ["vim"]
"$schema": "https://raw.githubusercontent.com/sumneko/vscode-lua/master/setting/schema.json",
"diagnostics.libraryFiles": "Disable",
"runtime": {
"version": "LuaJIT",
"path": [
"lua/?.lua",
"lua/?/init.lua",
"library/?.lua",
"library/?/init.lua"
]
},
"workspace": {
"checkThirdParty": "Disable",
"library": [
"$PWD/.dependencies/site/pack/vendor/start/plenary.nvim",
"$PWD/.dependencies/site/pack/vendor/start/nui.nvim",
"$PWD/.dependencies/site/pack/vendor/start/nvim-web-devicons",
"${3rd}/luassert",
"${3rd}/busted",
"${3rd}/luv",
"$VIMRUNTIME"
],
"ignoreDir": [
".dependencies",
".luarocks"
]
}
}
27 changes: 27 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,30 @@ test-docker:
.PHONY: format
format:
stylua --glob '*.lua' --glob '!defaults.lua' .

# Dependencies:

DEPS := ./.dependencies/site/pack/vendor/start

$(DEPS):
mkdir -p "$(DEPS)"

$(DEPS)/nui.nvim: $(DEPS)
@test -d "$(DEPS)/nui.nvim" || git clone https://github.com/MunifTanjim/nui.nvim "$(DEPS)/nui.nvim"

$(DEPS)/nvim-web-devicons: $(DEPS)
@test -d "$(DEPS)/nvim-web-devicons" || git clone https://github.com/nvim-tree/nvim-web-devicons "$(DEPS)/nvim-web-devicons"

$(DEPS)/plenary.nvim: $(DEPS)
@test -d "$(DEPS)/plenary.nvim" || git clone https://github.com/nvim-lua/plenary.nvim "$(DEPS)/plenary.nvim"

setup: $(DEPS)/nui.nvim $(DEPS)/nvim-web-devicons $(DEPS)/plenary.nvim
@echo "[setup] environment ready"

.PHONY: clean
clean:
rm -rf "$(DEPS)"

CONFIGURATION = .luarc.json
luals-check: setup
VIMRUNTIME="`nvim --clean --headless --cmd 'lua io.write(vim.env.VIMRUNTIME)' --cmd 'quit'`" lua-language-server --configpath=$(CONFIGURATION) --check=.
2 changes: 2 additions & 0 deletions lua/neo-tree.lua
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ M.close_all = function()
require("neo-tree.command").execute({ action = "close" })
end

---@type neotree.Config?
local new_user_config = nil

---Updates the config of neo-tree using the latest user config passed through setup, if any.
Expand Down Expand Up @@ -98,6 +99,7 @@ local function try_netrw_hijack(path)
return false
end

---@param config neotree.Config
M.setup = function(config)
-- merging is deferred until ensure_config
new_user_config = config
Expand Down
1 change: 1 addition & 0 deletions lua/neo-tree/defaults.lua
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
---@type neotree.Config
local config = {
-- If a user has a sources list it will replace this one.
-- Only sources listed here will be loaded.
Expand Down
2 changes: 2 additions & 0 deletions lua/neo-tree/events/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local q = require("neo-tree.events.queue")
local log = require("neo-tree.log")
local utils = require("neo-tree.utils")

---@class neotree.Event.Functions
local M = {
-- Well known event names, you can make up your own
AFTER_RENDER = "after_render",
Expand Down Expand Up @@ -52,6 +53,7 @@ local M = {
VIM_WIN_ENTER = "vim_win_enter",
}

---@param event_name neotree.Event|string
M.define_autocmd_event = function(event_name, autocmds, debounce_frequency, seed_fn, nested)
local opts = {
setup = function()
Expand Down
6 changes: 6 additions & 0 deletions lua/neo-tree/events/queue.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ local event_queues = {}
local event_definitions = {}
local M = {}

---@class neotree.Event.Handler
---@field event neotree.Event|string
---@field handler fun(...)
---@field id string?

local validate_event_handler = function(event_handler)
if type(event_handler) ~= "table" then
error("Event handler must be a table")
Expand Down Expand Up @@ -104,6 +109,7 @@ M.fire_event = function(event, args)
end
end

---@param event_handler neotree.Event.Handler
M.subscribe = function(event_handler)
validate_event_handler(event_handler)

Expand Down
9 changes: 5 additions & 4 deletions lua/neo-tree/setup/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -470,6 +470,8 @@ local merge_renderers = function(default_config, source_default_config, user_con
end
end

---@param user_config neotree.Config?
---@return neotree.Config._Full full_config
M.merge_config = function(user_config)
local default_config = vim.deepcopy(defaults)
user_config = vim.deepcopy(user_config or {})
Expand Down Expand Up @@ -538,7 +540,7 @@ M.merge_config = function(user_config)
-- used to either limit the sources that or loaded, or add extra external sources
local all_sources = {}
local all_source_names = {}
for _, source in ipairs(user_config.sources or default_config.sources) do
for _, source in ipairs(user_config.sources or default_config.sources or {}) do
local parts = utils.split(source, ".")
local name = parts[#parts]
local is_internal_ns, is_external_ns = false, false
Expand Down Expand Up @@ -624,11 +626,10 @@ M.merge_config = function(user_config)
end
--print(vim.inspect(default_config.filesystem))

-- Moving user_config.sources to user_config.orig_sources
user_config.orig_sources = user_config.sources and user_config.sources or {}
-- local orig_sources = user_config.sources and user_config.sources or {}

-- apply the users config
M.config = vim.tbl_deep_extend("force", default_config, user_config)
M.config = vim.tbl_deep_extend("force", default_config, user_config) --[[@as neotree.Config._Full]]

-- RE: 873, fixes issue with invalid source checking by overriding
-- source table with name table
Expand Down
10 changes: 10 additions & 0 deletions lua/neo-tree/sources/buffers/components.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,18 @@ local highlights = require("neo-tree.ui.highlights")
local common = require("neo-tree.sources.common.components")
local utils = require("neo-tree.utils")

---@alias neotree.Component.Buffers._Key
---|"name"

---@class neotree.Component.Buffers
---@field [1] neotree.Component.Buffers._Key|neotree.Component.Common._Key

---@type table<neotree.Component.Buffers._Key, neotree.Renderer>
local M = {}

---@class (exact) neotree.Component.Buffers.Name : neotree.Component.Common.Name

---@param config neotree.Component.Buffers.Name
M.name = function(config, node, state)
local highlight = config.highlight or highlights.FILE_NAME_OPENED
local name = node.name
Expand Down
Loading
Loading