Documentation ¶
Index ¶
- Constants
- Variables
- func ChildNodeAtPoint(pt sitter.Point, node *sitter.Node) (*sitter.Node, bool)
- func ExtractIdentifiers(doc DocumentContent, nodes []*sitter.Node, limit *sitter.Point) []string
- func FindChildNode(node *sitter.Node, compare func(*sitter.Node) int) *sitter.Node
- func Functions(doc DocumentContent, node *sitter.Node) map[string]Signature
- func HasAncestor(node *sitter.Node, compfn func(*sitter.Node) bool) bool
- func IsModuleScope(doc DocumentContent, node *sitter.Node) bool
- func LeafNodes(node *sitter.Node) []*sitter.Node
- func LoadStatements(input []byte, tree *sitter.Tree) []*sitter.Node
- func MustQuery(pattern []byte, lang *sitter.Language) *sitter.Query
- func NamedNodeAtPoint(doc DocumentContent, pt sitter.Point) (*sitter.Node, bool)
- func NamedNodeAtPosition(doc DocumentContent, pos protocol.Position) (*sitter.Node, bool)
- func NodeAtPoint(doc DocumentContent, pt sitter.Point) (*sitter.Node, bool)
- func NodeAtPosition(doc DocumentContent, pos protocol.Position) (*sitter.Node, bool)
- func NodeBefore(a, b *sitter.Node) bool
- func NodeLocation(node *sitter.Node, docURI uri.URI) protocol.Location
- func NodeRange(node *sitter.Node) protocol.Range
- func NodesRange(nodes []*sitter.Node) protocol.Range
- func Parse(ctx context.Context, input []byte) (*sitter.Tree, error)
- func PointAfter(a, b sitter.Point) bool
- func PointAfterOrEqual(a, b sitter.Point) bool
- func PointBefore(a, b sitter.Point) bool
- func PointBeforeOrEqual(a, b sitter.Point) bool
- func PointCmp(a, b sitter.Point) int
- func PointCovered(a sitter.Point, b *sitter.Node) bool
- func PointInside(a sitter.Point, b sitter.Range) bool
- func PositionToPoint(pos protocol.Position) sitter.Point
- func Query(node *sitter.Node, pattern string, matchFn MatchFunc)
- func RangeContainsPoint(r sitter.Range, p sitter.Point) bool
- func SitterRange(r protocol.Range) sitter.Range
- func SymbolsBefore(symbols []protocol.DocumentSymbol, before *sitter.Node) []protocol.DocumentSymbol
- func Unquote(input []byte, n *sitter.Node) string
- type DocumentContent
- type MatchFunc
- type Parameter
- type Signature
- type Symbol
- type Type
Constants ¶
const ( NodeTypeModule = "module" NodeTypeCall = "call" NodeTypeArgList = "argument_list" NodeTypeFunctionDef = "function_definition" NodeTypeParameters = "parameters" NodeTypeKeywordArgument = "keyword_argument" NodeTypeIdentifier = "identifier" NodeTypeIfStatement = "if_statement" NodeTypeExpressionStatement = "expression_statement" NodeTypeForStatement = "for_statement" NodeTypeAssignment = "assignment" NodeTypeAttribute = "attribute" NodeTypeString = "string" NodeTypeDictionary = "dictionary" NodeTypeList = "list" NodeTypeComment = "comment" NodeTypeBlock = "block" NodeTypeERROR = "ERROR" FieldName = "name" FieldParameters = "parameters" FieldReturnType = "return_type" FieldBody = "body" )
const FunctionParameters = `` /* 151-byte string literal not displayed */
FunctionParameters extracts parameters from a function definition and supports a mixture of positional parameters, default value parameters, typed parameters*, and typed default value parameters*.
- These are not valid Starlark, but we support them to enable using Python type-stub files for improved editor experience.
const Identifiers = `
[(module) @module
(identifier) @id
"." @dot
(ERROR "." @trailing-dot
.)
]
`
Extract all identifiers from the subtree. Include an extra empty identifier "" if there is an error node with a trailing period.
Variables ¶
var LanguagePython = python.GetLanguage()
Functions ¶
func ChildNodeAtPoint ¶
func ExtractIdentifiers ¶
func FindChildNode ¶
Find the deepest child node for which `compare` returns 0. Compare should return: - `-1` if the node is located before the range of interest - `0` if the node covers the range of interest - `1` if the node is located after the range of interest
func Functions ¶
func Functions(doc DocumentContent, node *sitter.Node) map[string]Signature
Functions finds all function definitions that are direct children of the provided sitter.Node.
func IsModuleScope ¶
func IsModuleScope(doc DocumentContent, node *sitter.Node) bool
A node is in the scope of the top level module if there are no function definitions in the ancestry of the node.
func NamedNodeAtPoint ¶
func NamedNodeAtPosition ¶
NamedNodeAtPosition returns the most granular named descendant at a position.
func NodeAtPoint ¶
func NodeAtPosition ¶
NodeAtPosition returns the node (named or unnamed) with the smallest start/end range that covers the given position.
func NodeBefore ¶
func PointAfter ¶
func PointAfterOrEqual ¶
func PointBefore ¶
func PointBeforeOrEqual ¶
func PositionToPoint ¶
PositionToPoint converts an LSP protocol file location to a Tree-sitter file location.
func Query ¶
Query executes a Tree-sitter S-expression query against a subtree and invokes matchFn on each result.
func SymbolsBefore ¶
func SymbolsBefore(symbols []protocol.DocumentSymbol, before *sitter.Node) []protocol.DocumentSymbol
Returns only the symbols that occur before the node given if any, otherwise return all symbols.
func Unquote ¶
Unquote a Tree sitter string node into its string contents.
Also accepts a parent module, block or expression statement containing a string node for convenience. If a non-string node is passed, Unquote will panic().
Tree sitter parses a string literal into 2 or more child nodes representing the beginning/ending delimiters, and any number of escape sequences inside. Thus, the string
"""hello\nTilted\nWorld"""
gets parsed into a tree like:
module [0, 0] - [1, 0] expression_statement [0, 0] - [0, 26] string [0, 0] - [0, 26] " [0, 0] - [0, 3] escape_sequence [0, 8] - [0, 10] escape_sequence [0, 16] - [0, 18] " [0, 23] - [0, 26]
Notably, there are no nodes to represent the contents in between the string delimiters and any escape sequences, so we have to extract those manually based on the start/end byte boundaries of the adjacent delimiter or escape sequence nodes.
Types ¶
type DocumentContent ¶
type Parameter ¶
type Parameter struct { Name string TypeHint string DefaultValue string Content string DocURI uri.URI Location protocol.Location }
func (Parameter) ParameterInfo ¶
func (p Parameter) ParameterInfo(fnDocs docstring.Parsed) protocol.ParameterInformation
type Signature ¶
type Signature struct { Name string Params []Parameter ReturnType string Docs docstring.Parsed Range protocol.Range // contains filtered or unexported fields }
func ExtractSignature ¶
func ExtractSignature(doc DocumentContent, n *sitter.Node) Signature
func Function ¶
Function finds a function definition for the given function name that is a direct child of the provided sitter.Node.
func (Signature) Label ¶
Label produces a human-readable Label for a function signature.
It's modeled to behave similarly to VSCode Python signature labels.
func (Signature) SignatureInfo ¶
func (s Signature) SignatureInfo() protocol.SignatureInformation
type Symbol ¶
type Symbol struct { Name string Detail string Kind protocol.SymbolKind Tags []protocol.SymbolTag Location protocol.Location SelectionRange protocol.Range Children []Symbol }
func DocumentSymbols ¶
func DocumentSymbols(doc DocumentContent) []Symbol
DocumentSymbols returns all symbols with document-wide visibility.
func ExtractVariableAssignment ¶
func ExtractVariableAssignment(doc DocumentContent, n *sitter.Node) Symbol
func SiblingSymbols ¶
func SiblingSymbols(doc DocumentContent, node, before *sitter.Node) []Symbol
Get all symbols defined at the same level as the given node. If before != nil, only include symbols that appear before that node.
func SymbolsInScope ¶
func SymbolsInScope(doc DocumentContent, node *sitter.Node) []Symbol
Get all symbols defined in scopes at or above the level of the given node, excluding symbols from the top-level module (document symbols).
func (Symbol) HasLocation ¶
builtins (e.g., `False`, `k8s_resource`) have no location