我正在尝试在Visual Studio中为Google Dart语言实现代码完成。我已经成功地在ICompletionSource like this中实现了一些硬编码的值
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秒后将第二个值插入到完成列表中的实现。这不起作用;但对于任何想要尝试的人来说,这是一个起点:
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?
});
}发布于 2014-08-25 23:02:48
您可以在IIntellisenseController实现中异步触发完成本身,而不是异步更新完成源。当您检测到需要完成时,首先执行所需结果的后台计算,然后使用ICompletionBroker触发结果显示。
https://stackoverflow.com/questions/25487920
复制相似问题