mirror of
https://github.com/lukaszraczylo/filepuff-mcp.git
synced 2026-10-14 05:30:19 +00:00
multi-fixes
This commit is contained in:
@@ -48,6 +48,8 @@ func ExtractDocComment(n *sitter.Node, content []byte, lang protocol.Language) *
|
||||
return extractCDocComment(n, content)
|
||||
case protocol.LangElixir:
|
||||
return extractElixirDocComment(n, content)
|
||||
case protocol.LangRust:
|
||||
return extractRustDocComment(n, content)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -551,6 +553,64 @@ func cleanPythonDocstring(doc string) string {
|
||||
return strings.TrimSpace(doc)
|
||||
}
|
||||
|
||||
// extractRustDocComment extracts Rust documentation comments (/// style).
|
||||
func extractRustDocComment(n *sitter.Node, content []byte) *DocComment {
|
||||
comments := collectPrecedingComments(n, content, []string{"line_comment"})
|
||||
if len(comments) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
// Filter for /// doc comments only
|
||||
var docComments []*sitter.Node
|
||||
for _, c := range comments {
|
||||
text := GetNodeText(c, content)
|
||||
trimmed := strings.TrimSpace(text)
|
||||
if strings.HasPrefix(trimmed, "///") {
|
||||
docComments = append(docComments, c)
|
||||
}
|
||||
}
|
||||
|
||||
if len(docComments) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
var parts []string
|
||||
var raw []string
|
||||
startLine := -1
|
||||
endLine := -1
|
||||
|
||||
for _, c := range docComments {
|
||||
text := GetNodeText(c, content)
|
||||
raw = append(raw, text)
|
||||
|
||||
if startLine == -1 {
|
||||
startLine = int(c.StartPoint().Row) + 1
|
||||
}
|
||||
endLine = int(c.EndPoint().Row) + 1
|
||||
|
||||
// Clean /// prefix
|
||||
cleaned := strings.TrimSpace(text)
|
||||
cleaned = strings.TrimPrefix(cleaned, "///")
|
||||
if len(cleaned) > 0 && cleaned[0] == ' ' {
|
||||
cleaned = cleaned[1:]
|
||||
}
|
||||
parts = append(parts, cleaned)
|
||||
}
|
||||
|
||||
if len(parts) == 0 {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &DocComment{
|
||||
Text: strings.Join(parts, "\n"),
|
||||
Raw: strings.Join(raw, "\n"),
|
||||
Style: CommentStyleDoxygen,
|
||||
Tags: nil,
|
||||
StartLine: startLine,
|
||||
EndLine: endLine,
|
||||
}
|
||||
}
|
||||
|
||||
// extractElixirDocComment extracts Elixir documentation from @doc and @moduledoc attributes.
|
||||
// Elixir uses module attributes like @doc and @moduledoc for documentation.
|
||||
func extractElixirDocComment(n *sitter.Node, content []byte) *DocComment {
|
||||
|
||||
@@ -18,6 +18,7 @@ import (
|
||||
"github.com/smacker/go-tree-sitter/html"
|
||||
"github.com/smacker/go-tree-sitter/javascript"
|
||||
"github.com/smacker/go-tree-sitter/python"
|
||||
"github.com/smacker/go-tree-sitter/rust"
|
||||
"github.com/smacker/go-tree-sitter/typescript/typescript"
|
||||
|
||||
"github.com/lukaszraczylo/mcp-filepuff/pkg/errors"
|
||||
@@ -117,10 +118,12 @@ func getLanguage(lang protocol.Language) (*sitter.Language, error) {
|
||||
return html.GetLanguage(), nil
|
||||
case protocol.LangElixir:
|
||||
return elixir.GetLanguage(), nil
|
||||
case protocol.LangRust:
|
||||
return rust.GetLanguage(), nil
|
||||
default:
|
||||
return nil, errors.New(errors.ErrInvalidLanguage, fmt.Sprintf("language %s is not supported", lang)).
|
||||
WithContext("language", string(lang)).
|
||||
WithRemediation("Supported languages: Go, TypeScript, JavaScript, Python, C, C++, HTML, Vue, Elixir")
|
||||
WithRemediation("Supported languages: Go, TypeScript, JavaScript, Python, C, C++, HTML, Vue, Elixir, Rust")
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -27,6 +27,8 @@ func ExtractSymbols(tree *sitter.Tree, content []byte, lang protocol.Language, f
|
||||
return extractCSymbols(root, content, filename)
|
||||
case protocol.LangElixir:
|
||||
return extractElixirSymbols(root, content, filename)
|
||||
case protocol.LangRust:
|
||||
return extractRustSymbols(root, content, filename)
|
||||
default:
|
||||
return nil
|
||||
}
|
||||
@@ -714,6 +716,133 @@ func extractElixirProtocol(n *sitter.Node, content []byte, filename string) *pro
|
||||
}
|
||||
}
|
||||
|
||||
// extractRustSymbols extracts symbols from Rust code.
|
||||
func extractRustSymbols(root *sitter.Node, content []byte, filename string) []protocol.Symbol {
|
||||
var symbols []protocol.Symbol
|
||||
|
||||
WalkTree(root, func(n *sitter.Node) bool {
|
||||
var symbol *protocol.Symbol
|
||||
|
||||
switch n.Type() {
|
||||
case "function_item":
|
||||
nameNode := n.ChildByFieldName("name")
|
||||
if nameNode != nil {
|
||||
symbol = &protocol.Symbol{
|
||||
Name: GetNodeText(nameNode, content),
|
||||
Kind: protocol.SymbolFunction,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
case "struct_item":
|
||||
nameNode := n.ChildByFieldName("name")
|
||||
if nameNode != nil {
|
||||
symbol = &protocol.Symbol{
|
||||
Name: GetNodeText(nameNode, content),
|
||||
Kind: protocol.SymbolStruct,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
case "enum_item":
|
||||
nameNode := n.ChildByFieldName("name")
|
||||
if nameNode != nil {
|
||||
symbol = &protocol.Symbol{
|
||||
Name: GetNodeText(nameNode, content),
|
||||
Kind: protocol.SymbolEnum,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
case "trait_item":
|
||||
nameNode := n.ChildByFieldName("name")
|
||||
if nameNode != nil {
|
||||
symbol = &protocol.Symbol{
|
||||
Name: GetNodeText(nameNode, content),
|
||||
Kind: protocol.SymbolTrait,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
case "impl_item":
|
||||
symbol = extractRustImpl(n, content, filename)
|
||||
case "type_item":
|
||||
nameNode := n.ChildByFieldName("name")
|
||||
if nameNode != nil {
|
||||
symbol = &protocol.Symbol{
|
||||
Name: GetNodeText(nameNode, content),
|
||||
Kind: protocol.SymbolType,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
case "const_item":
|
||||
nameNode := n.ChildByFieldName("name")
|
||||
if nameNode != nil {
|
||||
symbol = &protocol.Symbol{
|
||||
Name: GetNodeText(nameNode, content),
|
||||
Kind: protocol.SymbolConstant,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
case "static_item":
|
||||
nameNode := n.ChildByFieldName("name")
|
||||
if nameNode != nil {
|
||||
symbol = &protocol.Symbol{
|
||||
Name: GetNodeText(nameNode, content),
|
||||
Kind: protocol.SymbolVariable,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
case "macro_definition":
|
||||
nameNode := n.ChildByFieldName("name")
|
||||
if nameNode != nil {
|
||||
symbol = &protocol.Symbol{
|
||||
Name: GetNodeText(nameNode, content) + " (macro)",
|
||||
Kind: protocol.SymbolFunction,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
case "mod_item":
|
||||
nameNode := n.ChildByFieldName("name")
|
||||
if nameNode != nil {
|
||||
symbol = &protocol.Symbol{
|
||||
Name: GetNodeText(nameNode, content),
|
||||
Kind: protocol.SymbolModule,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if symbol != nil {
|
||||
if doc := ExtractDocComment(n, content, protocol.LangRust); doc != nil {
|
||||
symbol.Doc = FormatDocComment(doc)
|
||||
}
|
||||
symbols = append(symbols, *symbol)
|
||||
}
|
||||
|
||||
return true
|
||||
})
|
||||
|
||||
return symbols
|
||||
}
|
||||
|
||||
// extractRustImpl extracts an impl block symbol from Rust code.
|
||||
func extractRustImpl(n *sitter.Node, content []byte, filename string) *protocol.Symbol {
|
||||
typeNode := n.ChildByFieldName("type")
|
||||
traitNode := n.ChildByFieldName("trait")
|
||||
|
||||
var name string
|
||||
if traitNode != nil && typeNode != nil {
|
||||
name = "impl " + GetNodeText(traitNode, content) + " for " + GetNodeText(typeNode, content)
|
||||
} else if typeNode != nil {
|
||||
name = "impl " + GetNodeText(typeNode, content)
|
||||
} else {
|
||||
return nil
|
||||
}
|
||||
|
||||
return &protocol.Symbol{
|
||||
Name: name,
|
||||
Kind: protocol.SymbolType,
|
||||
Location: NodeLocation(n, filename),
|
||||
}
|
||||
}
|
||||
|
||||
// extractElixirImpl extracts a protocol implementation.
|
||||
func extractElixirImpl(n *sitter.Node, content []byte, filename string) *protocol.Symbol {
|
||||
// defimpl Protocol, for: Type do ... end
|
||||
|
||||
Reference in New Issue
Block a user