Skip to content
This repository has been archived by the owner on Oct 27, 2021. It is now read-only.

suggest: fix panic when suggesting at the beginning of a file #24

Merged
merged 1 commit into from
Apr 27, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion suggest/suggest.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ func (c *Config) Suggest(filename string, data []byte, cursor int) ([]Candidate,
}

fset, pos, pkg := c.analyzePackage(filename, data, cursor)
if pkg == nil {
return nil, 0
}
scope := pkg.Scope().Innermost(pos)

ctx, expr, partial := deduceCursorContext(data, cursor)
Expand Down Expand Up @@ -83,7 +86,11 @@ func (c *Config) analyzePackage(filename string, data []byte, cursor int) (*toke
if err != nil {
c.logParseError("Error parsing input file (outer block)", err)
}
pos := fset.File(fileAST.Pos()).Pos(cursor)
astPos := fileAST.Pos()
if astPos == 0 {
return nil, token.NoPos, nil
}
pos := fset.File(astPos).Pos(cursor)

var otherASTs []*ast.File
for _, otherName := range c.findOtherPackageFiles(filename, fileAST.Name.Name) {
Expand Down
1 change: 1 addition & 0 deletions suggest/testdata/test.0063/out.expected
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Nothing to complete.
1 change: 1 addition & 0 deletions suggest/testdata/test.0063/test.go.in
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
pa@