Skip to content

Commit db61e9c

Browse files
jbrown215facebook-github-bot
authored andcommitted
[flow][IDE] Show Root name in status bar message
Summary: Title Changelog: [internal] Reviewed By: SamChou19815 Differential Revision: D70123978 fbshipit-source-id: c233e51cdfe8b2798b9518208a6525c4cdce23ad
1 parent 062bfb5 commit db61e9c

File tree

1 file changed

+37
-15
lines changed

1 file changed

+37
-15
lines changed

src/lsp/flowLsp.ml

Lines changed: 37 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -844,22 +844,35 @@ let do_initialize params : Initialize.result =
844844
server_info = { name = "Flow"; version = Flow_version.version };
845845
}
846846

847+
let message_with_flow_and_root_name_prefix flowconfig msg =
848+
match FlowConfig.root_name flowconfig with
849+
| None -> "Flow: " ^ msg
850+
| Some root -> "Flow (" ^ root ^ "): " ^ msg
851+
847852
let show_connected_status (cenv : connected_env) : connected_env =
853+
let message_with_prefix = message_with_flow_and_root_name_prefix cenv.c_ienv.i_flowconfig in
848854
let (type_, message, shortMessage, progress, total) =
849855
if cenv.c_is_rechecking then
850856
let (server_status, _) = cenv.c_server_status in
851857
if not (ServerStatus.is_free server_status) then
852858
let (shortMessage, progress, total) = ServerStatus.get_progress server_status in
853-
let message = "Flow: " ^ ServerStatus.string_of_status ~use_emoji:false server_status in
854-
(MessageType.WarningMessage, message, shortMessage, progress, total)
859+
let message =
860+
message_with_prefix @@ ServerStatus.string_of_status ~use_emoji:false server_status
861+
in
862+
( MessageType.WarningMessage,
863+
message,
864+
Base.Option.map ~f:message_with_prefix shortMessage,
865+
progress,
866+
total
867+
)
855868
else
856-
(MessageType.WarningMessage, "Flow: Server is rechecking...", None, None, None)
869+
(MessageType.WarningMessage, message_with_prefix "Server is rechecking...", None, None, None)
857870
else
858871
let (_, watcher_status) = cenv.c_server_status in
859872
match watcher_status with
860873
| Some (_, FileWatcherStatus.Deferred { reason }) ->
861874
let message = Printf.sprintf "Waiting for %s to finish" reason in
862-
let short_message = Some "Flow: blocked" in
875+
let short_message = Some (message_with_prefix "blocked") in
863876
(MessageType.WarningMessage, message, short_message, None, None)
864877
| Some (_, FileWatcherStatus.Initializing)
865878
| Some (_, FileWatcherStatus.Ready)
@@ -875,7 +888,7 @@ let show_connected_status (cenv : connected_env) : connected_env =
875888
"https://flow.org/en/docs/lang/lazy-modes/"
876889
| _ -> "Flow is ready."
877890
in
878-
let short_message = Some "Flow: ready" in
891+
let short_message = Some (message_with_prefix "ready") in
879892
(MessageType.InfoMessage, message, short_message, None, None)
880893
in
881894
let c_ienv = show_status ~type_ ~message ~shortMessage ~progress ~total cenv.c_ienv in
@@ -900,26 +913,30 @@ let show_connecting (reason : CommandConnectSimple.error) (env : disconnected_en
900913
Lsp_writers.log_info to_stdout "Starting Flow server";
901914

902915
let (message, shortMessage, progress, total) =
916+
let message_with_prefix = message_with_flow_and_root_name_prefix env.d_ienv.i_flowconfig in
903917
match (reason, env.d_server_status) with
904-
| (CommandConnectSimple.Server_missing, _) -> ("Flow: Server starting", None, None, None)
905-
| (CommandConnectSimple.Server_socket_missing, _) -> ("Flow: Server starting?", None, None, None)
918+
| (CommandConnectSimple.Server_missing, _) ->
919+
(message_with_prefix "Server starting", None, None, None)
920+
| (CommandConnectSimple.Server_socket_missing, _) ->
921+
(message_with_prefix "Server starting?", None, None, None)
906922
| (CommandConnectSimple.(Build_id_mismatch Server_exited), _) ->
907-
("Flow: Server was wrong version and exited", None, None, None)
923+
(message_with_prefix "Server was wrong version and exited", None, None, None)
908924
| (CommandConnectSimple.(Build_id_mismatch (Client_should_error _)), _) ->
909-
("Flow: Server is wrong version", None, None, None)
925+
(message_with_prefix "Server is wrong version", None, None, None)
910926
| (CommandConnectSimple.Server_busy CommandConnectSimple.Too_many_clients, _) ->
911-
("Flow: Server busy", None, None, None)
912-
| (CommandConnectSimple.Server_busy _, None) -> ("Flow: Server busy", None, None, None)
927+
(message_with_prefix "Server busy", None, None, None)
928+
| (CommandConnectSimple.Server_busy _, None) ->
929+
(message_with_prefix "Server busy", None, None, None)
913930
| (CommandConnectSimple.Server_busy _, Some (server_status, watcher_status)) ->
914931
if not (ServerStatus.is_free server_status) then
915932
let (shortMessage, progress, total) = ServerStatus.get_progress server_status in
916-
( "Flow: " ^ ServerStatus.string_of_status ~use_emoji:false server_status,
933+
( message_with_prefix @@ ServerStatus.string_of_status ~use_emoji:false server_status,
917934
shortMessage,
918935
progress,
919936
total
920937
)
921938
else
922-
("Flow: " ^ FileWatcherStatus.string_of_status watcher_status, None, None, None)
939+
(message_with_prefix @@ FileWatcherStatus.string_of_status watcher_status, None, None, None)
923940
in
924941
let d_ienv =
925942
show_status ~type_:MessageType.WarningMessage ~message ~shortMessage ~progress ~total env.d_ienv
@@ -937,8 +954,9 @@ let show_disconnected (code : FlowExit.t option) (message : string option) (env
937954
false
938955
in
939956
let env = { env with d_ienv = { env.d_ienv with i_isConnected } } in
957+
let message_with_prefix = message_with_flow_and_root_name_prefix env.d_ienv.i_flowconfig in
940958
(* show red status *)
941-
let message = Base.Option.value message ~default:"Flow: server is stopped" in
959+
let message = Base.Option.value message ~default:(message_with_prefix "server is stopped") in
942960
let message =
943961
match code with
944962
| Some code -> Printf.sprintf "%s [%s]" message (FlowExit.to_string code)
@@ -1864,7 +1882,11 @@ let try_connect ~version_mismatch_strategy flowconfig_name (env : disconnected_e
18641882
else
18651883
(* We shouldn't hit this case. When `env.d_autostart` is `false`, we ask the server NOT to
18661884
* die on a version mismatch. *)
1867-
let msg = "Flow: the server was the wrong version" in
1885+
let msg =
1886+
message_with_flow_and_root_name_prefix
1887+
env.d_ienv.i_flowconfig
1888+
"the server was the wrong version"
1889+
in
18681890
show_disconnected None (Some msg) { env with d_server_status = None }
18691891
(* The server and the lsp are different binaries and can't talk to each other. The server is not
18701892
stopping (either because we asked it not to stop or because it is newer than this client). In

0 commit comments

Comments
 (0)