Fixed isolated file indexing
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -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}
|
||||
|
||||
38
test/isolation_test.go
Normal file
38
test/isolation_test.go
Normal file
@@ -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")
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user