internal/lsp: add additional error handling for builtin packages
Change-Id: I1a084a47d2f171c6b94bde6fece008cddd547833 Reviewed-on: https://go-review.googlesource.com/c/tools/+/175937 Run-TryBot: Rebecca Stambler <rstambler@golang.org> TryBot-Result: Gobot Gobot <gobot@golang.org> Reviewed-by: Ian Cottrell <iancottrell@google.com>
This commit is contained in:
parent
73554e0f78
commit
a1c92a4ac6
|
@ -110,7 +110,15 @@ func (c *completer) formatBuiltin(obj types.Object, score float64) CompletionIte
|
|||
case *types.Const:
|
||||
item.Kind = ConstantCompletionItem
|
||||
case *types.Builtin:
|
||||
fn := c.view.BuiltinPackage().Scope.Lookup(obj.Name())
|
||||
item.Kind = FunctionCompletionItem
|
||||
builtinPkg := c.view.BuiltinPackage()
|
||||
if builtinPkg == nil || builtinPkg.Scope == nil {
|
||||
break
|
||||
}
|
||||
fn := builtinPkg.Scope.Lookup(obj.Name())
|
||||
if fn == nil {
|
||||
break
|
||||
}
|
||||
decl, ok := fn.Decl.(*ast.FuncDecl)
|
||||
if !ok {
|
||||
break
|
||||
|
@ -119,7 +127,6 @@ func (c *completer) formatBuiltin(obj types.Object, score float64) CompletionIte
|
|||
results, writeResultParens := c.formatFieldList(decl.Type.Results)
|
||||
item.Label, item.Detail = formatFunction(obj.Name(), params, results, writeResultParens)
|
||||
item.Snippet, item.PlaceholderSnippet = c.functionCallSnippets(obj.Name(), params)
|
||||
item.Kind = FunctionCompletionItem
|
||||
case *types.TypeName:
|
||||
if types.IsInterface(obj.Type()) {
|
||||
item.Kind = InterfaceCompletionItem
|
||||
|
|
|
@ -31,7 +31,7 @@ func (c *completer) structFieldSnippets(label, detail string) (*snippet.Builder,
|
|||
if i >= len(lit.Elts) {
|
||||
return nil, nil
|
||||
}
|
||||
// If the expression is not an identifer, it is not a struct field name.
|
||||
// If the expression is not an identifier, it is not a struct field name.
|
||||
if _, ok := lit.Elts[i].(*ast.Ident); !ok {
|
||||
return nil, nil
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue