Skip to content

Commit

Permalink
Merge branch 'master' into xerror
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Steinke committed May 31, 2019
2 parents 3706d2b + 26e35f1 commit 53e600e
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions internal/lsp/cache/parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -61,32 +61,36 @@ func (imp *importer) parseFiles(filenames []string) ([]*ast.File, []error) {
wg.Add(1)
go func(i int, filename string) {
ioLimit <- true // wait
defer func() {
<-ioLimit // signal done
wg.Done()
}()

if gof.ast != nil {
if gof.ast != nil { // already have an ast
parsed[i], errors[i] = gof.ast, nil
} else {
// We don't have a cached AST for this file.
gof.read(imp.ctx)
if gof.fc.Error != nil {
return
}
src := gof.fc.Data
if src == nil {
parsed[i], errors[i] = nil, xerrors.Errorf("No source for %v", filename)
} else {
// ParseFile may return both an AST and an error.
parsed[i], errors[i] = parseFile(imp.fset, filename, src)
return
}

// No cached AST for this file, so try parsing it.
gof.read(imp.ctx)
if gof.fc.Error != nil { // file content error, so abort
return
}

// Fix any badly parsed parts of the AST.
if file := parsed[i]; file != nil {
tok := imp.fset.File(file.Pos())
imp.view.fix(imp.ctx, parsed[i], tok, src)
}
}
src := gof.fc.Data
if src == nil { // no source
parsed[i], errors[i] = nil, xerrors.Errorf("No source for %v", filename)
return
}

<-ioLimit // signal
wg.Done()
// ParseFile may return a partial AST AND an error.
parsed[i], errors[i] = parseFile(imp.fset, filename, src)

// Fix any badly parsed parts of the AST.
if file := parsed[i]; file != nil {
tok := imp.fset.File(file.Pos())
imp.view.fix(imp.ctx, parsed[i], tok, src)
}
}(i, filename)
}
wg.Wait()
Expand Down

0 comments on commit 53e600e

Please sign in to comment.