@@ -43,41 +43,47 @@ local function status_cmd()
4343 local data = require (" ccusage.data" )
4444 local verbose_formatter = require (" ccusage.formatters.verbose" )
4545
46- -- Get formatter context with unified error handling
47- local context = data .get_formatter_context ()
46+ -- Helper function to handle the formatted context
47+ local function handle_context (context )
48+ -- Handle errors with appropriate notifications
49+ if not context .data then
50+ vim .notify (" ccusage CLI not found. Please install with: npm install -g ccusage" , vim .log .levels .ERROR , {
51+ title = " CCUsage Error" ,
52+ })
53+ return
54+ end
4855
49- -- Handle errors with appropriate notifications
50- if not context .data then
51- vim .notify (" ccusage CLI not found. Please install with: npm install -g ccusage" , vim .log .levels .ERROR , {
52- title = " CCUsage Error" ,
53- })
54- return
55- end
56+ if not context .stats then
57+ vim .notify (" Unable to compute usage statistics" , vim .log .levels .WARN , {
58+ title = " CCUsage" ,
59+ })
60+ return
61+ end
5662
57- if not context .stats then
58- vim .notify (" Unable to compute usage statistics" , vim .log .levels .WARN , {
59- title = " CCUsage" ,
60- })
61- return
62- end
63+ -- Format the data using the verbose formatter
64+ local formatted_message = verbose_formatter (context )
65+ if not formatted_message then
66+ vim .notify (" Unable to format usage statistics" , vim .log .levels .WARN , {
67+ title = " CCUsage" ,
68+ })
69+ return
70+ end
71+
72+ -- Get appropriate log level and title
73+ local level = get_log_level (context )
74+ local title = get_title (context )
6375
64- -- Format the data using the verbose formatter
65- local formatted_message = verbose_formatter (context )
66- if not formatted_message then
67- vim .notify (" Unable to format usage statistics" , vim .log .levels .WARN , {
68- title = " CCUsage" ,
76+ -- Show notification
77+ vim .notify (formatted_message , level , {
78+ title = title ,
79+ timeout = 5000 , -- Show for 5 seconds
6980 })
70- return
7181 end
7282
73- -- Get appropriate log level and title
74- local level = get_log_level (context )
75- local title = get_title (context )
76-
77- -- Show notification
78- vim .notify (formatted_message , level , {
79- title = title ,
80- timeout = 10000 , -- Show for 10 seconds
83+ -- Get formatter context with bypass cache and callback
84+ data .get_formatter_context ({
85+ bypass_cache = true ,
86+ callback = handle_context ,
8187 })
8288end
8389
0 commit comments