ci: generate annotations for Lua types#4306
Conversation
|
Hey, thanks for looking into this. With #4010 I had a similar goal, although with a much more limited scope. When this PR is finished, the changes, from a user's perspective, are:
Are these assumptions correct? |
Since the previous way to enable lspconfig followed the I don't intend to deprecate
Yes, this is a very important objective. In fact, neoconf itself doesn't need these type definitions; it generates them purely as a feature to make it convenient for users to use these types within their own configurations. |
cc526cd to
5917d35
Compare
|
I just noticed an issue: since the JSON schemas are all JSON with comments rather than standard JSON, |
I'm favor of that but we don't have a tracking issue for it, nor in https://github.com/openresty/lua-cjson . If it's not too horrible, this may even justify forking cjson if it won't be accepted upstream. cc @skewb1k |
I think it's reasonable to have a flag for that.
We can take a similar approach to neovim/neovim#35574 and neovim/neovim#35424 by opening PRs to both upstream and neovim, and being okay with merging into neovim first. If upstream is not interested, we can certainly diverge. Additionally, I recall some discussions on Matrix regarding hard-forking due to API differences and other factors, so I don't think that's a problem. |
While it's cool to support comments in local function readfile(path)
local file = io.open(path, "r")
if not file then
return nil
end
local content = file:read("*a")
file:close()
return content
end
local dir = "./schemas"
local files = vim.fn.readdir(dir)
for _, file in ipairs(files) do
local file_path = vim.fs.joinpath(dir, file)
local content = readfile(file_path)
vim.json.decode(content)
endRunning this in the root of https://github.com/folke/neoconf.nvim succeeds (introducing comment manually will cause it to fail). |
|
You are correct. I noticed that neoconf uses a JSONC decoder for JSON schemas, which led to my misunderstanding that JSON schemas could be JSONC; they should strictly be standard JSON. The reason neoconf uses JSONC parsing here should because this wrapped function is also used to parse settings.json, which is allowed to be JSONC. Therefore, for this PR, using vim.json is sufficient. |
1948f99 to
22ad3d9
Compare
|
I have completed the essential refactoring; this PR is now in a usable state. |
91e347e to
a30c9d1
Compare
justinmk
left a comment
There was a problem hiding this comment.
The lua/lspconfig/types/lsp.lua file is big and will keep growing. Does it avoid a perf issue if we split it into a bunch of files per-config?
| @@ -1,4 +1,5 @@ | |||
| ---@brief | |||
| ---@schema https://raw.githubusercontent.com/FractalBoy/perl-language-server/master/client/package.json | |||
There was a problem hiding this comment.
is @schema a LuaLS/emmylua feature? should we mention it in the readme?
There was a problem hiding this comment.
This is just something I defined myself so that we can annotate the JSON schema while adding a server. I may need to mention it in the contributing guide or somewhere similar.
However, emmylua-analyzer-rust does have a @schema (https://github.com/EmmyLuaLs/emmylua-analyzer-rust/pull/952)field that functions like @type, using a remote JSON schema as the @type. But it seems to support a limited version of JSON schema. I haven't tried it yet.
I haven't noticed any performance issues during my own use, but the problem is that the default I was just about to apply |
7f4598f to
6470e89
Compare
bb9a2be to
17005fa
Compare
|
the codespell CI should ignore types/ since we don't control the spelling there. |
0f7c62d to
bbfc903
Compare
c52c718 to
e480152
Compare
3dd5244 to
cfdc686
Compare
768327b to
0b847c3
Compare
94fddda to
c5be612
Compare
c62f2c3 to
6b05a26
Compare
| vim.fn.writefile( | ||
| vim.split(vim.json.encode(schema_json, { indent = ' ', sort_keys = true }), '\n', { plain = true }), |
There was a problem hiding this comment.
this reminds me we need neovim/neovim#31930 to make writefile() less annoying :)
| ---Regenerates all schema files under the local `schemas/` directory. | ||
| local function generate_all_schemas() | ||
| ---@diagnostic disable-next-line: param-type-mismatch | ||
| vim.fn.delete(vim.fs.joinpath(vim.uv.cwd(), 'schemas'), 'rf') |
There was a problem hiding this comment.
just fyi, we have vim.fs.rm() now too
|
I just noticed that I lost the |
Add Lua types from the LSP server settings, ref: neovim/nvim-lspconfig#4306 (`gopls` seems to not have one). Completion: - Add `fuzzy` and change `noselect` to `noinsert` in `completeopt`. - blink.cmp: do not automatically insert texts while cycling through the completion items. Correctly remove `~` at the end of a buffer.
Add Lua types from the LSP server settings, ref: neovim/nvim-lspconfig#4306 (`gopls` seems to not have one). Completion: - Add `fuzzy` and change `noselect` to `noinsert` in `completeopt`. - blink.cmp: do not automatically insert texts while cycling through the completion items. Correctly remove `~` at the end of a buffer.
Automatically generate Lua types from the LSP server settings JSON schema

Modified from neoconf.nvim