Skip to content

Commit

Permalink
feat: add scripts for .luarc.json
Browse files Browse the repository at this point in the history
  • Loading branch information
max397574 committed Jun 15, 2024
1 parent a06f5f9 commit 146f3c4
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 14 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
todo.norg
.libraries/
.luarc.json
9 changes: 0 additions & 9 deletions .luarc.json

This file was deleted.

6 changes: 6 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,9 @@ You can get third party libraries for type annotations by doing
```bash
make install_libraries
```

Then use
```bash
bash scripts/write_luarc.sh
```
from the root directory of this repo to generate a `.luarc.json` file to configure luals to use the type annotations.
37 changes: 37 additions & 0 deletions scripts/write_luarc.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
local function tofile(fname, text)
local f = io.open(fname, "w")
if not f then
error(("failed to write: %s"):format(f))
else
print(("Written to: %s"):format(fname))
f:write(text)
f:close()
end
end

local out = nil
local i = 1
while i <= #_G.arg do
if _G.arg[i] == "--out" then
out = assert(_G.arg[i + 1], "--out <outfile> needed")
i = i + 1
end
i = i + 1
end

local libraries = {
[["./.libraries/busted/library/"]],
[["./.libraries/luassert/library/"]],
[["./.libraries/luv/library/"]],
'"' .. vim.fn.expand("$VIMRUNTIME" .. "/lua", false, true)[1] .. '"',
}

local lines = {
"{",
[[ "$schema": "https://raw.githubusercontent.com/LuaLS/vscode-lua/master/setting/schema.json",]],
[[ "runtime.version": "LuaJIT",]],
}
table.insert(lines, ' "workspace.library": [\n ' .. table.concat(libraries, ",\n ") .. "\n ]")
table.insert(lines, "}")

tofile(out, table.concat(lines, "\n"))
3 changes: 3 additions & 0 deletions scripts/write_luarc.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/env bash

nvim --headless --clean -l scripts/write_luarc.lua --out .luarc.json
5 changes: 0 additions & 5 deletions spec/example_spec.lua

This file was deleted.

0 comments on commit 146f3c4

Please sign in to comment.