Skip to content

Commit 74e74d2

Browse files
authored
Merge branch 'master' into generic-pattern1
2 parents 647971c + 3e6fd3c commit 74e74d2

37 files changed

+1613
-81
lines changed

.github/workflows/test.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: test
2+
on: [ push, pull_request ]
3+
jobs:
4+
test:
5+
strategy:
6+
fail-fast: false
7+
matrix:
8+
include:
9+
- { os: ubuntu-20.04, platform: linux-x64 }
10+
- { os: macos-latest, platform: darwin-x64 }
11+
- { os: windows-latest, platform: win32-x64 }
12+
runs-on: ${{ matrix.os }}
13+
steps:
14+
- uses: actions/checkout@v4
15+
with:
16+
submodules: recursive
17+
- uses: actboy168/setup-luamake@master
18+
- run: luamake -platform ${{ matrix.platform }}

3rd/json.lua

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
# changelog
22

3+
## 3.7.5
4+
* `FIX` rename in library files
5+
36
## 3.7.4
47
`2024-1-5`
58
* `FIX` rename to unicode with `Lua.runtime.unicodeName = true`

meta/template/table.lua

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ function table.insert(list, pos, value) end
2727
---@nodiscard
2828
function table.maxn(table) end
2929

30-
---@version >5.3
30+
---@version >5.3, JIT
3131
---#DES 'table.move'
3232
---@param a1 table
3333
---@param f integer

