mirror of
https://github.com/lukaszraczylo/filepuff-mcp.git
synced 2026-06-05 22:23:50 +00:00
104 lines
2.6 KiB
Go
104 lines
2.6 KiB
Go
// Package protocol defines shared types used across the MCP file operations server.
|
|
package protocol
|
|
|
|
import "path/filepath"
|
|
|
|
// Location represents a position in a file.
|
|
type Location struct {
|
|
File string `json:"file"`
|
|
Line int `json:"line"`
|
|
Column int `json:"column"`
|
|
}
|
|
|
|
// Range represents a range in a file.
|
|
type Range struct {
|
|
Start Location `json:"start"`
|
|
End Location `json:"end"`
|
|
}
|
|
|
|
// SymbolKind represents the kind of a symbol.
|
|
type SymbolKind string
|
|
|
|
const (
|
|
SymbolFunction SymbolKind = "function"
|
|
SymbolMethod SymbolKind = "method"
|
|
SymbolClass SymbolKind = "class"
|
|
SymbolStruct SymbolKind = "struct"
|
|
SymbolInterface SymbolKind = "interface"
|
|
SymbolVariable SymbolKind = "variable"
|
|
SymbolConstant SymbolKind = "constant"
|
|
SymbolType SymbolKind = "type"
|
|
SymbolField SymbolKind = "field"
|
|
SymbolProperty SymbolKind = "property"
|
|
SymbolModule SymbolKind = "module"
|
|
SymbolPackage SymbolKind = "package"
|
|
SymbolEnum SymbolKind = "enum"
|
|
SymbolTrait SymbolKind = "trait"
|
|
)
|
|
|
|
// Symbol represents a code symbol (function, class, variable, etc.).
|
|
type Symbol struct {
|
|
Name string `json:"name"`
|
|
Kind SymbolKind `json:"kind"`
|
|
Doc string `json:"doc,omitempty"`
|
|
Location Location `json:"location"`
|
|
}
|
|
|
|
// SyntaxError represents a syntax error in a file.
|
|
type SyntaxError struct {
|
|
Message string `json:"message"`
|
|
Location Location `json:"location"`
|
|
}
|
|
|
|
// Language represents a programming language.
|
|
type Language string
|
|
|
|
const (
|
|
LangGo Language = "go"
|
|
LangTypeScript Language = "typescript"
|
|
LangJavaScript Language = "javascript"
|
|
LangPython Language = "python"
|
|
LangC Language = "c"
|
|
LangCpp Language = "cpp"
|
|
LangHTML Language = "html"
|
|
LangVue Language = "vue"
|
|
LangJSON Language = "json"
|
|
LangYAML Language = "yaml"
|
|
LangElixir Language = "elixir"
|
|
LangRust Language = "rust"
|
|
LangUnknown Language = "unknown"
|
|
)
|
|
|
|
// DetectLanguage detects the language from a filename.
|
|
func DetectLanguage(filename string) Language {
|
|
ext := filepath.Ext(filename)
|
|
switch ext {
|
|
case ".go":
|
|
return LangGo
|
|
case ".ts", ".tsx":
|
|
return LangTypeScript
|
|
case ".js", ".jsx", ".mjs", ".cjs":
|
|
return LangJavaScript
|
|
case ".py", ".pyw":
|
|
return LangPython
|
|
case ".c", ".h":
|
|
return LangC
|
|
case ".cpp", ".cc", ".cxx", ".hpp", ".hxx":
|
|
return LangCpp
|
|
case ".html", ".htm":
|
|
return LangHTML
|
|
case ".vue":
|
|
return LangVue
|
|
case ".json":
|
|
return LangJSON
|
|
case ".yaml", ".yml":
|
|
return LangYAML
|
|
case ".ex", ".exs":
|
|
return LangElixir
|
|
case ".rs":
|
|
return LangRust
|
|
default:
|
|
return LangUnknown
|
|
}
|
|
}
|