Skip to content

Commit

Permalink
Notify user in console when gopkgs returns no packages. Fixes microso…
Browse files Browse the repository at this point in the history
  • Loading branch information
mkorejo committed Feb 20, 2018
1 parent 4884626 commit 801ac6f
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions src/goPackages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ import { promptForMissingTool, promptForUpdatingTool } from './goInstallTools';
type GopkgsDone = (res: Map<string, string>) => void;
let allPkgsCache: Map<string, string>;
let allPkgsLastHit: number;
let gopkgsNotified: boolean = false;
let gopkgsRunning: boolean = false;
let gopkgsSubscriptions: GopkgsDone[] = [];
let cacheTimeout: number = 5000;

function gopkgs(): Promise<Map<string, string>> {
let t0 = Date.now();
Expand Down Expand Up @@ -59,7 +59,7 @@ function gopkgs(): Promise<Map<string, string>> {
}
*/
sendTelemetryEvent('gopkgs', {}, { timeTaken });
cacheTimeout = timeTaken > 5000 ? timeTaken : 5000;

return resolve(pkgs);
});
});
Expand Down Expand Up @@ -93,7 +93,7 @@ function getAllPackagesNoCache(): Promise<Map<string, string>> {
* @returns Map<string, string> mapping between package import path and package name
*/
export function getAllPackages(): Promise<Map<string, string>> {
let useCache = allPkgsCache && allPkgsLastHit && (new Date().getTime() - allPkgsLastHit) < cacheTimeout;
let useCache = allPkgsCache && allPkgsLastHit && (new Date().getTime() - allPkgsLastHit) < 5000;
if (useCache) {
allPkgsLastHit = new Date().getTime();
return Promise.resolve(allPkgsCache);
Expand All @@ -102,6 +102,10 @@ export function getAllPackages(): Promise<Map<string, string>> {
return getAllPackagesNoCache().then((pkgs) => {
if (!pkgs || pkgs.size === 0) {
console.log('Could not find packages. Ensure `gopkgs -format {{.Name}};{{.ImportPath}}` runs successfully.');
if (!gopkgsNotified) {
vscode.window.showInformationMessage('Could not find packages. Ensure `gopkgs -format {{.Name}};{{.ImportPath}}` runs successfully.');
gopkgsNotified = true;
}
}
allPkgsLastHit = new Date().getTime();
return allPkgsCache = pkgs;
Expand Down

0 comments on commit 801ac6f

Please sign in to comment.