script/cli/doc.lua

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,6 +169,7 @@ local function collectTypes(global, results)
169169
field.desc = getDesc(source)
170170
field.rawdesc = getDesc(source, true)
171171
field.extends = packObject(source.extends)
172+
field.visible = vm.getVisibleType(source)
172173
return
173174
end
174175
if source.type == 'setfield'
@@ -187,6 +188,7 @@ local function collectTypes(global, results)
187188
field.desc = getDesc(source)
188189
field.rawdesc = getDesc(source, true)
189190
field.extends = packObject(source.value)
191+
field.visible = vm.getVisibleType(source)
190192
return
191193
end
192194
if source.type == 'tableindex' then
@@ -207,6 +209,7 @@ local function collectTypes(global, results)
207209
field.desc = getDesc(source)
208210
field.rawdesc = getDesc(source, true)
209211
field.extends = packObject(source.value)
212+
field.visible = vm.getVisibleType(source)
210213
return
211214
end
212215
end)
@@ -245,6 +248,8 @@ local function collectVars(global, results)
245248
}
246249
result.desc = result.desc or getDesc(set)
247250
result.rawdesc = result.rawdesc or getDesc(set, true)
251+
result.defines[#result.defines].extends['desc'] = getDesc(set)
252+
result.defines[#result.defines].extends['rawdesc'] = getDesc(set, true)
248253
end
249254
end
250255
if #result.defines == 0 then
@@ -292,6 +297,18 @@ function export.export(outputPath, callback)
292297
return docPath, mdPath
293298
end
294299

300+
function export.getDocOutputPath()
301+
local doc_output_path = ''
302+
if type(DOC_OUT_PATH) == 'string' then
303+
doc_output_path = fs.absolute(fs.path(DOC_OUT_PATH)):string()
304+
elseif DOC_OUT_PATH == true then
305+
doc_output_path = fs.current_path():string()
306+
else
307+
doc_output_path = LOGPATH
308+
end
309+
return doc_output_path
310+
end
311+
295312
---@async
296313
---@param outputPath string
297314
function export.makeDoc(outputPath)
@@ -350,7 +367,7 @@ function export.runCLI()
350367
ws.awaitReady(rootUri)
351368
await.sleep(0.1)
352369

353-
local docPath, mdPath = export.export(LOGPATH, function (i, max)
370+
local docPath, mdPath = export.export(export.getDocOutputPath(), function (i, max)
354371
if os.clock() - lastClock > 0.2 then
355372
lastClock = os.clock()
356373
local output = '\x0D'

script/cli/init.lua

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,3 +12,8 @@ if _G['DOC'] then
1212
require 'cli.doc' .runCLI()
1313
os.exit(0, true)
1414
end
15+
16+
if _G['VISUALIZE'] then
17+
local ret = require 'cli.visualize' .runCLI()
18+
os.exit(ret or 0, true)
19+
end

script/cli/visualize.lua

Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
local lang = require 'language'
2+
local parser = require 'parser'
3+
local guide = require 'parser.guide'
4+
5+
local function nodeId(node)
6+
return node.type .. ':' .. node.start .. ':' .. node.finish
7+
end
8+
9+
local function shorten(str)
10+
if type(str) ~= 'string' then
11+
return str
12+
end
13+
str = str:gsub('\n', '\\\\n')
14+
if #str <= 20 then
15+
return str
16+
else
17+
return str:sub(1, 17) .. '...'
18+
end
19+
end
20+
21+
local function getTooltipLine(k, v)
22+
if type(v) == 'table' then
23+
if v.type then
24+
v = '<node ' .. v.type .. '>'
25+
else
26+
v = '<table>'
27+
end
28+
end
29+
v = tostring(v)
30+
v = v:gsub('"', '\\"')
31+
return k .. ': ' .. shorten(v) .. '\\n'
32+
end
33+
34+
local function getTooltip(node)
35+
local str = ''
36+
local skipNodes = {parent = true, start = true, finish = true, type = true}
37+
str = str .. getTooltipLine('start', node.start)
38+
str = str .. getTooltipLine('finish', node.finish)
39+
for k, v in pairs(node) do
40+
if type(k) ~= 'number' and not skipNodes[k] then
41+
str = str .. getTooltipLine(k, v)
42+
end
43+
end
44+
for i = 1, math.min(#node, 15) do
45+
str = str .. getTooltipLine(i, node[i])
46+
end
47+
if #node > 15 then
48+
str = str .. getTooltipLine('15..' .. #node, '(...)')
49+
end
50+
return str
51+
end
52+
53+
local nodeEntry = '\t"%s" [\n\t\tlabel="%s\\l%s\\l"\n\t\ttooltip="%s"\n\t]'
54+
local function getNodeLabel(node)
55+
local keyName = guide.getKeyName(node)
56+
if node.type == 'binary' or node.type == 'unary' then
57+
keyName = node.op.type
58+
elseif node.type == 'label' or node.type == 'goto' then
59+
keyName = node[1]
60+
end
61+
return nodeEntry:format(nodeId(node), node.type, shorten(keyName) or '', getTooltip(node))
62+
end
63+
64+
local function getVisualizeVisitor(writer)
65+
local function visitNode(node, parent)
66+
if node == nil then return end
67+
writer:write(getNodeLabel(node))
68+
writer:write('\n')
69+
if parent then
70+
writer:write(('\t"%s" -> "%s"'):format(nodeId(parent), nodeId(node)))
71+
writer:write('\n')
72+
end
73+
guide.eachChild(node, function(child)
74+
visitNode(child, node)
75+
end)
76+
end
77+
return visitNode
78+
end
79+
80+
81+
local export = {}
82+
83+
function export.visualizeAst(code, writer)
84+
local state = parser.compile(code, 'Lua', _G['LUA_VER'] or 'Lua 5.4')
85+
writer:write('digraph AST {\n')
86+
writer:write('\tnode [shape = rect]\n')
87+
getVisualizeVisitor(writer)(state.ast)
88+
writer:write('}\n')
89+
end
90+
91+
function export.runCLI()
92+
lang(LOCALE)
93+
local file = _G['VISUALIZE']
94+
local code, err = io.open(file)
95+
if not code then
96+
io.stderr:write('failed to open ' .. file .. ': ' .. err)
97+
return 1
98+
end
99+
code = code:read('a')
100+
return export.visualizeAst(code, io.stdout)
101+
end
102+
103+
return export

script/core/rename.lua

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,11 @@ function m.rename(uri, pos, newname)
414414
return
415415
end
416416
mark[uid] = true
417-
if files.isLibrary(turi, true) then
417+
if vm.isMetaFile(turi) then
418+
return
419+
end
420+
if files.isLibrary(turi, true)
421+
and not files.isLibrary(uri, true) then
418422
return
419423
end
420424
results[#results+1] = {

0 commit comments

Comments
 (0)