Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit6f5b2c4

Browse files
dsymeKevinRansom
authored andcommitted
fix cancellation warnings (#3077)
1 parentf09f727 commit6f5b2c4

18 files changed

+70
-53
lines changed

‎vsintegration/src/FSharp.Editor/Classification/ColorizationService.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ type internal FSharpColorizationService
3030
memberthis.AddSyntacticClassificationsAsync(document:Document,textSpan:TextSpan,result:List<ClassifiedSpan>,cancellationToken:CancellationToken)=
3131
async{
3232
letdefines= projectInfoManager.GetCompilationDefinesForEditingDocument(document)
33-
let!sourceText= document.GetTextAsync(cancellationToken)
33+
let!sourceText= document.GetTextAsync(cancellationToken)|> Async.AwaitTask
3434
result.AddRange(Tokenizer.getColorizationData(document.Id, sourceText, textSpan, Some(document.FilePath), defines, cancellationToken))
3535
}|> RoslynHelpers.StartAsyncUnitAsTask cancellationToken
3636

‎vsintegration/src/FSharp.Editor/CodeFix/AddNewKeywordToDisposableConstructorInvocation.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,8 @@ type internal FSharpAddNewKeywordCodeFixProvider() =
2525
title,
2626
(fun(cancellationToken: CancellationToken)->
2727
async{
28-
let!sourceText= context.Document.GetTextAsync()
28+
let!cancellationToken= Async.CancellationToken
29+
let!sourceText= context.Document.GetTextAsync(cancellationToken)|> Async.AwaitTask
2930
return context.Document.WithText(sourceText.WithChanges(TextChange(TextSpan(context.Span.Start,0),"new")))
3031
}|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
3132
title), context.Diagnostics|> Seq.filter(fun x-> this.FixableDiagnosticIds.Contains x.Id)|> Seq.toImmutableArray)

‎vsintegration/src/FSharp.Editor/CodeFix/AddOpenCodeFixProvider.fs‎

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ type internal FSharpAddOpenCodeFixProvider
3838
fixUnderscoresInMenuText fullName,
3939
fun(cancellationToken: CancellationToken)->
4040
async{
41-
let!sourceText= context.Document.GetTextAsync()
41+
let!cancellationToken= Async.CancellationToken
42+
let!sourceText= context.Document.GetTextAsync(cancellationToken)|> Async.AwaitTask
4243
return context.Document.WithText(sourceText.Replace(context.Span, qualifier))
4344
}|> RoslynHelpers.StartAsyncAsTask(cancellationToken))
4445

@@ -49,7 +50,8 @@ type internal FSharpAddOpenCodeFixProvider
4950
fixUnderscoresInMenuText displayText,
5051
(fun(cancellationToken: CancellationToken)->
5152
async{
52-
let!sourceText= context.Document.GetTextAsync()
53+
let!cancellationToken= Async.CancellationToken
54+
let!sourceText= context.Document.GetTextAsync(cancellationToken)|> Async.AwaitTask
5355
letchangedText,_= OpenDeclarationHelper.insertOpenDeclaration sourceText ctx ns
5456
return context.Document.WithText(changedText)
5557
}|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),

