Skip to content

Commit 1f9bbca

Browse files
authored
Convert OCE to empty value on certain VS operations (#17906)
1 parent e49b91f commit 1f9bbca

File tree

3 files changed

+21
-6
lines changed

3 files changed

+21
-6
lines changed

vsintegration/src/FSharp.Editor/Classification/ClassificationService.fs

+1
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,7 @@ type internal FSharpClassificationService [<ImportingConstructor>] () =
295295

296296
addSemanticClassification sourceText textSpan classificationData result
297297
}
298+
|> CancellableTask.ifCanceledReturn ()
298299
|> CancellableTask.startAsTask cancellationToken
299300

300301
// Do not perform classification if we don't have project options (#defines matter)

vsintegration/src/FSharp.Editor/Common/CancellableTasks.fs

+17-6
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
// The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
2020

2121
// 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.
22-
22+
2323
namespace Microsoft.VisualStudio.FSharp.Editor
2424

2525
// Don't warn about the resumable code invocation
@@ -467,8 +467,8 @@ module CancellableTasks =
467467
// Low priority extensions
468468
type CancellableTaskBuilderBase with
469469

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

474474
/// <summary>
@@ -611,10 +611,10 @@ module CancellableTasks =
611611
fun sm ->
612612
if __useResumableCode then
613613
sm.Data.ThrowIfCancellationRequested()
614-
614+
615615
let mutable awaiter = getAwaiter
616616
let mutable __stack_fin = true
617-
617+
618618
if not (Awaiter.isCompleted awaiter) then
619619
let __stack_yield_fin = ResumableCode.Yield().Invoke(&sm)
620620
__stack_fin <- __stack_yield_fin
@@ -706,7 +706,7 @@ module CancellableTasks =
706706
(task: 'Awaitable)
707707
: 'Awaiter =
708708
Awaitable.getAwaiter task
709-
709+
710710

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

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

1122+
/// If this CancellableTask gets canceled for another reason than the token being canceled, return the specified value.
1123+
let inline ifCanceledReturn value (ctask : CancellableTask<_>) =
1124+
cancellableTask {
1125+
let! ct = getCancellationToken ()
1126+
1127+
try
1128+
return! ctask
1129+
with :? OperationCanceledException when ct.IsCancellationRequested = false ->
1130+
return value
1131+
}
1132+
11221133
/// <exclude />
11231134
[<AutoOpen>]
11241135
module MergeSourcesExtensions =

vsintegration/src/FSharp.Editor/Structure/BlockStructureService.fs

+3
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,8 @@ open CancellableTasks
156156
[<Export(typeof<IFSharpBlockStructureService>)>]
157157
type internal FSharpBlockStructureService [<ImportingConstructor>] () =
158158

159+
let emptyValue = FSharpBlockStructure ImmutableArray.empty
160+
159161
interface IFSharpBlockStructureService with
160162

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

0 commit comments

Comments
 (0)