Skip to content

Commit

Permalink
tl types: split symbols into symbols_by_file
Browse files Browse the repository at this point in the history
  • Loading branch information
hishamhm committed Aug 21, 2024
1 parent 9e483f4 commit dcf9889
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 8 deletions.
4 changes: 3 additions & 1 deletion tl
Original file line number Diff line number Diff line change
Expand Up @@ -1339,7 +1339,8 @@ do
tlconfig["quiet"] = true
tlconfig["gen_compat"] = "off"

local env = setup_env(tlconfig, args["file"][1])
local filename = args["file"][1]
local env = setup_env(tlconfig, filename)
env.keep_going = true

local tr, trenv
Expand Down Expand Up @@ -1367,6 +1368,7 @@ do
x = tonumber(x) or 1
json_out_table(io.stdout, tl.symbols_in_scope(tr, y, x))
else
tr.symbols = tr.symbols_by_file[filename]
json_out_table(io.stdout, tr)
end

Expand Down
14 changes: 11 additions & 3 deletions tl.lua
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,9 @@ local tl = {PrettyPrintOptions = {}, TypeCheckOptions = {}, Env = {}, Symbol = {









Expand Down Expand Up @@ -10621,7 +10624,7 @@ function tl.get_types(result, trenv)
tr = {
by_pos = {},
types = {},
symbols = mark_array({}),
symbols_by_file = {},
globals = {},
},
}
Expand Down Expand Up @@ -10773,6 +10776,9 @@ function tl.get_types(result, trenv)
end
end

local symbols = mark_array({})
tr.symbols_by_file[filename] = symbols


do
local stack = {}
Expand All @@ -10791,11 +10797,11 @@ function tl.get_types(result, trenv)
else
local other = stack[level]
level = level - 1
tr.symbols[other][4] = i
symbols[other][4] = i
id = other - 1
end
local sym = mark_array({ s.y, s.x, s.name, id })
table.insert(tr.symbols, sym)
table.insert(symbols, sym)
end
end
end
Expand All @@ -10808,6 +10814,8 @@ function tl.get_types(result, trenv)
end
end

tr.symbols = tr.symbols_by_file[filename]

return tr, trenv
end

Expand Down
16 changes: 12 additions & 4 deletions tl.tl
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,12 @@ local record tl
end

record TypeReport
type Symbol = {integer, integer, string, integer}

by_pos: {string: {integer: {integer: integer}}}
types: {integer: TypeInfo}
symbols: {{integer, integer, string, integer}}
symbols: {Symbol}
symbols_by_file: {string: {Symbol}}
globals: {string: integer}
end

Expand Down Expand Up @@ -10621,7 +10624,7 @@ function tl.get_types(result: Result, trenv: TypeReportEnv): TypeReport, TypeRep
tr = {
by_pos = {},
types = {},
symbols = mark_array {},
symbols_by_file = {},
globals = {},
},
}
Expand Down Expand Up @@ -10773,6 +10776,9 @@ function tl.get_types(result: Result, trenv: TypeReportEnv): TypeReport, TypeRep
end
end

local symbols: {TypeReport.Symbol} = mark_array {}
tr.symbols_by_file[filename] = symbols

-- resolve scope cross references, skipping unneeded scope blocks
do
local stack = {}
Expand All @@ -10791,11 +10797,11 @@ function tl.get_types(result: Result, trenv: TypeReportEnv): TypeReport, TypeRep
else
local other = stack[level]
level = level - 1
tr.symbols[other][4] = i -- overwrite id from @{
symbols[other][4] = i -- overwrite id from @{
id = other - 1
end
local sym = mark_array({ s.y, s.x, s.name, id })
table.insert(tr.symbols, sym)
table.insert(symbols, sym)
end
end
end
Expand All @@ -10808,6 +10814,8 @@ function tl.get_types(result: Result, trenv: TypeReportEnv): TypeReport, TypeRep
end
end

tr.symbols = tr.symbols_by_file[filename]

return tr, trenv
end

Expand Down

0 comments on commit dcf9889

Please sign in to comment.