本文整理汇总了Golang中github.com/quarnster/completion/content.CompletionResult类的典型用法代码示例。如果您正苦于以下问题:Golang CompletionResult类的具体用法?Golang CompletionResult怎么用?Golang CompletionResult使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了CompletionResult类的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。
示例1: complete_pkg
func (g *Go) complete_pkg(pkg string, cmp *content.CompletionResult) error {
if g.imports == nil {
g.imports = make(map[string]*types.Package)
}
if p, err := types.GcImport(g.imports, pkg); err != nil {
return err
} else {
nn := p.Scope()
for i := 0; i < nn.NumEntries(); i++ {
t := nn.At(i)
var flags content.Flags
if n := t.Name(); n[0] != strings.ToUpper(n)[0] {
flags = content.FLAG_ACC_PROTECTED
} else {
flags = content.FLAG_ACC_PUBLIC
}
switch t.(type) {
case *types.Func:
var m content.Method
m.Flags |= flags
m.Name.Relative = t.Name()
sig := t.Type().Underlying().(*types.Signature)
if sig.Recv() != nil {
continue
}
par := sig.Params()
for j := 0; j < par.Len(); j++ {
m.Parameters = append(m.Parameters, g.pkg_var(par.At(j)))
}
ret := sig.Results()
for j := 0; j < ret.Len(); j++ {
m.Returns = append(m.Returns, g.pkg_var(ret.At(j)))
}
cmp.Methods = append(cmp.Methods, m)
case *types.TypeName:
var t2 content.Type
t2.Flags |= flags
t2.Name.Relative = t.Name()
switch t.Type().Underlying().(type) {
case *types.Interface:
t2.Flags |= content.FLAG_TYPE_INTERFACE
case *types.Struct:
t2.Flags |= content.FLAG_TYPE_STRUCT
}
cmp.Types = append(cmp.Types, t2)
case *types.Const, *types.Var:
var f content.Field
f.Name.Relative = t.Name()
f.Type = g.pkg_type(t.Type())
cmp.Fields = append(cmp.Fields, f)
default:
log4go.Warn("Unimplemented type in package completion: at: %+v, %v, %v", t, reflect.TypeOf(t), reflect.TypeOf(t.Type().Underlying()))
}
}
}
return nil
}
开发者ID:NeoTse,项目名称:completion,代码行数:60,代码来源:complete.go
示例2: Load
func (d *DWARFHelper) Load() (content.CompletionResult, error) {
var cmp content.CompletionResult
r := d.df.Reader()
for {
if e, err := r.Next(); err != nil {
return cmp, err
break
} else if e == nil {
break
} else {
switch e.Tag {
case dwarf.TagMember:
if f, err := d.toContentField(e); err != nil {
return cmp, err
} else {
cmp.Fields = append(cmp.Fields, f)
}
case dwarf.TagSubprogram:
if m, err := d.toContentMethod(e); err != nil {
return cmp, err
} else {
cmp.Methods = append(cmp.Methods, m)
}
case dwarf.TagClassType, dwarf.TagTypedef, dwarf.TagStructType:
if t, err := d.GetType(e.Offset); err != nil {
return cmp, err
} else {
cmp.Types = append(cmp.Types, t)
}
}
}
}
return cmp, nil
}
开发者ID:berkus,项目名称:completion,代码行数:34,代码来源:dwarf.go
示例3: Complete
func (c *Java) Complete(args *content.CompleteArgs, cmp *content.CompletionResult) error {
log4go.Fine("%+v", args)
var archive Archive
session := args.Session()
if session != nil {
if a, ok := session.Get("java_archive").(Archive); ok {
archive = a
}
}
if archive == nil {
cp, err := DefaultClasspath()
if err != nil {
// We don't really care about not being able to get the default classpath as it could be provided manually by the user
log4go.Warn("Couldn't get the default classpath: %s", err)
}
settings := args.Settings()
if cp2, ok := settings.Get("java_classpath").([]string); ok {
// TODO: do we ever want to override rather than append to the classpath?
cp = append(cp, cp2...)
}
log4go.Fine("classpath: %+v", cp)
if archive, err = NewCompositeArchive(cp); err != nil {
return err
} else if session != nil {
session.Set("java_archive", archive)
}
}
className, err := fqnToClassname(args.Location)
if err != nil {
return err
}
data, err := archive.LoadClass(className)
if err != nil {
return err
}
class, err := NewClass(bytes.NewReader(data))
if err != nil {
return err
}
ct, err := class.ToContentType()
if err != nil {
return err
}
// TODO(q): Inherited fields and methods?
// I see value in being able to "just" get the smaller set,
// but getting the full set should definitely be possible "server side"
cmp.Fields = ct.Fields
cmp.Types = ct.Types
cmp.Methods = ct.Methods
return nil
}
开发者ID:NeoTse,项目名称:completion,代码行数:57,代码来源:java.go
示例4: Complete
func (d *DWARFHelper) Complete(id content.FullyQualifiedName) (content.CompletionResult, error) {
var cmp content.CompletionResult
r := d.df.Reader()
for {
e, err := r.Next()
if err != nil {
return cmp, err
} else if e == nil {
break
}
switch e.Tag {
case dwarf.TagCompileUnit:
continue
case dwarf.TagClassType, dwarf.TagTypedef, dwarf.TagStructType:
t, err := d.GetType(e.Offset)
if err != nil {
return cmp, err
}
if t.Name != id || !e.Children {
r.SkipChildren()
continue
}
r2 := d.df.Reader()
r2.Seek(e.Offset)
for {
e, err := r.Next()
if err != nil {
return cmp, err
} else if e == nil || e.Tag == 0 {
break
}
switch e.Tag {
case dwarf.TagMember:
if f, err := d.toContentField(e); err != nil {
return cmp, err
} else {
f.Name.Absolute = fmt.Sprintf("dwarf://field/%s;%d", d.id, e.Offset)
cmp.Fields = append(cmp.Fields, f)
}
case dwarf.TagSubprogram:
if m, err := d.toContentMethod(e); err != nil {
return cmp, err
} else {
m.Name.Absolute = fmt.Sprintf("dwarf://method/%s;%d", d.id, e.Offset)
cmp.Methods = append(cmp.Methods, m)
}
r.SkipChildren()
}
}
return cmp, nil
default:
r.SkipChildren()
}
}
return cmp, errors.New(fmt.Sprintf("Unable to find type: %s", id))
}
开发者ID:NeoTse,项目名称:completion,代码行数:56,代码来源:dwarf.go
示例5: complete
func (c *Net) complete(cache *Cache, t *content.Type, cmp *content.CompletionResult) error {
if ct, err := cache.Complete(t); err != nil {
return err
} else {
cmp.Fields = ct.Fields
cmp.Types = ct.Types
cmp.Methods = ct.Methods
}
return nil
}
开发者ID:jerchung,项目名称:completion,代码行数:10,代码来源:net.go
示例6: TestNet
func TestNet(t *testing.T) {
paths := DefaultPaths()
if len(paths) == 0 {
t.Skip("Neither mono nor Windows .NET Framework paths were possible to get")
}
var (
n Net
args content.CompleteAtArgs
cmp content.CompletionResult
)
tests := []struct {
InFile string
Line, Column uint
}{
// TODO: this test is not platform independent as it depends on whatever framework you happen
// to have installed
{"./testdata/CompleteSharp.cs", 40, 27},
{"./testdata/CompleteSharp.cs", 40, 41},
{"./testdata/CompleteSharp.cs", 47, 47},
//{"./testdata/CompleteSharp.cs", 28, 14},
{"./testdata/CompleteSharp.cs", 211, 46},
{"./testdata/CompleteSharp.cs", 761, 83},
{"./testdata/CompleteSharp.cs", 761, 27},
{"./testdata/CompleteSharp.cs", 857, 29},
{"./testdata/CompleteSharp.cs", 737, 15},
{"./testdata/CompleteSharp.cs", 95, 38},
{"./testdata/CompleteSharp.cs", 95, 45},
{"./testdata/CompleteSharp.cs", 776, 39},
{"./testdata/NamespaceTest.cs", 4, 15},
{"./testdata/NamespaceTest.cs", 6, 15},
}
args.SessionId = "a"
args.Settings().Set("net_paths", []string{"./testdata/"})
args.Settings().Set("net_assemblies", []string{"CompleteSharp.exe"})
for _, test := range tests {
args.Location.File.Name = test.InFile
args.Location.Line = test.Line
args.Location.Column = test.Column
ex := fmt.Sprintf("%s-%d-%d.cmp", test.InFile, test.Line, test.Column)
if err := n.CompleteAt(&args, &cmp); err != nil {
t.Errorf("Unable to complete %v: %s", test, err)
} else if exp, err := ioutil.ReadFile(ex); err != nil {
t.Logf("Couldn't read the expected output file %s (%s); it'll be created", ex, err)
if err := ioutil.WriteFile(ex, []byte(cmp.String()), 0644); err != nil {
t.Error(err)
}
} else if d := util.Diff(string(exp), cmp.String()); len(d) != 0 {
t.Error(d)
}
}
}
开发者ID:noname007,项目名称:completion,代码行数:53,代码来源:net_test.go
示例7: complete
func (g *Go) complete(t reflect.Type, cmp *content.CompletionResult) error {
if k := t.Kind(); k != reflect.Ptr {
return fmt.Errorf("Expected a pointer to a type not %v", k)
}
for i := 0; i < t.NumMethod(); i++ {
m := t.Method(i)
cmp.Methods = append(cmp.Methods, g.method(m))
}
t = t.Elem()
for i := 0; i < t.NumMethod(); i++ {
m := t.Method(i)
cmp.Methods = append(cmp.Methods, g.method(m))
}
for i := 0; i < t.NumField(); i++ {
f := t.Field(i)
cmp.Fields = append(cmp.Fields, g.field(f))
}
return nil
}
开发者ID:NeoTse,项目名称:completion,代码行数:22,代码来源:complete.go
示例8: CompleteAt
func (c *Clang) CompleteAt(a *content.CompleteAtArgs, ret *content.CompletionResult) error {
fn, args, err := c.prepare(a)
if err != nil {
return err
}
args = append([]string{"-fsyntax-only", "-Xclang", fmt.Sprintf("-code-completion-at=%s:%d:%d", fn, a.Location.Line, a.Location.Column)}, args...)
args = append(args, fn)
if out, oute, err := RunClang(a.Location.File.Contents, args...); len(out) == 0 {
if err != nil {
return err
} else {
return fmt.Errorf("%s", oute)
}
} else if r, err := parseresult(string(out)); err != nil {
return err
} else {
*ret = r
ret.Messages = string(oute)
return nil
}
}
开发者ID:noname007,项目名称:completion,代码行数:22,代码来源:clang.go
示例9: CompleteAt
func (t *Clang) CompleteAt(args *content.CompleteAtArgs, res *content.CompletionResult) error {
origargs, _ := args.Settings().Get("compiler_flags").([]string)
var unsaved map[string]string
if args.Location.File.Contents != "" {
unsaved = map[string]string{args.Location.File.Name: args.Location.File.Contents}
}
if tu := t.GetTranslationUnit(args.Location.File.Name, origargs, "", unsaved); tu == nil {
return nil
}
cres := tu.CompleteAt(args.Location.File.Name, int(args.Location.Line), int(args.Location.Column), unsaved, 0)
if !cres.IsValid() {
return fmt.Errorf("CompleteResults is not valid")
}
defer cres.Dispose()
for _, r := range cres.Results() {
var (
buf bytes.Buffer
)
switch r.CursorKind {
case clang.CK_StructDecl, clang.CK_TypedefDecl:
for _, c := range r.CompletionString.Chunks() {
buf.WriteString(c.Text())
}
var tt content.Type
tt.Flags = content.FLAG_TYPE_CLASS
tt.Name.Absolute = buf.String()
res.Types = append(res.Types, tt)
case clang.CK_FunctionDecl:
var (
m content.Method
paramstarted bool
argCount int
)
for _, c := range r.CompletionString.Chunks() {
switch k := c.Kind(); k {
case clang.CompletionChunk_ResultType:
var v content.Variable
v.Name.Relative = c.Text()
m.Returns = append(m.Returns, v)
case clang.CompletionChunk_Placeholder:
var v content.Variable
v.Type.Name.Relative = c.Text()
v.Name.Relative = fmt.Sprintf("arg%d", argCount)
argCount++
m.Parameters = append(m.Parameters, v)
case clang.CompletionChunk_LeftParen:
paramstarted = true
case clang.CompletionChunk_RightParen, clang.CompletionChunk_Comma:
case clang.CompletionChunk_TypedText:
if !paramstarted {
buf.WriteString(c.Text())
}
default:
log4go.Warn("Unimplemented CompletionChunkKind: %s", k)
}
}
m.Name.Relative = buf.String()
res.Methods = append(res.Methods, m)
default:
log4go.Warn("Unimplemented CursorKind: %s", r.CursorKind)
}
}
return nil
}
开发者ID:NeoTse,项目名称:completion,代码行数:65,代码来源:complete.go
注:本文中的github.com/quarnster/completion/content.CompletionResult类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论