示例#1
0
 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();
 }
示例#2
0
        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;
                }
            }
        }
示例#3
0
 protected virtual void OnDisable()
 {
     CompletionPluginManager.UnregisterCompletionPlugins(this);
 }
示例#4
0
 protected virtual void OnEnable()
 {
     CompletionPluginManager.RegisterCompletionPlugins(this);
 }