@@ -6,93 +6,135 @@ use lsp_types::{
66} ;
77use serde:: { Deserialize , Serialize } ;
88
9- use super :: ClientProxy ;
9+ use super :: { ClientId , ClientProxy } ;
1010
11- pub struct VsCodeStatusBar {
11+ pub struct StatusBar {
1212 client : Arc < ClientProxy > ,
1313}
1414
1515#[ derive( Clone , Copy ) ]
16- pub enum Task {
16+ pub enum ProgressTask {
1717 LoadWorkspace = 0 ,
1818 DiagnoseWorkspace = 1 ,
1919}
2020
21- fn get_task_name ( task : & Task ) -> & ' static str {
22- match task {
23- Task :: LoadWorkspace => "Load workspace" ,
24- Task :: DiagnoseWorkspace => "Diagnose workspace" ,
21+ impl ProgressTask {
22+ pub fn as_i32 ( & self ) -> i32 {
23+ * self as i32
24+ }
25+
26+ pub fn get_task_name ( & self ) -> & ' static str {
27+ match self {
28+ ProgressTask :: LoadWorkspace => "Load workspace" ,
29+ ProgressTask :: DiagnoseWorkspace => "Diagnose workspace" ,
30+ }
2531 }
2632}
2733
28- impl VsCodeStatusBar {
34+ impl StatusBar {
2935 pub fn new ( client : Arc < ClientProxy > ) -> Self {
3036 Self { client }
3137 }
3238
33- pub fn set_server_status ( & self , health : & str , loading : bool , message : & str ) {
34- self . client . send_notification (
35- "emmy/setServerStatus" ,
36- EmmyServerStatus {
37- health : health. to_string ( ) ,
38- loading,
39- message : message. to_string ( ) ,
40- } ,
41- ) ;
39+ pub fn create_progress_task ( & self , client_id : ClientId , task : ProgressTask ) {
40+ match client_id {
41+ ClientId :: VSCode => {
42+ self . vscode_set_server_status ( "ok" , true , task. get_task_name ( ) ) ;
43+ }
44+ _ => {
45+ self . client . send_notification (
46+ "window/workDoneProgress/create" ,
47+ WorkDoneProgressCreateParams {
48+ token : NumberOrString :: Number ( task. as_i32 ( ) ) ,
49+ } ,
50+ ) ;
51+ self . client . send_notification (
52+ "$/progress" ,
53+ ProgressParams {
54+ token : NumberOrString :: Number ( task as i32 ) ,
55+ value : ProgressParamsValue :: WorkDone ( WorkDoneProgress :: Begin (
56+ WorkDoneProgressBegin {
57+ title : task. get_task_name ( ) . to_string ( ) ,
58+ cancellable : Some ( false ) ,
59+ message : Some ( task. get_task_name ( ) . to_string ( ) ) ,
60+ percentage : None ,
61+ } ,
62+ ) ) ,
63+ } ,
64+ )
65+ }
66+ }
4267 }
4368
44- pub fn start_task ( & self , task : Task ) {
45- self . client . send_notification (
46- "window/workDoneProgress/create" ,
47- WorkDoneProgressCreateParams {
48- token : NumberOrString :: Number ( task as i32 ) ,
49- } ,
50- ) ;
51- self . client . send_notification (
52- "$/progress" ,
53- ProgressParams {
54- token : NumberOrString :: Number ( task as i32 ) ,
55- value : ProgressParamsValue :: WorkDone ( WorkDoneProgress :: Begin (
56- WorkDoneProgressBegin {
57- title : get_task_name ( & task) . to_string ( ) ,
58- cancellable : Some ( false ) ,
59- message : Some ( get_task_name ( & task) . to_string ( ) ) ,
60- percentage : None ,
61- } ,
62- ) ) ,
63- } ,
64- )
69+ pub fn update_progress_task (
70+ & self ,
71+ client_id : ClientId ,
72+ task : ProgressTask ,
73+ percentage : Option < u32 > ,
74+ message : Option < String > ,
75+ ) {
76+ match client_id {
77+ ClientId :: VSCode => {
78+ if let Some ( message) = message {
79+ self . vscode_report_progress ( & message, percentage. unwrap_or ( 0 ) as f64 / 100.0 ) ;
80+ } else {
81+ self . vscode_report_progress ( task. get_task_name ( ) , percentage. unwrap ( ) as f64 ) ;
82+ }
83+ }
84+ _ => self . client . send_notification (
85+ "$/progress" ,
86+ ProgressParams {
87+ token : NumberOrString :: Number ( task. as_i32 ( ) ) ,
88+ value : ProgressParamsValue :: WorkDone ( WorkDoneProgress :: Report (
89+ WorkDoneProgressReport {
90+ percentage,
91+ cancellable : Some ( false ) ,
92+ message,
93+ } ,
94+ ) ) ,
95+ } ,
96+ ) ,
97+ }
6598 }
6699
67- pub fn update_task ( & self , task : Task , percentage : Option < u32 > , message : Option < String > ) {
68- self . client . send_notification (
69- "$/progress" ,
70- ProgressParams {
71- token : NumberOrString :: Number ( task as i32 ) ,
72- value : ProgressParamsValue :: WorkDone ( WorkDoneProgress :: Report (
73- WorkDoneProgressReport {
74- percentage,
75- cancellable : Some ( false ) ,
76- message,
77- } ,
78- ) ) ,
79- } ,
80- )
100+ pub fn finish_progress_task (
101+ & self ,
102+ client_id : ClientId ,
103+ task : ProgressTask ,
104+ message : Option < String > ,
105+ ) {
106+ match client_id {
107+ ClientId :: VSCode => {
108+ if let Some ( message) = message {
109+ self . vscode_set_server_status ( "ok" , false , & message) ;
110+ } else {
111+ self . vscode_set_server_status ( "ok" , false , task. get_task_name ( ) ) ;
112+ }
113+ }
114+ _ => self . client . send_notification (
115+ "$/progress" ,
116+ ProgressParams {
117+ token : NumberOrString :: Number ( task. as_i32 ( ) ) ,
118+ value : ProgressParamsValue :: WorkDone ( WorkDoneProgress :: End (
119+ WorkDoneProgressEnd { message } ,
120+ ) ) ,
121+ } ,
122+ ) ,
123+ }
81124 }
82125
83- pub fn finish_task ( & self , task : Task , message : Option < String > ) {
126+ fn vscode_set_server_status ( & self , health : & str , loading : bool , message : & str ) {
84127 self . client . send_notification (
85- "$/progress" ,
86- ProgressParams {
87- token : NumberOrString :: Number ( task as i32 ) ,
88- value : ProgressParamsValue :: WorkDone ( WorkDoneProgress :: End ( WorkDoneProgressEnd {
89- message,
90- } ) ) ,
128+ "emmy/setServerStatus" ,
129+ EmmyServerStatus {
130+ health : health. to_string ( ) ,
131+ loading,
132+ message : message. to_string ( ) ,
91133 } ,
92- )
134+ ) ;
93135 }
94136
95- pub fn report_progress ( & self , message : & str , percentage : f64 ) {
137+ fn vscode_report_progress ( & self , message : & str , percentage : f64 ) {
96138 self . client . send_notification (
97139 "emmy/progressReport" ,
98140 EmmyProgress {
0 commit comments