-
Notifications
You must be signed in to change notification settings - Fork 646
Show completion for newly created package. #1191
Conversation
@uudashr, |
@ramya-rao-a check please |
src/goPackages.ts
Outdated
let pkgs = new Map<string, string>(); | ||
chunks.join('').split('\n').forEach((pkgPath) => { | ||
if (!pkgPath) return; | ||
const lastIndex = pkgPath.lastIndexOf('/'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The main reason I used go list all
instead of gopkgs
initially was to get the package name and not rely on the import path of the package to determine the package name like you are doing here.
Because package names need not necessarily be the last part of the package path. See #647
And we use the package names to provide completion for unimported packages.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I see... make sense, because it completion, not import package
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, and later on I added the Go: Browse Packages
feature because then I had all the packages in hand, so it seemed like a good feature to add
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can strip off the version part from "pkgname.v1" , it works when people always using standard way on naming package related to the package path, but that doesn't guarantee
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That's exactly what I did in cb0d2bc :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cb0d2bc no longer in master?
Here are some example, can't guarantee consistent pattern:
- speech;google.golang.org/api/speech/v1beta1
- spectrum;google.golang.org/api/spectrum/v1explorer
- speech;google.golang.org/api/speech/v1
- prediction;google.golang.org/api/prediction/v1.2
- tilde;gopkg.in/mattes/go-expand-tilde.v1
So using go list -f '{{.Name}};{{.ImportPath}}' all
is the proper way, it just need to make it faster.
Case
- Autocomplete un-imported will suggest only packages on cache, no way to suggest new package since it need invalidation. Need to listen some events to invalidates, haven't figure out which one.
- Go: Browse Packages use
https://github.com/tpng/gopkgs
which looks in$GOPATH/pkg
, new package will not exists in$GOPATH/pkg
, so browse package will not help. Except we change it, usehttps://github.com/haya14busa/gopkgs
which search in$GOPATH/src
. This is workaround, but still completion still stale.
Btw, why not change to https://github.com/haya14busa/gopkgs
for Browse Packages? It seems good improvement, solve one problem.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I replaced cb0d2bc with using go list -f '{{.Name}};{{.ImportPath}}' all
I am fine with auto complete using cache as it does today.
I didnt use https://github.com/tpng/gopkgs
for the Browse Packages
feature as it will not have the "main" packages as in the ones that are executable
I am fine with using https://github.com/haya14busa/gopkgs
for just the Browse Packages feature as well as long as it lists the "main" packages as well
@ramya-rao-a latest changes should be able to show correct package name |
@ramya-rao-a please check |
@uudashr, |
src/goInstallTools.ts
Outdated
function getMissingTools(goVersion: SemVersion): Promise<string[]> { | ||
let keys = Object.keys(getTools(goVersion)); | ||
return Promise.all<string>(keys.map(tool => new Promise<string>((resolve, reject) => { | ||
if (tool === 'gopkgs') { | ||
gopkgsMissing().then((missing) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This line will be reached only when there is no gopkgs
tool in the user's machine.
Whereas you are expecting to reach here to make a decision on whether the gopkgs
present in the user machine is the old one or the new one
What do you think of this instead?
ramya-rao-a@2119ec1
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ahhh... I see your point. Agree with that. We can remove the gopkgsMissing()
then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, I have pushed my change to your branch
@uudashr The below assert is failing when vendor is not supported. Any idea why? https://github.com/uudashr/vscode-go/blob/faster-go-list-all/test/go.test.ts#L590 |
@ramya-rao-a Not sure, still investigating... |
@uudashr Tests are fixed now |
@uudashr First off, thanks for all your work in getting this together There are a few things I still want to discuss
|
You are welcome... thanks for fixing the test
|
@ramya-rao-a for point number 2, roughly will be going to be like https://gist.github.com/uudashr/8fbacf975cb8140b962fc7fd3122ff22 |
Previously the
goListAll()
cache the packages, resulting completion for newly created package not shown because the outdated cache and it quite irritating.To takeout cache, we need to invoke
go list all
on demand. But the execution time is unacceptable, it will try to load packages from GOROOT, GOPATH and also user home directory. That is whycp.spawn('go', [], { env: process.env })
took so long, and by not providing the env will execute faster.Better implementation package listing tools
https://github.com/haya14busa/gopkgs
. It search the packages from golangsrc
. So I replace thego list all
usinggopkgs
.go list all
took 4.87sgopkgs
took 0.08sgoListAll()
and it fast.