1 module served.utils.progress; 2 3 import std.format; 4 import core.time : MonoTime; 5 6 import served.types; 7 8 /// Documents a progress type should have progress attached 9 private enum withProgress; 10 11 /// Documents a progress type can possibly have some progress attached 12 private enum optionalProgress; 13 14 /// The types to report 15 enum ProgressType 16 { 17 /// default invalid/ignored value 18 unknown, 19 /// sent when serve-d is first registering all workspace-d components. Sent on first configLoad. 20 globalStartup, 21 /// sent before each workspace that is going to be loaded. Sent for every workspace. 22 /// sent with workspaceUri argument 23 @optionalProgress configLoad, 24 /// sent when all workspaces have been loaded. Sent when everything is initialized. 25 configFinish, 26 /// sent for each root of a workspace on startup. Sent for every configLoad for all roots. 27 /// sent with root.uri argument 28 /// 29 /// With current lazy implementation this is instantly done 30 @withProgress workspaceStartup, 31 /// sent for every auto completion server starting up. Sent after all workspaceStartups for a workspace. 32 /// sent with root.uri argument 33 /// 34 /// With current lazy implementation this is instantly done 35 @withProgress completionStartup, 36 /// sent when dub is being reloaded 37 /// sent with instance.uri argument 38 @withProgress dubReload, 39 /// sent when the import paths are being indexed 40 /// sent with instance.uri argument 41 @withProgress importReload, 42 /// sent when dub is being upgraded before imports are being reloading 43 /// sent with instance.uri argument 44 @withProgress importUpgrades, 45 } 46 47 void reportProgress(Args...)(bool condition, ProgressType type, size_t step, size_t max, Args args) 48 { 49 if (condition) 50 reportProgress(type, step, max, args); 51 } 52 53 void reportProgress(Args...)(ProgressType type, size_t step, size_t max, Args args) 54 { 55 double time = (MonoTime.currTime() - startupTime).total!"msecs" / 1000.0; 56 if (max > 0) 57 rpc.log(format!"[progress] [%09.3f] [%s] %d / %d: "(time, type, step, max), args); 58 else if (step > 0) 59 rpc.log(format!"[progress] [%09.3f] [%s] %d: "(time, type, step), args); 60 else if (Args.length > 0) 61 rpc.log(format!"[progress] [%09.3f] [%s]: "(time, type), args); 62 else 63 rpc.log(format!"[progress] [%09.3f] [%s]"(time, type)); 64 }