diff --git a/tl b/tl index 95a824d2b..093ac9cfa 100755 --- a/tl +++ b/tl @@ -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 @@ -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 diff --git a/tl.lua b/tl.lua index 3863e8679..31d7d7804 100644 --- a/tl.lua +++ b/tl.lua @@ -136,6 +136,9 @@ local tl = {PrettyPrintOptions = {}, TypeCheckOptions = {}, Env = {}, Symbol = { + + + @@ -10621,7 +10624,7 @@ function tl.get_types(result, trenv) tr = { by_pos = {}, types = {}, - symbols = mark_array({}), + symbols_by_file = {}, globals = {}, }, } @@ -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 = {} @@ -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 @@ -10808,6 +10814,8 @@ function tl.get_types(result, trenv) end end + tr.symbols = tr.symbols_by_file[filename] + return tr, trenv end diff --git a/tl.tl b/tl.tl index 0abe1689b..1eb4901c5 100644 --- a/tl.tl +++ b/tl.tl @@ -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 @@ -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 = {}, }, } @@ -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 = {} @@ -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 @@ -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