• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang content.SourceLocation类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中github.com/quarnster/completion/content.SourceLocation的典型用法代码示例。如果您正苦于以下问题:Golang SourceLocation类的具体用法?Golang SourceLocation怎么用?Golang SourceLocation使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了SourceLocation类的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: GetDefinition

func (c *Clang) GetDefinition(a *content.GetDefinitionArgs, ret *content.SourceLocation) error {
	fn, args, err := c.prepare(&a.CompleteAtArgs)
	if err != nil {
		return err
	}
	args = append([]string{"-fsyntax-only", "-Xclang", "-ast-dump", "-Xclang", "-ast-dump-filter", "-Xclang", a.Identifier}, args...)
	args = append(args, fn)
	out, oute, err := RunClang(a.Location.File.Contents, args...)
	if len(out) == 0 {
		if err != nil {
			return err
		} else {
			return fmt.Errorf("%s", oute)
		}
	}
	re, err := regexp.Compile(`\w+Decl[^<]+<(..[^:,]+):?(\d+)?:?(\d+)?.*?\s` + a.Identifier + `\s`)
	if err != nil {
		return err
	}
	res := re.FindAllStringSubmatch(string(out), -1)
	if len(res) == 0 {
		return fmt.Errorf("Not found")
	}
	ret.File.Name = res[0][1]
	i, _ := strconv.ParseInt(res[0][2], 10, 32)
	ret.Line = uint(i)
	i, _ = strconv.ParseInt(res[0][3], 10, 32)
	ret.Column = uint(i)
	return nil
}
开发者ID:noname007,项目名称:completion,代码行数:30,代码来源:clang.go


示例2: 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
}
开发者ID:noname007,项目名称:completion,代码行数:29,代码来源:scopes_manual.go


示例3: TestVisibility

func TestVisibility(t *testing.T) {
	if d, err := ioutil.ReadFile("../../net/testdata/CompleteSharp.cs"); err != nil {
		t.Error(err)
	} else {
		var p SCOPES
		if !p.Parse(string(d)) {
			t.Fatalf("Failed to parse: %s\n%v", p.Error(), p.RootNode())
		}
		tests := []struct {
			line uint
			res  []text.Region
		}{
			{32, []text.Region{{872, 1090}, {1096, 1158}, {34796, 34846}, {35017, 35067}, {37046, 37049}}},
			{116, []text.Region{{872, 1090}, {1096, 1248}, {1337, 1414}, {2803, 2897}, {3812, 3990}, {3991, 4012}, {4108, 4321}, {4533, 4565}, {4565, 4639}, {4988, 5114}, {6210, 6293}, {6672, 6740}, {6927, 7035}, {8232, 8286}, {8500, 8568}, {10533, 10641}, {11209, 11307}, {12510, 12570}, {12645, 12709}, {13010, 13091}, {32050, 32228}, {32343, 32392}, {33297, 33371}, {33636, 33718}, {34790, 34846}, {35017, 35067}, {37046, 37049}}},
			{730, []text.Region{{872, 1090}, {1096, 1208}, {32060, 32228}, {32343, 32483}, {32499, 32597}, {32608, 32705}, {32735, 32880}, {33287, 33371}, {33636, 33718}, {34790, 34846}, {35017, 35067}, {37046, 37049}}},
		}
		loc := content.SourceLocation{File: content.File{Contents: string(d)}, Column: 1}
		for i := range tests {
			loc.Line = tests[i].line
			vis := Visibility(loc)
			if !reflect.DeepEqual(vis.Regions(), tests[i].res) {
				t.Errorf("Output differs.\nExpected\n%v, got\n%v", tests[i].res, vis.Regions())
			}
			if testing.Verbose() {
				t.Log(Substr(loc.File.Contents, vis))
			}
		}
	}
}
开发者ID:NeoTse,项目名称:completion,代码行数:29,代码来源:scopes_test.go


示例4: TestClang

func TestClang(t *testing.T) {
	if _, err := RunClang("-v"); err != nil {
		t.Skipf("Couldn't launch clang: %s", err)
	}
	loc := content.SourceLocation{}
	loc.Column = 1
	loc.Line = 10
	loc.File.Name = "testdata/hello.cpp"
	t.Log(CompleteAt([]string{}, loc))
}
开发者ID:berkus,项目名称:completion,代码行数:10,代码来源:clang_test.go



注:本文中的github.com/quarnster/completion/content.SourceLocation类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang content.Type类代码示例发布时间:2022-05-28
下一篇:
Golang content.Method类代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap