Skip to content

Commit 0444ce1

Browse files
committed
Add package to cache when autocompleting unimported packages.
Fixes #484.
1 parent e16c74a commit 0444ce1

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

autocompletecontext.go

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -367,7 +367,9 @@ func (c *auto_complete_context) apropos(file []byte, filename string, cursor int
367367
if !ok {
368368
var d *decl
369369
if ident, ok := cc.expr.(*ast.Ident); ok && g_config.UnimportedPackages {
370-
d = resolveKnownPackageIdent(ident.Name, c.current.name, c.current.context)
370+
p := resolveKnownPackageIdent(ident.Name, c.current.name, c.current.context)
371+
c.pcache[p.name] = p
372+
d = p.main
371373
}
372374
if d == nil {
373375
return nil, 0

cursorcontext.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ func (c *auto_complete_context) deduce_cursor_context(file []byte, cursor int) (
422422
// package name has nothing to do with package file name, that's why we need to
423423
// scan the packages. And many of them will have conflicts. Can we make a smart
424424
// prediction algorithm which will prefer certain packages over another ones?
425-
func resolveKnownPackageIdent(ident string, filename string, context *package_lookup_context) *decl {
425+
func resolveKnownPackageIdent(ident string, filename string, context *package_lookup_context) *package_file_cache {
426426
importPath, ok := knownPackageIdents[ident]
427427
if !ok {
428428
return nil
@@ -433,9 +433,9 @@ func resolveKnownPackageIdent(ident string, filename string, context *package_lo
433433
return nil
434434
}
435435

436-
p := new_package_file_cache(path, path)
436+
p := new_package_file_cache(path, importPath)
437437
p.update_cache()
438-
return p.main
438+
return p
439439
}
440440

441441
var knownPackageIdents = map[string]string{

0 commit comments

Comments
 (0)