‎vsintegration/src/FSharp.Editor/CodeFix/ImplementInterfaceCodeFixProvider.fs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ type internal FSharpImplementInterfaceCodeFixProvider
118118
title,
119119
(fun(cancellationToken: CancellationToken)->
120120
async{
121-
let!sourceText= context.Document.GetTextAsync()|> Async.AwaitTask
121+
let!sourceText= context.Document.GetTextAsync(cancellationToken)|> Async.AwaitTask
122122
letgetMemberByLocation(name,range:range)=
123123
letlineStr= sourceText.Lines.[range.EndLine-1].ToString()
124124
results.GetSymbolUseAtLocation(range.EndLine, range.EndColumn, lineStr,[name], userOpName=userOpName)

‎vsintegration/src/FSharp.Editor/CodeFix/RenameUnusedValue.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ type internal FSharpRenameUnusedValueCodeFixProvider
3535
title,
3636
(fun(cancellationToken: CancellationToken)->
3737
async{
38-
let!sourceText= context.Document.GetTextAsync()
38+
let!cancellationToken= Async.CancellationToken
39+
let!sourceText= context.Document.GetTextAsync(cancellationToken)|> Async.AwaitTask
3940
return context.Document.WithText(sourceText.WithChanges(textChange))
4041
}|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
4142
title)

‎vsintegration/src/FSharp.Editor/CodeFix/ReplaceWithSuggestion.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ type internal FSharpReplaceWithSuggestionCodeFixProvider() =
2424
title,
2525
(fun(cancellationToken: CancellationToken)->
2626
async{
27-
let!sourceText= context.Document.GetTextAsync()
27+
let!cancellationToken= Async.CancellationToken
28+
let!sourceText= context.Document.GetTextAsync(cancellationToken)|> Async.AwaitTask
2829
return context.Document.WithText(sourceText.WithChanges(textChange))
2930
}|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
3031
title)

‎vsintegration/src/FSharp.Editor/CodeFix/SimplifyName.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ type internal FSharpSimplifyNameCodeFixProvider() =
2323
title,
2424
(fun(cancellationToken: CancellationToken)->
2525
async{
26-
let!sourceText= context.Document.GetTextAsync()
26+
let!cancellationToken= Async.CancellationToken
27+
let!sourceText= context.Document.GetTextAsync(cancellationToken)|> Async.AwaitTask
2728
return context.Document.WithText(sourceText.WithChanges(textChange))
2829
}|> RoslynHelpers.StartAsyncAsTask(cancellationToken)),
2930
title)

‎vsintegration/src/FSharp.Editor/Common/Pervasive.fs‎

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -199,13 +199,4 @@ module Async =
199199
async{return! agent.PostAndAsyncReply id}
200200

201201

202-
typeAsyncBuilderwith
203-
member__.Bind(computation:System.Threading.Tasks.Task<'a>,binder:'a->Async<'b>):Async<'b>=
204-
async{
205-
let!a= Async.AwaitTask computation
206-
return! binder a
207-
}
208-
209-
member__.ReturnFrom(computation:System.Threading.Tasks.Task<'a>):Async<'a>= Async.AwaitTask computation
210-
211202

‎vsintegration/src/FSharp.Editor/Common/RoslynHelpers.fs‎

Lines changed: 23 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ namespace Microsoft.VisualStudio.FSharp.Editor
55
openSystem
66
openSystem.Collections.Immutable
77
openSystem.Collections.Generic
8+
openSystem.Threading
89
openSystem.Threading.Tasks
910
openMicrosoft.CodeAnalysis
1011
openMicrosoft.CodeAnalysis.Text
@@ -85,16 +86,28 @@ module internal RoslynHelpers =
8586

8687
letCollectTaggedText(list:List<_>)(t:TaggedText)= list.Add(TaggedText(roslynTag t.Tag, t.Text))
8788

88-
letStartAsyncAsTask cancellationToken computation=
89-
letcomputation=
90-
async{
91-
try
92-
return! computation
93-
with e->
94-
Assert.Exception(e)
95-
return Unchecked.defaultof<_>
96-
}
97-
Async.StartAsTask(computation, TaskCreationOptions.None, cancellationToken)
89+
typeVolatileBarrier()=
90+
[<VolatileField>]
91+
let mutableisStopped=false
92+
member__.Proceed=not isStopped
93+
member__.Stop()= isStopped<-true
94+
95+
// This is like Async.StartAsTask, but if cancellation occurs we explicitly associate the cancellation with cancellationToken
96+
letStartAsyncAsTask(cancellationToken:CancellationToken)computation=
97+
lettcs=new TaskCompletionSource<_>(TaskCreationOptions.None)
98+
letbarrier= VolatileBarrier()
99+
letreg= cancellationToken.Register(fun _->if barrier.Proceedthen tcs.TrySetCanceled(cancellationToken)|> ignore)
100+
lettask= tcs.Task
101+
letdisposeReg()= barrier.Stop();ifnot task.IsCanceledthen reg.Dispose()
102+
Async.StartWithContinuations(
103+
async{do! Async.SwitchToThreadPool()
104+
return! computation},
105+
continuation=(fun result-> disposeReg(); tcs.TrySetResult(result)|> ignore),
106+
exceptionContinuation=(function:? OperationCanceledException-> disposeReg(); tcs.TrySetCanceled(cancellationToken)|> ignore
107+
| exn-> disposeReg(); tcs.TrySetException(exn)|> ignore),
108+
cancellationContinuation=(fun _oce-> disposeReg(); tcs.TrySetCanceled(cancellationToken)|> ignore),
109+
cancellationToken=cancellationToken)
110+
task
98111

99112
letStartAsyncUnitAsTask cancellationToken(computation:Async<unit>)=
100113
StartAsyncAsTask cancellationToken computation:> Task

‎vsintegration/src/FSharp.Editor/Debugging/LanguageDebugInfoService.fs‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,8 @@ type internal FSharpLanguageDebugInfoService [<ImportingConstructor>](projectInf
5353
memberthis.GetDataTipInfoAsync(document:Document,position:int,cancellationToken:CancellationToken):Task<DebugDataTipInfo>=
5454
async{
5555
letdefines= projectInfoManager.GetCompilationDefinesForEditingDocument(document)
56-
let!sourceText= document.GetTextAsync(cancellationToken)
56+
let!cancellationToken= Async.CancellationToken
57+
let!sourceText= document.GetTextAsync(cancellationToken)|> Async.AwaitTask
5758
lettextSpan= TextSpan.FromBounds(0, sourceText.Length)
5859
lettokens= Tokenizer.getColorizationData(document.Id, sourceText, textSpan, Some(document.Name), defines, cancellationToken)
5960
letresult=

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp