-
-
Notifications
You must be signed in to change notification settings - Fork 330
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
[feature] Support pre-commit hook #2343
Comments
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config
You may be able to write your own precommit script that utilizes |
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config
Can it return 1 when problems found? It can be used by pre-commit. |
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config
LuaLS/lua-language-server#2343 Remove luaformatter pre-commit hook for lua-language-server Add cppcheck to coc-diagnostic Add some templates Update PKGBUILD template for cmake Add v2ex, disqus Remove the content about github codespace from README.md Fix the bug about missing lua Fix user.js template Rename/Add some templates Add /usr/src/linux/include to &path Add coc-tsserver, coc-eslint Update user.js template Add supertux2 config Rename .p10k.zsh romkatv/powerlevel10k#2437
AFAIK, someone has created a Github Action for this automated check, but I forgot the name of the project. |
Hard, because script/cli/check.lua use multi process, main process cannot know if sub process find error. |
I guess main process can know the exit code of sub process. So if sub process uses For example:
if _G['CHECK_WORKER'] then
local checkPassed = require 'cli.check_worker'
os.exit(checkPassed and 0 or 1, true)
end
local checkPassed = true
for _, process in ipairs(procs) do
checkPassed = process:wait() == 0 and checkPassed
end
...
return checkPassed
if _G['CHECK'] then
local checkPassed = require 'cli.check'
os.exit(checkPassed and 0 or 1, true)
end |
you can see a lua-ls script in these nix pre-commit hooks https://github.com/cachix/git-hooks.nix/blob/master/modules/hooks.nix that handles checking for errors by using a a wrapper and checking check.json file contents after the run. I'm writing a similar shell script wrapper and ran into some other problems. for example --check doesn't seem to support checking a single file(?), only a directory. but that is very slow if you only want to check changed files. if you filter the pre-commit rule for only .lua files, it will pass each lua file as an argument to the script, and also possibly make multiple invocations, so you have to cope with that to avoid constantly rerunning --check across the whole directory multiple times. Definitely seems it would be useful if there was a --check-files option or something |
Isn't that text = ''
set -e
export logpath="$(mktemp -d)"
lua-language-server --check $(realpath .) \
--checklevel="${hooks.lua-ls.settings.checklevel}" \
--configpath="${luarc-dir}/.luarc.json" \
--logpath="$logpath"
if [[ -f $logpath/check.json ]]; then
echo "+++++++++++++++ lua-language-server diagnostics +++++++++++++++"
cat $logpath/check.json
exit 1
fi
''; In my github action lint workflow, I just use # exit error if any
if [ $(jq -r 'length' ${LUALS_RESULT_FILE}) -gt 0 ]; then
exit 1
fi
I also thought about this when I integrate LuaLS into my project's gha lint workflow. I have been using Let me give an example. In a project you have a This kind of problem doesn't exist in
Btw did you try the I used this in my gha workflow, but unfortunately I can only use |
Sorry to find it for late. Can you provide a PR for your prove of concept? if count == 0 then
print(lang.script('CLI_CHECK_SUCCESS'))
else
print(lang.script('CLI_CHECK_RESULTS', count, outpath))
end cannot work. |
|
Simply adding I see that you have opened #2998 which largely follows my suggestion above. Glad that it works out 😄
AFAIK, since some version of LuaLS,
Some reported that before v3.8 (?) it supports passing just a file: #2989, #2749 In my own opinion, since the diagnostics performed by LuaLS is a workspace-wise (some meta definition maybe defined in another file in the workspace), it makes little sense to support passing a single file? 🤔 There is no single file mode diagnostics (?), as opposed to PS: I am no maintainer, so my understanding may not be 100% correct 🙈 |
I try to support check single file: diff --git a/script/cli/check_worker.lua b/script/cli/check_worker.lua
index a2e0bff..eb1a491 100644
--- a/script/cli/check_worker.lua
+++ b/script/cli/check_worker.lua
@@ -27,8 +27,14 @@ function export.runCLI()
print(lang.script('CLI_CHECK_ERROR_TYPE', type(CHECK_WORKER)))
return
end
+ local filepath = fs.path(CHECK_WORKER)
+ local is_directory = fs.is_directory(filepath)
- local rootPath = fs.absolute(fs.path(CHECK_WORKER)):string()
+ local path = filepath
+ if not is_directory then
+ path = fs.path('.')
+ end
+ local rootPath = fs.absolute(path):string()
local rootUri = furi.encode(rootPath)
if not rootUri then
print(lang.script('CLI_CHECK_ERROR_URI', rootPath))
@@ -102,6 +108,9 @@ function export.runCLI()
config.set(rootUri, 'Lua.diagnostics.neededFileStatus', diagStatus)
local uris = files.getChildFiles(rootUri)
+ if not is_directory then
+ uris = { furi.encode(fs.absolute(filepath):string()) }
+ end
local max = #uris
table.sort(uris) -- sort file list to ensure the work distribution order across multiple threads
for i, uri in ipairs(uris) do However, it cannot work:
Support pre-commit needs:
|
Just by looking at the output, I guess if the
To support checking only single file, I have a few questions:
|
know it from
Perhaps |
This may work in your pre commit hook case, but I don't think this will work in general. 😕
In short, just assuming
That's a great idea 👍 directory mode
file(s) mode
By forcing relative paths arguments in file mode, then it makes sense to assume PS: these are just my opinions, it doesn't represent maintainers' opinions 😄 |
Wait a minute, I still think that single file mode is not suitable for LuaLS. Lets consider the following minimal example:
---@class Foo
---@type Foo
local foo A very simple one, where Now someone edited the ---@class Bar and then commit it
This is what I want to express, LuaLS diagnostics is workspace-wise. |
Can it support pre-commit like https://github.com/Koihik/LuaFormatter? TIA!
The text was updated successfully, but these errors were encountered: