Documentation
¶
Index ¶
- type Comment
- type Language
- func C() *Language
- func CSS() *Language
- func Cpp() *Language
- func Elixir() *Language
- func GetLanguageFromExt(ext string) (*Language, error)
- func Go() *Language
- func Haskell() *Language
- func Java() *Language
- func JavaScript() *Language
- func Julia() *Language
- func Lua() *Language
- func PHP() *Language
- func Protobuf() *Language
- func Python() *Language
- func QML() *Language
- func R() *Language
- func Ruby() *Language
- func Rust() *Language
- func Tsx() *Language
- func TypeScript() *Language
- func YAML() *Language
- type QueryEngine
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Comment ¶
type Comment struct {
Text string
Source string
Line int
Offset int
Scope string
// Strip records, for each line of Text, how many bytes were taken off the
// front of the matching Source line. An alert's column is meaningful in
// Text; putting it back in Source means adding this.
//
// Empty for a comment that was never dedented, in which case the caller
// falls back to measuring the source line itself.
//
// Not serialised: this is bookkeeping for putting an alert back where it
// came from, not part of what a comment is.
Strip []int `json:"-"`
}
Comment represents an in-code comment (line or block).
func GetComments ¶
GetComments returns all comments in the given source code.
type Language ¶
type Language struct {
Delims *regexp.Regexp
Parser *sitter.Language
// Prefix matches a block comment's per-line decoration -- the ` *` that
// starts each line of a JSDoc or Javadoc block.
//
// This is not the same thing as Cutset. Decoration is noise of a known
// width that has to come off for the body to be valid markup; indentation
// is meaningful and only its common part comes off. Conflating them is why
// a cutset of " *" cannot work: `*` is both the decoration and Markdown's
// list and emphasis marker, so a cutset wide enough to remove the noise
// also eats a list.
//
// The match is blanked rather than deleted, which keeps every column where
// it was and leaves the dedent below to remove the whitespace it becomes.
Prefix *regexp.Regexp
Queries []core.Scope
Cutset string
Padding padding
}
Language represents a supported programming language.
NOTE: What about haskell, less, perl, php, powershell, r, sass, swift?
func Elixir ¶
func Elixir() *Language
Elixir extracts `#` comments and the prose held by the `@moduledoc`, `@doc`, `@typedoc` and `@shortdoc` attributes.
The attributes are the point. Elixir has no documentation comment syntax: its API documentation lives in module attributes holding a string or a heredoc, and that is what `mix docs` publishes and what a reader of the module reads first. A comment-only pass sees the asides and none of the documentation.
They are given a `doc` meta scope -- `text.comment.doc.line` and `text.comment.doc.block` -- so that published documentation can be held to a different standard than an implementation note, or excluded on its own.
The queries capture `quoted_content`, the body of the string, rather than the string itself. That leaves the delimiters out of the extracted text without a `Delims` pattern having to take them off, which matters for the single-quoted form: stripping its `"` with a regex would also strip any quote written inside the prose. `@doc false` and `@doc since: "1.0"` carry no prose, and neither matches a query that requires a string or sigil.
func GetLanguageFromExt ¶
GetLanguageFromExt returns a Language based on the given file extension.
func Haskell ¶
func Haskell() *Language
Haskell is parsed with the Elm grammar: the two languages share their comment syntax (`--`, `{- -}`), and comments are extras that survive error recovery, which is all comment extraction needs.
func JavaScript ¶
func JavaScript() *Language
func QML ¶
func QML() *Language
QML is parsed with the JavaScript grammar: QML's object syntax isn't valid JavaScript, but comments are extras and survive error recovery, which is all comment extraction needs.
func R ¶
func R() *Language
R (and Perl, which shares the normed extension) is parsed with the Bash grammar: all three languages use `#` line comments, and comments are extras that survive error recovery, which is all comment extraction needs.
func TypeScript ¶
func TypeScript() *Language
type QueryEngine ¶
type QueryEngine struct {
// contains filtered or unexported fields
}
func NewQueryEngine ¶
func NewQueryEngine(tree *sitter.Tree, lang *Language) *QueryEngine