未验证 提交 e17f775b 编写于 作者: H Heejae Chang 提交者: GitHub

do not cancel pending incremental parsing request (#27718)

* workaround on long pending incremental parsing requests

* use GetSyntaxTreeAsync so that underlying AsyncLazy reuse same Task for parsing when there are multiple requests

* comment updated

* more comments
上级 1f16bdf8
......@@ -8,6 +8,15 @@
namespace Microsoft.CodeAnalysis.Host
{
/// <summary>
/// when users type, we chain all those changes as incremental parsing requests
/// but doesn't actually realize those changes. it is saved as a pending request.
/// so if nobody asks for final parse tree, those chain can keep grow.
/// we do this since Roslyn is lazy at the core (don't do work if nobody asks for it)
///
/// but certain host such as VS, we have this (BackgroundParser) which preemptively
/// trying to realize such trees for open/active files expecting users will use them soonish.
/// </summary>
internal class BackgroundParser
{
private readonly Workspace _workspace;
......@@ -178,8 +187,16 @@ private void ParseDocumentAsync(Document document)
var cancellationToken = cancellationTokenSource.Token;
// We end up creating a chain of parsing tasks that each attempt to produce
// the appropriate syntax tree for any given document. Once we start work to create
// the syntax tree for a given document, we don't want to stop.
// Otherwise we can end up in the unfortunate scenario where we keep cancelling work,
// and then having the next task re-do the work we were just in the middle of.
// By not cancelling, we can reuse the useful results of previous tasks when performing later steps in the chain.
//
// we still cancel whole task if the task didn't start yet. we just don't cancel if task is started but not finished yet.
var task = _taskScheduler.ScheduleTask(
() => document.GetSyntaxTreeAsync(cancellationToken),
() => document.GetSyntaxTreeAsync(CancellationToken.None),
"BackgroundParser.ParseDocumentAsync",
cancellationToken);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册