File tree 3 files changed +9
-3
lines changed
3 files changed +9
-3
lines changed Original file line number Diff line number Diff line change @@ -50,6 +50,8 @@ lsp = [
50
50
lua = [
51
51
" dep:mlua" ,
52
52
" dep:mlua-tree-sitter" ,
53
+ " lsp-positions/lua" ,
54
+ " lsp-positions/tree-sitter" ,
53
55
" stack-graphs/lua" ,
54
56
]
55
57
Original file line number Diff line number Diff line change 9
9
10
10
use std:: borrow:: Cow ;
11
11
12
+ use lsp_positions:: lua:: Module as _;
12
13
use mlua:: Lua ;
13
- use mlua_tree_sitter:: Module ;
14
+ use mlua_tree_sitter:: Module as _ ;
14
15
use mlua_tree_sitter:: WithSource ;
15
16
use stack_graphs:: arena:: Handle ;
16
17
use stack_graphs:: graph:: File ;
@@ -82,6 +83,7 @@ impl StackGraphLanguageLua {
82
83
// Create a Lua environment and load the language's stack graph rules.
83
84
// TODO: Sandbox the Lua environment
84
85
let lua = Lua :: new ( ) ;
86
+ lua. open_lsp_positions ( ) ?;
85
87
lua. open_ltreesitter ( ) ?;
86
88
lua. load ( self . lua_source . as_ref ( ) )
87
89
. set_name ( & self . lua_source_name )
Original file line number Diff line number Diff line change @@ -29,8 +29,10 @@ impl CheckLua for mlua::Lua {
29
29
fn can_build_stack_graph_from_lua ( ) -> Result < ( ) , anyhow:: Error > {
30
30
const LUA : & [ u8 ] = br#"
31
31
function process(parsed, file)
32
- -- TODO: fill in the definiens span from the parse tree root
32
+ local sc = lsp_positions.SpanCalculator.new_from_tree(parsed)
33
+ local module_ast = parsed:root()
33
34
local module = file:internal_scope_node()
35
+ module:set_definiens_span(sc:for_node(module_ast))
34
36
module:add_edge_from(file:root_node())
35
37
end
36
38
"# ;
@@ -52,7 +54,7 @@ fn can_build_stack_graph_from_lua() -> Result<(), anyhow::Error> {
52
54
local graph = ...
53
55
local file = graph:file("test.py")
54
56
assert_deepeq("nodes", {
55
- "[test.py(0) scope]",
57
+ "[test.py(0) scope def 1:6-3:4 ]",
56
58
}, iter_tostring(file:nodes()))
57
59
assert_deepeq("edges", {
58
60
"[root] -0-> [test.py(0) scope]",
You can’t perform that action at this time.
0 commit comments