Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Convert OCE to empty value on certain VS operations #17906

Merged
merged 2 commits into from
Oct 23, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -295,6 +295,7 @@ type internal FSharpClassificationService [<ImportingConstructor>] () =

addSemanticClassification sourceText textSpan classificationData result
}
|> CancellableTask.ifCanceledReturn ()
|> CancellableTask.startAsTask cancellationToken

// Do not perform classification if we don't have project options (#defines matter)
Expand Down
23 changes: 17 additions & 6 deletions vsintegration/src/FSharp.Editor/Common/CancellableTasks.fs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

namespace Microsoft.VisualStudio.FSharp.Editor

// Don't warn about the resumable code invocation
Expand Down Expand Up @@ -467,8 +467,8 @@ module CancellableTasks =
// Low priority extensions
type CancellableTaskBuilderBase with

[<NoEagerConstraintApplication>]
member inline _.Source(awaiter: CancellableTask<unit array>) =
[<NoEagerConstraintApplication>]
member inline _.Source(awaiter: CancellableTask<unit array>) =
(fun (token) -> (awaiter token :> Task).GetAwaiter())

/// <summary>
Expand Down Expand Up @@ -611,10 +611,10 @@ module CancellableTasks =
fun sm ->
if __useResumableCode then
sm.Data.ThrowIfCancellationRequested()

let mutable awaiter = getAwaiter
let mutable __stack_fin = true

if not (Awaiter.isCompleted awaiter) then
let __stack_yield_fin = ResumableCode.Yield().Invoke(&sm)
__stack_fin <- __stack_yield_fin
Expand Down Expand Up @@ -706,7 +706,7 @@ module CancellableTasks =
(task: 'Awaitable)
: 'Awaiter =
Awaitable.getAwaiter task


/// <summary>Allows the computation expression to turn other types into CancellationToken -> 'Awaiter</summary>
///
Expand Down Expand Up @@ -1119,6 +1119,17 @@ module CancellableTasks =

let inline ignore ([<InlineIfLambda>] ctask: CancellableTask<_>) = toUnit ctask

/// If this CancellableTask gets canceled for another reason than the token being canceled, return the specified value.
let inline ifCanceledReturn value (ctask : CancellableTask<_>) =
cancellableTask {
let! ct = getCancellationToken ()

try
return! ctask
with :? OperationCanceledException when ct.IsCancellationRequested = false ->
return value
}

/// <exclude />
[<AutoOpen>]
module MergeSourcesExtensions =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,8 @@ open CancellableTasks
[<Export(typeof<IFSharpBlockStructureService>)>]
type internal FSharpBlockStructureService [<ImportingConstructor>] () =

let emptyValue = FSharpBlockStructure ImmutableArray.empty

interface IFSharpBlockStructureService with

member _.GetBlockStructureAsync(document, cancellationToken) : Task<FSharpBlockStructure> =
Expand All @@ -171,4 +173,5 @@ type internal FSharpBlockStructureService [<ImportingConstructor>] () =
|> Seq.toImmutableArray
|> FSharpBlockStructure
}
|> CancellableTask.ifCanceledReturn emptyValue
|> CancellableTask.start cancellationToken
Loading