async void TextBuffer_Changed(object sender, TextContentChangedEventArgs e) { if (!IsCommandMode) { return; } var buf = CreateReplCommandInput(e); if (buf == null) { return; } int baseOffset = this.OffsetOfPrompt.Value; int totalLength = wpfTextView.TextSnapshot.Length - baseOffset; int currentDocVersion = docVersion; prevCommandTextChangedState?.CancelIfSameVersion(commandVersion); var changedState = new CommandTextChangedState(commandVersion); prevCommandTextChangedState = changedState; try { cachedColorsList.SetAsyncUpdatingAfterChanges(baseOffset); await this.CommandHandler.OnCommandUpdatedAsync(buf, changedState.CancellationToken); if (changedState.CancellationToken.IsCancellationRequested) { return; } var cachedColors = new CachedTextColorsCollectionBuilder(this, totalLength).Create(buf.Input, buf.ColorInfos); Debug.Assert(cachedColors.TextLength == totalLength); if (currentDocVersion == docVersion) { cachedColorsList.AddOrUpdate(baseOffset, cachedColors); } } catch (OperationCanceledException ex) when(ex.CancellationToken.Equals(changedState.CancellationToken)) { } catch (Exception ex) { Debug.Fail("Exception: " + ex.Message); if (currentDocVersion == docVersion) { cachedColorsList.AddOrUpdate(baseOffset, new CachedTextColorsCollection()); } } finally { if (prevCommandTextChangedState == changedState) { prevCommandTextChangedState = null; } changedState.Dispose(); } }
async void TextBuffer_Changed(object sender, TextContentChangedEventArgs e) { if (!IsCommandMode) return; var buf = CreateReplCommandInput(e); if (buf == null) return; int baseOffset = OffsetOfPrompt.Value; int totalLength = wpfTextView.TextSnapshot.Length - baseOffset; int currentDocVersion = docVersion; prevCommandTextChangedState?.CancelIfSameVersion(commandVersion); var changedState = new CommandTextChangedState(commandVersion); prevCommandTextChangedState = changedState; try { cachedColorsList.SetAsyncUpdatingAfterChanges(baseOffset); await CommandHandler.OnCommandUpdatedAsync(buf, changedState.CancellationToken); if (changedState.CancellationToken.IsCancellationRequested) return; var cachedColors = new CachedTextColorsCollectionBuilder(this, totalLength).Create(buf.Input, buf.ColorInfos); Debug.Assert(cachedColors.TextLength == totalLength); if (currentDocVersion == docVersion) cachedColorsList.AddOrUpdate(baseOffset, cachedColors); } catch (OperationCanceledException ex) when (ex.CancellationToken.Equals(changedState.CancellationToken)) { } catch (Exception ex) { Debug.Fail("Exception: " + ex.Message); if (currentDocVersion == docVersion) cachedColorsList.AddOrUpdate(baseOffset, new CachedTextColorsCollection()); } finally { if (prevCommandTextChangedState == changedState) prevCommandTextChangedState = null; changedState.Dispose(); } }