首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何异步更新ICompletionSource中的完成结果?

如何异步更新ICompletionSource中的完成结果?
EN

Stack Overflow用户
提问于 2014-08-25 22:15:06
回答 1查看 540关注 0票数 1

我正在尝试在Visual Studio中为Google Dart语言实现代码完成。我已经成功地在ICompletionSource like this中实现了一些硬编码的值

代码语言:javascript
复制
class CompletionSource : ICompletionSource
{
    CompletionSourceProvider provider;
    ITextBuffer buffer;
    ITextDocumentFactoryService textDocumentFactory;
    DartAnalysisService analysisService;

    public CompletionSource(CompletionSourceProvider provider, ITextBuffer buffer, ITextDocumentFactoryService textDocumentFactory, DartAnalysisService analysisService)
    {
        this.provider = provider;
        this.buffer = buffer;
        this.textDocumentFactory = textDocumentFactory;
        this.analysisService = analysisService;
    }

    public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
    {
        var triggerPoint = session.GetTriggerPoint(buffer.CurrentSnapshot);
        if (triggerPoint == null)
            return;

        var applicableTo = buffer.CurrentSnapshot.CreateTrackingSpan(new SnapshotSpan(triggerPoint.Value, 1), SpanTrackingMode.EdgeInclusive);

        var completions = new ObservableCollection<Completion>();
        completions.Add(new Completion("Something1"));
        completions.Add(new Completion("Something2"));
        completions.Add(new Completion("Something3"));

        completionSets.Add(new CompletionSet("All", "All", applicableTo, completions, Enumerable.Empty<Completion>()));
    }

    public void Dispose()
    {
        GC.SuppressFinalize(true);
    }
}

这一切都运行得很好。然而,在实际的实现中,获取完成的操作很慢(它由另一个进程处理),所以我需要能够稍后返回这些结果。

如果我同步完成所有工作,编辑器在请求期间挂起(这并不奇怪)。

文档相当糟糕。我尝试了所有的排序;包括在CompletionSet构造函数中使用两个IEnumerable<Completion>参数;在ObservableCollection<Completion>中插入值,在会话和CompletionSet上调用Recalculate()

这是一个在1秒后将第二个值插入到完成列表中的实现。这不起作用;但对于任何想要尝试的人来说,这是一个起点:

代码语言:javascript
复制
    public void AugmentCompletionSession(ICompletionSession session, IList<CompletionSet> completionSets)
    {
        var triggerPoint = session.GetTriggerPoint(buffer.CurrentSnapshot);
        if (triggerPoint == null)
            return;

        ITextDocument doc;
        if (!textDocumentFactory.TryGetTextDocument(buffer, out doc))
            return;

        var applicableTo = buffer.CurrentSnapshot.CreateTrackingSpan(new SnapshotSpan(triggerPoint.Value, 1), SpanTrackingMode.EdgeInclusive);

        var completions = new ObservableCollection<Completion>();
        completions.Add(new Completion("Hard-coded..."));

        var completionSet = new CompletionSet("All", "All", applicableTo, Enumerable.Empty<Completion>(), completions);
        completionSets.Add(completionSet);

        Task.Run(async () =>
        {
            await Task.Delay(1000); // Wait 1s
            completions.Add(new Completion("Danny")); // This doesn't update the code-completion list; why not?
        });
    }
EN

回答 1

Stack Overflow用户

发布于 2014-08-25 23:02:48

您可以在IIntellisenseController实现中异步触发完成本身,而不是异步更新完成源。当您检测到需要完成时,首先执行所需结果的后台计算,然后使用ICompletionBroker触发结果显示。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25487920

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档