<commit_before>﻿using Caliburn.Micro;
using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Editing;
using SMAStudiovNext.Core;
using SMAStudiovNext.Modules.Runbook.Editor.Completion;
using SMAStudiovNext.Modules.WindowRunbook.Editor.Completion;
using System.Linq;
using System.Management.Automation.Language;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;

namespace SMAStudiovNext.Modules.Runbook.Editor
{
    public class KeystrokeService
    {
        private readonly ICompletionProvider _completionProvider;
        private readonly TextArea _textArea;

        private CompletionWindow _completionWindow = null;
        private long _triggerTag;
        private bool _openedByControlSpace = false;

        public KeystrokeService(TextArea textArea, ICompletionProvider completionProvider)
        {
            _completionProvider = completionProvider;
            _completionProvider.OnCompletionCompleted += OnCompletionResultRetrieved;

            _textArea = textArea;
            _textArea.KeyUp += OnKeyReleased;
            _textArea.TextEntered += OnTextEntered;
        }

        #region Event Handlers
        private void OnTextEntered(object sender, TextCompositionEventArgs e)
        {
            var ch = e.Text[0];
            var lineText = string.Empty;
            var caretPosition = -1;
            var caretLinePosition = -1;

            Execute.OnUIThread(() =>
            {
                var line = _textArea.Document.GetLineByOffset(_textArea.Caret.Offset);
                lineText = _textArea.Document.GetText(line);
                caretPosition = _textArea.Caret.Offset;
                caretLinePosition = caretPosition - line.Offset;
            });

            var lineParts = lineText.Substring(0, caretLinePosition).Split('|');

            if (IsCodeCompletionTrigger(ch) || CompletionUtils.IsCommand(lineParts[lineParts.Length - 1]))
            {
                TriggerCompletion();<commit_msg>changed code completion trigger<commit_after>﻿using Caliburn.Micro;
using ICSharpCode.AvalonEdit.CodeCompletion;
using ICSharpCode.AvalonEdit.Editing;
using SMAStudiovNext.Core;
using SMAStudiovNext.Modules.Runbook.Editor.Completion;
using SMAStudiovNext.Modules.WindowRunbook.Editor.Completion;
using System.Linq;
using System.Management.Automation.Language;
using System.Threading;
using System.Threading.Tasks;
using System.Windows.Input;

namespace SMAStudiovNext.Modules.Runbook.Editor
{
    public class KeystrokeService
    {
        private readonly ICompletionProvider _completionProvider;
        private readonly TextArea _textArea;

        private CompletionWindow _completionWindow = null;
        private long _triggerTag;
        private bool _openedByControlSpace = false;

        public KeystrokeService(TextArea textArea, ICompletionProvider completionProvider)
        {
            _completionProvider = completionProvider;
            _completionProvider.OnCompletionCompleted += OnCompletionResultRetrieved;

            _textArea = textArea;
            _textArea.KeyUp += OnKeyReleased;
            _textArea.TextEntered += OnTextEntered;
        }

        #region Event Handlers
        private void OnTextEntered(object sender, TextCompositionEventArgs e)
        {
            var ch = e.Text[0];
            var lineText = string.Empty;
            var caretPosition = -1;
            var caretLinePosition = -1;

            Execute.OnUIThread(() =>
            {
                var line = _textArea.Document.GetLineByOffset(_textArea.Caret.Offset);
                lineText = _textArea.Document.GetText(line);
                caretPosition = _textArea.Caret.Offset;
                caretLinePosition = caretPosition - line.Offset;
            });

            var lineParts = lineText.Substring(0, caretLinePosition).Split('|');

            if (IsCodeCompletionTrigger(ch))// || CompletionUtils.IsCommand(lineParts[lineParts.Length - 1]))
            {
                TriggerCompletion();
{'fraction_non_alphanumeric': 0.07573876334740502, 'fraction_numerical': 0.0024832381425378696, 'mean_word_length': 2.695412844036697, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7659230', 'n_tokens_mistral': 1089, 'n_tokens_neox': 1036, 'n_words': 206}