Skip to content

Commit

Permalink
Slightly better loading error messages (#1234)
Browse files Browse the repository at this point in the history
* Log cancelled as warn, better loading project error message

* Refactor selectProject

* Log cancellation as info

* formatting
  • Loading branch information
TheAngryByrd authored Feb 16, 2024
1 parent d068d9b commit de453f7
Show file tree
Hide file tree
Showing 5 changed files with 330 additions and 334 deletions.
27 changes: 26 additions & 1 deletion src/FsAutoComplete.Core/AdaptiveExtensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ open IcedTasks
open System.Threading



[<AutoOpen>]
module AdaptiveExtensions =

Expand Down Expand Up @@ -286,6 +285,13 @@ module AMap =
HashMap.union removeOps changes |> HashMapDelta


let tryFindR (reason: 'a) (key: 'Key) (map: amap<'Key, 'Value>) : aval<Result<'Value, 'a>> =
aval {
match! AMap.tryFind key map with
| Some x -> return Ok x
| None -> return Error reason
}

/// Adaptively looks up the given key in the map and flattens the value to be easily worked with. Note that this operation should not be used extensively since its resulting aval will be re-evaluated upon every change of the map.
let tryFindAndFlatten (key: 'Key) (map: amap<'Key, aval<option<'Value>>>) =
aval {
Expand All @@ -294,6 +300,7 @@ module AMap =
| None -> return None
}


/// Adaptively looks up the given key in the map and binds the value to be easily worked with. Note that this operation should not be used extensively since its resulting aval will be re-evaluated upon every change of the map.
let tryFindA (key: 'Key) (map: amap<'Key, #aval<'Value>>) =
aval {
Expand Down Expand Up @@ -741,6 +748,15 @@ module AsyncAVal =
let mapOption (f: 'a -> CancellationToken -> 'b) (value: asyncaval<'a option>) : asyncaval<'b option> =
mapSync (fun data ctok -> data |> Option.map (fun d -> f d ctok)) value


/// Returns a new async adaptive value that adaptively applies the mapping function to the given
/// optional adaptive inputs.
let mapResult
(f: 'a -> CancellationToken -> 'b)
(value: asyncaval<Result<'a, 'Error>>)
: asyncaval<Result<'b, 'Error>> =
mapSync (fun data ctok -> data |> Result.map (fun d -> f d ctok)) value

type AsyncAValBuilder() =
member inline x.MergeSources(v1: asyncaval<'T1>, v2: asyncaval<'T2>) =
(v1, v2)
Expand Down Expand Up @@ -829,3 +845,12 @@ module AMapAsync =
| Some x -> return! x
| None -> return None
}


/// Adaptively looks up the given key in the map and flattens the value to be easily worked with. Note that this operation should not be used extensively since its resulting aval will be re-evaluated upon every change of the map.
let tryFindAndFlattenR reason (key: 'Key) (map: amap<'Key, asyncaval<Result<'Value, 'Error>>>) =
asyncAVal {
match! AMap.tryFind key map with
| Some x -> return! x
| None -> return Error reason
}
14 changes: 14 additions & 0 deletions src/FsAutoComplete.Core/AdaptiveExtensions.fsi
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ module ASet =
FSharp.Data.Adaptive.amap<'a, 'b>

module AMap =
open FSharp.Data.Adaptive

/// A simple multi-map implementation.
type internal MultiSetMap<'k, 'v> = FSharp.Data.Adaptive.HashMap<'k, FSharp.Data.Adaptive.HashSet<'v>>
Expand Down Expand Up @@ -109,6 +110,8 @@ module AMap =

override InputChangedObject: t: obj * o: FSharp.Data.Adaptive.IAdaptiveObject -> unit

val tryFindR: reason: 'a -> key: 'Key -> map: amap<'Key, 'Value> -> aval<Result<'Value, 'a>>

/// Adaptively looks up the given key in the map and flattens the value to be easily worked with. Note that this operation should not be used extensively since its resulting aval will be re-evaluated upon every change of the map.
val tryFindAndFlatten:
key: 'Key ->
Expand Down Expand Up @@ -199,6 +202,7 @@ module Extensions =
(System.Threading.CancellationToken -> System.Runtime.CompilerServices.TaskAwaiter<'a>)

module AsyncAVal =
open System.Threading

/// <summary>
/// Evaluates the given adaptive value and returns a Task containing the value.
Expand Down Expand Up @@ -314,6 +318,9 @@ module AsyncAVal =
val mapOption:
f: ('a -> System.Threading.CancellationToken -> 'b) -> value: asyncaval<'a option> -> asyncaval<'b option>

val mapResult:
f: ('a -> CancellationToken -> 'b) -> value: asyncaval<Result<'a, 'Error>> -> asyncaval<Result<'b, 'Error>>

type AsyncAValBuilder =

new: unit -> AsyncAValBuilder
Expand Down Expand Up @@ -355,6 +362,7 @@ module AsyncAValBuilderExtensions =
member inline BindReturn: value: asyncaval<'T1> * mapping: ('T1 -> 'T2) -> asyncaval<'T2>

module AMapAsync =
open FSharp.Data.Adaptive

/// <summary>
/// Adaptively maps over the given map lifting the value in the map to be an asyncaval.
Expand All @@ -380,3 +388,9 @@ module AMapAsync =
/// Adaptively looks up the given key in the map and flattens the value to be easily worked with. Note that this operation should not be used extensively since its resulting aval will be re-evaluated upon every change of the map.
val tryFindAndFlatten:
key: 'Key -> map: FSharp.Data.Adaptive.amap<'Key, asyncaval<'Value option>> -> asyncaval<'Value option>

val tryFindAndFlattenR:
reason: 'Error ->
key: 'Key ->
map: amap<'Key, asyncaval<Result<'Value, 'Error>>> ->
asyncaval<Result<'Value, 'Error>>
Loading

0 comments on commit de453f7

Please sign in to comment.