本文整理匯總了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
}