core

package
v0.7.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 28, 2025 License: MIT Imports: 37 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var DocstringQueries = map[string]string{
	"python": `
		(module . (expression_statement (string) @docstring))
		(class_definition body: (block . (expression_statement (string) @docstring)))
		(function_definition body: (block . (expression_statement (string) @docstring)))
	`,
	"javascript": `
		(comment) @jsdoc
		(#match? @jsdoc "^/\\*\\*")
	`,
	"typescript": `
		(comment) @jsdoc
		(#match? @jsdoc "^/\\*\\*")
	`,
	"tsx": `
		(comment) @jsdoc
		(#match? @jsdoc "^/\\*\\*")
	`,
	"java": `
		(comment) @javadoc
		(#match? @javadoc "^/\\*\\*")
	`,
}

DocstringQueries maps language names to their tree-sitter docstring query patterns.

View Source
var ExtensionToLanguage = map[string]string{

	"py": "python",

	"js": "javascript", "jsx": "javascript",
	"ts": "typescript", "tsx": "tsx",

	"go": "golang",

	"java": "java", "kt": "kotlin", "scala": "scala",

	"c": "c", "h": "c",
	"cpp": "cpp", "cc": "cpp", "cxx": "cpp", "hpp": "cpp",

	"rs": "rust",

	"rb": "ruby",

	"sh": "bash", "bash": "bash",

	"cs": "csharp",

	"swift": "swift",

	"ex": "elixir", "exs": "elixir",

	"lua": "lua",

	"php": "php",

	"ml": "ocaml", "mli": "ocaml",

	"sql": "sql",

	"html": "html", "htm": "html",
	"css": "css",

	"yaml": "yaml", "yml": "yaml",
	"toml": "toml",
	"hcl":  "hcl", "tf": "hcl",

	"dockerfile": "dockerfile",
	"proto":      "protobuf",
	"svelte":     "svelte",
	"elm":        "elm",
	"groovy":     "groovy",
	"cue":        "cue",
}

ExtensionToLanguage maps file extensions to tree-sitter language names.

View Source
var QueryTemplates = map[string]string{
	"python":     "(comment) @comment",
	"javascript": "(comment) @comment",
	"typescript": "(comment) @comment",
	"tsx":        "(comment) @comment",
	"golang":     "(comment) @comment",
	"rust": `
		(line_comment) @comment
		(block_comment) @comment
	`,
	"swift": "(comment) @comment",
	"kotlin": `
		(line_comment) @comment
		(multiline_comment) @comment
	`,
	"java": `
		(line_comment) @comment
		(block_comment) @comment
	`,
	"elixir":   "(comment) @comment",
	"c":        "(comment) @comment",
	"cpp":      "(comment) @comment",
	"csharp":   "(comment) @comment",
	"ruby":     "(comment) @comment",
	"php":      "(comment) @comment",
	"bash":     "(comment) @comment",
	"lua":      "(comment) @comment",
	"ocaml":    "(comment) @comment",
	"sql":      "(comment) @comment",
	"html":     "(comment) @comment",
	"css":      "(comment) @comment",
	"yaml":     "(comment) @comment",
	"toml":     "(comment) @comment",
	"hcl":      "(comment) @comment",
	"svelte":   "(comment) @comment",
	"elm":      "(comment) @comment",
	"groovy":   "(comment) @comment",
	"cue":      "(comment) @comment",
	"scala":    "(comment) @comment",
	"protobuf": "(comment) @comment",
}

QueryTemplates maps language names to their tree-sitter comment query patterns.

Functions

func GetLanguage

func GetLanguage(name string) *sitter.Language

GetLanguage returns the tree-sitter Language for the given language name.

Types

type CommentDetector

type CommentDetector struct {
	// contains filtered or unexported fields
}

CommentDetector detects comments in source code using tree-sitter.

func NewCommentDetector

func NewCommentDetector() *CommentDetector

NewCommentDetector creates a new CommentDetector instance.

func (*CommentDetector) Detect

func (d *CommentDetector) Detect(content, filePath string, includeDocstrings bool) []models.CommentInfo

Detect extracts comments from the given source code.

type LanguageRegistry

type LanguageRegistry struct {
	// contains filtered or unexported fields
}

LanguageRegistry provides thread-safe access to tree-sitter parsers.

func NewLanguageRegistry

func NewLanguageRegistry() *LanguageRegistry

NewLanguageRegistry creates a new LanguageRegistry instance.

func (*LanguageRegistry) GetLanguageName

func (r *LanguageRegistry) GetLanguageName(extension string) string

GetLanguageName returns the tree-sitter language name for a file extension.

func (*LanguageRegistry) GetParser

func (r *LanguageRegistry) GetParser(extension string) *sitter.Parser

GetParser returns a parser for the given extension. Parsers are cached for reuse.

func (*LanguageRegistry) IsSupported

func (r *LanguageRegistry) IsSupported(extension string) bool

IsSupported returns true if the extension is supported.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL