Skip to content

Commit

Permalink
Add indicator for failed project loading instead of warning messages
Browse files Browse the repository at this point in the history
  • Loading branch information
Krzysztof-Cieslak committed Jun 11, 2019
1 parent aa2d0ba commit 66118a5
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 30 deletions.
15 changes: 0 additions & 15 deletions src/Core/LanguageService.fs
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,6 @@ module LanguageService =
(err?Message |> unbox<string>), data

let project s =

match client with
| None -> Promise.empty
| Some cl ->
Expand All @@ -240,20 +239,6 @@ module LanguageService =
let res = res.content |> ofJson<obj>
deserializeProjectResult (res |> unbox)
)
|> Promise.onFail(fun _ ->
let disableShowNotification = "FSharp.disableFailedProjectNotifications" |> Configuration.get false
if not disableShowNotification then
let msg = "Project parsing failed: " + path.basename(s)
vscode.window.showErrorMessage(msg, "Disable notification", "Show status")
|> Promise.map(fun res ->
if res = "Disable notification" then
Configuration.set "FSharp.disableFailedProjectNotifications" true
|> ignore
if res = "Show status" then
ShowStatus.CreateOrShow(s, (path.basename(s)))
)
|> ignore
)


let workspacePeek dir deep excludedDirs =
Expand Down
72 changes: 57 additions & 15 deletions src/Core/Project.fs
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ module Project =
let private workspaceLoadedEmitter = EventEmitter<unit>()
let workspaceLoaded = workspaceLoadedEmitter.event

let private statusUpdatedEmitter = EventEmitter<unit>()
let statusUpdated = statusUpdatedEmitter.event

let excluded = "FSharp.excludeProjectDirectories" |> Configuration.get [| ".git"; "paket-files"; ".fable"; "node_modules" |]

let deepLevel = "FSharp.workspaceModePeekDeepLevel" |> Configuration.get 2 |> max 0
Expand Down Expand Up @@ -104,9 +107,12 @@ module Project =
| true, v ->
match v, state with
| ProjectLoadingState.Loaded _, ProjectLoadingState.Loading _ -> ()
| _ -> loadedProjects.Add(path, state)
| _ ->
loadedProjects.Add(path, state)
statusUpdatedEmitter.fire ()
| _ ->
loadedProjects.Add(path, state)
statusUpdatedEmitter.fire ()


let getProjectsFromWorkspacePeek () =
Expand Down Expand Up @@ -641,17 +647,6 @@ module Project =
projectNotRestoredLoadedEmitter.fire d.Project
Some (true, d.Project, ProjectLoadingState.NotRestored (d.Project, msg) )
| ErrorData.ProjectParsingFailed d ->
if not disableShowNotification && d.Project.EndsWith(".fsproj") then
let msg = "Project parsing failed: " + path.basename(d.Project)
vscode.window.showErrorMessage(msg, "Disable notification", "Show status")
|> Promise.map(fun res ->
if res = "Disable notification" then
Configuration.set "FSharp.disableFailedProjectNotifications" true
|> ignore
elif res = "Show status" then
ShowStatus.CreateOrShow(d.Project, (path.basename(d.Project)))
)
|> ignore
Some (true, d.Project, ProjectLoadingState.Failed (d.Project, msg) )
| _ ->
if not disableShowNotification then
Expand Down Expand Up @@ -694,9 +689,6 @@ module Project =
setAnyProjectContext true
| _ -> ()




projs
|> List.ofArray
|> LanguageService.workspaceLoad
Expand All @@ -713,13 +705,57 @@ module Project =
|> Promise.bind (function Some x -> Promise.lift x | None -> getWorkspaceForModeIonideSearch ())
|> Promise.bind (initWorkspaceHelper)

module internal ProjectStatus =
let mutable timer = None
let mutable path = ""

let clearTimer () =
match timer with
| Some t ->
clearTimeout t
timer <- None
| _ -> ()

let mutable item : StatusBarItem option = None
let private hideItem () = item |> Option.iter (fun n -> n.hide ())

let private showItem (text : string) tooltip =
path <- tooltip
item.Value.text <- sprintf "$(flame) %s" text
item.Value.tooltip <- tooltip
item.Value.command <- "showProjStatusFromIndicator"
item.Value.color <- ThemeColor "fsharp.statusBarWarnings" |> U2.Case2
item.Value.show()


let update () =
let projs = getInWorkspace ()
match projs |> List.tryPick (function | ProjectLoadingState.Failed(p,er) -> Some p | _ -> None ) with
| Some p -> showItem "Project loading failed" p
| None ->
match projs |> List.tryPick (function | ProjectLoadingState.Loading(p) -> Some p | _ -> None ) with
| Some p -> showItem "Project loading" p
| None ->
match projs |> List.tryPick (function | ProjectLoadingState.NotRestored(p,_) -> Some p | _ -> None ) with
| Some p -> showItem "Project not restored" p
| None -> hideItem ()

let statusUpdateHandler () =
clearTimer()
timer <- Some (setTimeout (fun () -> update ()) 1000.)




let activate (context : ExtensionContext) =
CurrentWorkspaceConfiguration.setContext context
commands.registerCommand("fsharp.clearCache", clearCache |> unbox<Func<obj,obj>> )
|> context.subscriptions.Add

Notifications.notifyWorkspaceHandler <- Some handleProjectParsedNotification
workspaceNotificationAvaiable <- true
ProjectStatus.item <- Some (window.createStatusBarItem (StatusBarAlignment.Right, 9000. ))
statusUpdated.Invoke(!!ProjectStatus.statusUpdateHandler) |> context.subscriptions.Add

commands.registerCommand("fsharp.changeWorkspace", (fun _ ->
workspacePeek ()
Expand All @@ -729,6 +765,12 @@ module Project =
))
|> context.subscriptions.Add

commands.registerCommand("showProjStatusFromIndicator", (fun _ ->
let name = path.basename (ProjectStatus.path)
ShowStatus.CreateOrShow(ProjectStatus.path,name)
|> box
)) |> context.subscriptions.Add

initWorkspace ()
|> Promise.onSuccess (fun _ ->
setTimeout (fun _ ->
Expand Down

0 comments on commit 66118a5

Please sign in to comment.