Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 0 additions & 4 deletions tests/benchmarks/CompilerServiceBenchmarks/Program.fs
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,10 @@
open System.IO
open System.Text
open System.Threading.Tasks
open FSharp.Compiler.ErrorLogger
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.Diagnostics
open FSharp.Compiler.Syntax
open FSharp.Compiler.Symbols
open FSharp.Compiler.EditorServices
open FSharp.Compiler.Text
open FSharp.Compiler.AbstractIL
open FSharp.Compiler.AbstractIL.IL
open FSharp.Compiler.AbstractIL.ILBinaryReader
open Microsoft.CodeAnalysis.Text
Expand Down
1 change: 1 addition & 0 deletions tests/service/Common.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ open System.Diagnostics
open System.IO
open System.Collections.Generic
open System.Collections.Immutable
open System.Threading
open System.Threading.Tasks
open FSharp.Compiler.CodeAnalysis
open FSharp.Compiler.IO
Expand Down
26 changes: 15 additions & 11 deletions vsintegration/src/FSharp.Editor/Common/Extensions.fs
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module internal Microsoft.VisualStudio.FSharp.Editor.Extensions
open System
open System.IO
open System.Collections.Immutable
open System.Threading
open System.Threading.Tasks

open Microsoft.CodeAnalysis
Expand Down Expand Up @@ -293,14 +294,17 @@ module Exception =
|> String.concat " ---> "

type Async with
static member RunImmediate (computation: Async<'T>, ?cancellationToken ) =
let cancellationToken = defaultArg cancellationToken Async.DefaultCancellationToken
let ts = TaskCompletionSource<'T>()
let task = ts.Task
Async.StartWithContinuations(
computation,
(fun k -> ts.SetResult k),
(fun exn -> ts.SetException exn),
(fun _ -> ts.SetCanceled()),
cancellationToken)
task.Result
static member RunImmediateExceptOnUI (computation: Async<'T>, ?cancellationToken ) =
match SynchronizationContext.Current with
| null ->
let cancellationToken = defaultArg cancellationToken Async.DefaultCancellationToken
let ts = TaskCompletionSource<'T>()
let task = ts.Task
Async.StartWithContinuations(
computation,
(fun k -> ts.SetResult k),
(fun exn -> ts.SetException exn),
(fun _ -> ts.SetCanceled()),
cancellationToken)
task.Result
| _ -> Async.RunSynchronously(computation, ?cancellationToken=cancellationToken)
Original file line number Diff line number Diff line change
Expand Up @@ -107,4 +107,4 @@ type internal FSharpIndentationService
match indent with
| None -> Nullable()
| Some(indentation) -> Nullable<FSharpIndentationResult>(FSharpIndentationResult(sourceText.Lines.[lineNumber].Start, indentation))
} |> (fun c -> Async.RunImmediate(c,cancellationToken=cancellationToken))
} |> (fun c -> Async.RunImmediateExceptOnUI(c,cancellationToken=cancellationToken))
Original file line number Diff line number Diff line change
Expand Up @@ -203,7 +203,7 @@ type Document with
let workspaceService = this.Project.Solution.GetFSharpWorkspaceService()
let parsingOptions, _, _ =
workspaceService.FSharpProjectOptionsManager.TryGetOptionsForDocumentOrProject(this, CancellationToken.None, nameof(this.SetFSharpProjectOptionsForTesting))
|> Async.RunImmediate
|> Async.RunImmediateExceptOnUI
|> Option.get
ProjectCache.Projects.Add(this.Project, (workspaceService.Checker, workspaceService.FSharpProjectOptionsManager, parsingOptions, projectOptions))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ type internal GoToDefinition(metadataAsSource: FSharpMetadataAsSourceService) =
}

let span =
match Async.RunImmediate(goToAsync, cancellationToken = cancellationToken) with
match Async.RunImmediateExceptOnUI(goToAsync, cancellationToken = cancellationToken) with
| Some span -> span
| _ -> TextSpan()

Expand Down