mirror of
https://github.com/lukaszraczylo/filepuff-mcp.git
synced 2026-10-12 04:54:27 +00:00
edit.ValidateLanguage had zero callers (only its own godoc referenced it) — removed. yaml_json.go: contrary to the audit's claim, the file is NOT entirely dead — ParseYAML/ParseJSON are live via the Parse() dispatch (parser.go:198-200) and are kept with their tests. Removed only the genuinely unreachable scaffolding that nothing constructs or calls: the YAMLNode/JSONNode types, WalkYAML, GetYAMLNodeText, GetYAMLNodeLocation, QueryYAML, QueryJSON, ValidateYAML, ValidateJSON, and ToSitterTree, plus their now-orphaned tests. YAML/JSON parsing behavior is unchanged (TestParseYAML/TestParseJSON/TestRegistryParse_YAML_JSON still pass).
59 lines
1.8 KiB
Go
59 lines
1.8 KiB
Go
// Package parser provides YAML and JSON parsing with AST support.
|
|
package parser
|
|
|
|
import (
|
|
"context"
|
|
"encoding/json"
|
|
|
|
"gopkg.in/yaml.v3"
|
|
|
|
"github.com/lukaszraczylo/mcp-filepuff/pkg/errors"
|
|
"github.com/lukaszraczylo/mcp-filepuff/pkg/protocol"
|
|
)
|
|
|
|
// ParseYAML parses YAML content and returns a tree-sitter-compatible result.
|
|
// YAML does not use tree-sitter, so the returned ParseResult.Tree is nil.
|
|
func (r *Registry) ParseYAML(ctx context.Context, filename string, content []byte) (*ParseResult, error) {
|
|
if len(content) > maxFileSize {
|
|
return nil, errors.NewFileTooLarge(filename, int64(len(content)), maxFileSize)
|
|
}
|
|
|
|
var root yaml.Node
|
|
if err := yaml.Unmarshal(content, &root); err != nil {
|
|
return nil, errors.NewParseError("yaml", filename, err)
|
|
}
|
|
|
|
return &ParseResult{
|
|
Tree: nil, // YAML uses yaml.Node instead of tree-sitter
|
|
Language: protocol.LangYAML,
|
|
Errors: extractYAMLErrors(),
|
|
Content: content,
|
|
}, nil
|
|
}
|
|
|
|
// ParseJSON parses JSON content and returns a tree-sitter-compatible result.
|
|
// JSON does not use tree-sitter, so the returned ParseResult.Tree is nil.
|
|
func (r *Registry) ParseJSON(ctx context.Context, filename string, content []byte) (*ParseResult, error) {
|
|
if len(content) > maxFileSize {
|
|
return nil, errors.NewFileTooLarge(filename, int64(len(content)), maxFileSize)
|
|
}
|
|
|
|
var jsonData any
|
|
if err := json.Unmarshal(content, &jsonData); err != nil {
|
|
return nil, errors.NewParseError("json", filename, err)
|
|
}
|
|
|
|
return &ParseResult{
|
|
Tree: nil, // JSON uses native Go structures
|
|
Language: protocol.LangJSON,
|
|
Errors: []SyntaxError{},
|
|
Content: content,
|
|
}, nil
|
|
}
|
|
|
|
// extractYAMLErrors returns YAML syntax errors. yaml.Unmarshal already reports
|
|
// parse errors, so reaching here means the document was syntactically valid.
|
|
func extractYAMLErrors() []SyntaxError {
|
|
return []SyntaxError{}
|
|
}
|