better multi file support
This commit is contained in:
@@ -59,7 +59,6 @@ func (v *Validator) validateNode(node *index.ProjectNode) {
|
||||
}
|
||||
|
||||
// Check for mandatory Class if it's an object node (+/$)
|
||||
// Root node usually doesn't have a name or is implicit
|
||||
if node.RealName != "" && (node.RealName[0] == '+' || node.RealName[0] == '$') {
|
||||
hasClass := false
|
||||
hasType := false
|
||||
@@ -102,12 +101,75 @@ func (v *Validator) validateNode(node *index.ProjectNode) {
|
||||
}
|
||||
}
|
||||
|
||||
// Legacy/Compatibility method if needed, but we prefer ValidateProject
|
||||
func (v *Validator) Validate(file string, config *parser.Configuration) {
|
||||
// No-op or local checks if any
|
||||
func (v *Validator) CheckUnused() {
|
||||
referencedNodes := make(map[*index.ProjectNode]bool)
|
||||
for _, ref := range v.Tree.References {
|
||||
if ref.Target != nil {
|
||||
referencedNodes[ref.Target] = true
|
||||
}
|
||||
}
|
||||
|
||||
v.checkUnusedRecursive(v.Tree.Root, referencedNodes)
|
||||
}
|
||||
|
||||
func (v *Validator) CheckUnused() {
|
||||
// To implement unused check, we'd need reference tracking in Index
|
||||
// For now, focusing on duplicate fields and class validation
|
||||
func (v *Validator) checkUnusedRecursive(node *index.ProjectNode, referenced map[*index.ProjectNode]bool) {
|
||||
// Heuristic for GAM
|
||||
if isGAM(node) {
|
||||
if !referenced[node] {
|
||||
v.Diagnostics = append(v.Diagnostics, Diagnostic{
|
||||
Level: LevelWarning,
|
||||
Message: fmt.Sprintf("Unused GAM: %s is defined but not referenced in any thread or scheduler", node.RealName),
|
||||
Position: v.getNodePosition(node),
|
||||
File: v.getNodeFile(node),
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// Heuristic for DataSource and its signals
|
||||
if isDataSource(node) {
|
||||
for _, signal := range node.Children {
|
||||
if !referenced[signal] {
|
||||
v.Diagnostics = append(v.Diagnostics, Diagnostic{
|
||||
Level: LevelWarning,
|
||||
Message: fmt.Sprintf("Unused Signal: %s is defined in DataSource %s but never referenced", signal.RealName, node.RealName),
|
||||
Position: v.getNodePosition(signal),
|
||||
File: v.getNodeFile(signal),
|
||||
})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for _, child := range node.Children {
|
||||
v.checkUnusedRecursive(child, referenced)
|
||||
}
|
||||
}
|
||||
|
||||
func isGAM(node *index.ProjectNode) bool {
|
||||
if node.RealName == "" || (node.RealName[0] != '+' && node.RealName[0] != '$') {
|
||||
return false
|
||||
}
|
||||
_, hasInput := node.Children["InputSignals"]
|
||||
_, hasOutput := node.Children["OutputSignals"]
|
||||
return hasInput || hasOutput
|
||||
}
|
||||
|
||||
func isDataSource(node *index.ProjectNode) bool {
|
||||
if node.Parent != nil && node.Parent.Name == "Data" {
|
||||
return true
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (v *Validator) getNodePosition(node *index.ProjectNode) parser.Position {
|
||||
if len(node.Fragments) > 0 {
|
||||
return node.Fragments[0].ObjectPos
|
||||
}
|
||||
return parser.Position{Line: 1, Column: 1}
|
||||
}
|
||||
|
||||
func (v *Validator) getNodeFile(node *index.ProjectNode) string {
|
||||
if len(node.Fragments) > 0 {
|
||||
return node.Fragments[0].File
|
||||
}
|
||||
return ""
|
||||
}
|
||||
Reference in New Issue
Block a user