Skip to content
This repository has been archived by the owner on Jul 15, 2023. It is now read-only.

Notify user in console when gopkgs returns no packages #1528

Merged
merged 3 commits into from
Feb 20, 2018
Merged
Changes from 1 commit
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
Next Next commit
Notify user in console when gopkgs returns no packages. Fixes #1471
  • Loading branch information
mkorejo committed Feb 20, 2018
commit 801ac6fed61ab9ea5a98e9ebe7cb1e17d707d6e3
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