public void Start(string code) { Stop(); hasCompletionFinished_ = false; thread_ = new Thread(() => { var completions = CompletionPluginManager.GetCompletions(code); result_.completions = completions; result_.partialCode = completions[0].prefix ?? ""; }); thread_.Start(); }
public async void Start(string code) { Stop(); cancellationTokenSource_ = new CancellationTokenSource(); var token = cancellationTokenSource_.Token; var task = Task.Run(() => { var completions = CompletionPluginManager.GetCompletions(code); token.ThrowIfCancellationRequested(); var result = new Result(); result.completions = completions; result.partialCode = (completions.Length == 0) ? "" : (completions[0].prefix ?? ""); return(result); }, token); try { var result = await task; onCompletionFinished.Invoke(result); } catch (OperationCanceledException) { // ... } finally { if (cancellationTokenSource_ != null) { cancellationTokenSource_.Dispose(); cancellationTokenSource_ = null; } } }
protected virtual void OnDisable() { CompletionPluginManager.UnregisterCompletionPlugins(this); }
protected virtual void OnEnable() { CompletionPluginManager.RegisterCompletionPlugins(this); }