本文整理汇总了Golang中github.com/quarnster/completion/content.SourceLocation.Offset方法的典型用法代码示例。如果您正苦于以下问题:Golang SourceLocation.Offset方法的具体用法?Golang SourceLocation.Offset怎么用?Golang SourceLocation.Offset使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类github.com/quarnster/completion/content.SourceLocation
的用法示例。
在下文中一共展示了SourceLocation.Offset方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: Visibility
// Returns the RegionSet visible from the given source code location.
// Note that it only uses '{' and '}' to deduce scopes, and further
// processing is likely needed depending on language specifics.
func Visibility(loc content.SourceLocation) (ret text.RegionSet) {
var s SCOPES
s.Parse(loc.File.Contents)
var rec func(node *parser.Node)
pos := int(loc.Offset())
rec = func(node *parser.Node) {
for _, child := range node.Children {
if !child.Range.Contains(pos) || child.Name == "TextScope" || child.Name == "CommentScope" {
r := child.Range
if child.Name == "BracketScope" || child.Name == "TextScope" {
// We want the brackets (or "'s) as part of the result to make the resulting
// source code parseable.
r.A += 1
r.B -= 1
}
ret = ret.Cut(r)
} else {
rec(child)
}
}
}
root := s.RootNode()
ret.Add(root.Range)
rec(root)
return
}