From ff19fef779e1f56951864a6ca675bf07d4660417 Mon Sep 17 00:00:00 2001 From: Martino Ferrari Date: Mon, 2 Feb 2026 14:26:19 +0100 Subject: [PATCH] Fixed isolated file indexing --- internal/index/index.go | 8 ++++++- internal/lsp/server.go | 17 ++++++++++++-- test/isolation_test.go | 38 ++++++++++++++++++++++++++++++++ test/lsp_completion_test.go | 4 ++-- test/lsp_signal_test.go | 4 ++-- test/validator_multifile_test.go | 4 ++-- 6 files changed, 66 insertions(+), 9 deletions(-) create mode 100644 test/isolation_test.go diff --git a/internal/index/index.go b/internal/index/index.go index 930ca5a..18832e8 100644 --- a/internal/index/index.go +++ b/internal/index/index.go @@ -182,7 +182,13 @@ func (pt *ProjectTree) AddFile(file string, config *parser.Configuration) { } if config.Package == nil { - pt.populateNode(pt.Root, file, config) + node := &ProjectNode{ + Children: make(map[string]*ProjectNode), + Metadata: make(map[string]string), + Variables: make(map[string]VariableInfo), + } + pt.IsolatedFiles[file] = node + pt.populateNode(node, file, config) return } diff --git a/internal/lsp/server.go b/internal/lsp/server.go index 10cd72e..24e9389 100644 --- a/internal/lsp/server.go +++ b/internal/lsp/server.go @@ -716,9 +716,16 @@ func HandleCompletion(params CompletionParams) *CompletionList { return nil } -func suggestGAMSignals(_ *index.ProjectNode, direction string) *CompletionList { +func suggestGAMSignals(container *index.ProjectNode, direction string) *CompletionList { var items []CompletionItem + // Find scope root + root := container + for root.Parent != nil { + root = root.Parent + } + + var walk func(*index.ProjectNode) processNode := func(node *index.ProjectNode) { if !isDataSource(node) { return @@ -776,7 +783,13 @@ func suggestGAMSignals(_ *index.ProjectNode, direction string) *CompletionList { } } - Tree.Walk(processNode) + walk = func(n *index.ProjectNode) { + processNode(n) + for _, child := range n.Children { + walk(child) + } + } + walk(root) if len(items) > 0 { return &CompletionList{Items: items} diff --git a/test/isolation_test.go b/test/isolation_test.go new file mode 100644 index 0000000..4780cb1 --- /dev/null +++ b/test/isolation_test.go @@ -0,0 +1,38 @@ +package integration + +import ( + "testing" + + "github.com/marte-community/marte-dev-tools/internal/index" + "github.com/marte-community/marte-dev-tools/internal/parser" +) + +func TestIsolatedFileIsolation(t *testing.T) { + pt := index.NewProjectTree() + + // File 1: Project file + f1 := "#package P\n+A = { Class = C }" + p1 := parser.NewParser(f1) + c1, _ := p1.Parse() + pt.AddFile("f1.marte", c1) + + // File 2: Isolated file + f2 := "+B = { Class = C }" + p2 := parser.NewParser(f2) + c2, _ := p2.Parse() + pt.AddFile("f2.marte", c2) + + pt.ResolveReferences() + + // Try finding A from f2 + isoNode := pt.IsolatedFiles["f2.marte"] + if pt.ResolveName(isoNode, "A", nil) != nil { + t.Error("Isolated file f2 should not see global A") + } + + // Try finding B from f1 + pNode := pt.Root.Children["P"] + if pt.ResolveName(pNode, "B", nil) != nil { + t.Error("Project file f1 should not see isolated B") + } +} \ No newline at end of file diff --git a/test/lsp_completion_test.go b/test/lsp_completion_test.go index 000f177..07822d3 100644 --- a/test/lsp_completion_test.go +++ b/test/lsp_completion_test.go @@ -193,8 +193,8 @@ $App = { } } } - if !foundProjectDS { - t.Error("Expected ProjectDS in isolated file suggestions (now shared root)") + if foundProjectDS { + t.Error("Did not expect ProjectDS in isolated file suggestions (isolation)") } // Completion in a project file diff --git a/test/lsp_signal_test.go b/test/lsp_signal_test.go index 013d5e4..d0480bd 100644 --- a/test/lsp_signal_test.go +++ b/test/lsp_signal_test.go @@ -45,9 +45,9 @@ func TestLSPSignalReferences(t *testing.T) { v.ValidateProject() // Find definition of MySig in MyDS - root := idx.Root + root := idx.IsolatedFiles["signal_refs.marte"] if root == nil { - t.Fatal("Root node not found") + t.Fatal("Root node not found (isolated)") } // Traverse to MySig diff --git a/test/validator_multifile_test.go b/test/validator_multifile_test.go index e02820e..3c6a40d 100644 --- a/test/validator_multifile_test.go +++ b/test/validator_multifile_test.go @@ -194,7 +194,7 @@ func TestIsolatedFileValidation(t *testing.T) { t.Fatal("Reference SharedObj not found in index") } - if ref.Target == nil { - t.Errorf("Expected reference in root file (iso.marte) to resolve to global SharedObj") + if ref.Target != nil { + t.Errorf("Isolation failure: reference in isolated file resolved to global object") } }