Example #1
0
 private void CloseCodeCompletionWindow(object sender, EventArgs e)
 {
     _codeCompletionWindow = null;
 }
Example #2
0
        private void ShowIntellisense(char keyValue, int wordLengthLimit)
        {
            if (_completionDataProvider == null)
            {
                return;
            }
            if (ActiveTextAreaControl.SelectionManager.HasSomethingSelected)
            {
                return;
            }

            var caretPosition = ActiveTextAreaControl.Caret;
            var line          = Document.GetLineSegment(caretPosition.Line);
            var word          = line.GetWord(caretPosition.Column - 1);

            var wordType = (word as AsmWord)?.WordType;

            if (wordType == AsmWord.AsmWordType.Comment)
            {
                if (_codeCompletionWindow != null)
                {
                    _codeCompletionWindow.Close();
                }
                return;
            }
            if (wordType == AsmWord.AsmWordType.Opcode && wordLengthLimit > 0 && !_forcedAutoCompleteWindow)
            {
                if (_codeCompletionWindow != null)
                {
                    _codeCompletionWindow.Close();
                }
                return;
            }
            if ((wordType == AsmWord.AsmWordType.NumberByte || wordType == AsmWord.AsmWordType.NumberWord) && wordLengthLimit > 0 && !_forcedAutoCompleteWindow)
            {
                if (_codeCompletionWindow != null)
                {
                    _codeCompletionWindow.Close();
                }
                return;
            }

            if (word.Word.Trim().Length < wordLengthLimit)
            {
                if ((word.IsWhiteSpace || string.IsNullOrWhiteSpace(word.Word)) && !_forcedAutoCompleteWindow && _codeCompletionWindow != null)
                {
                    _codeCompletionWindow.Close();
                }
                return;
            }
            var provider = _completionDataProvider;

            if (IsIncludeLine(line) && caretPosition.Column > 0)
            {
                // Auto-complete file names for include statements
                var fullLine    = Document.GetText(line);
                var stringStart = fullLine.LastIndexOf("\"", caretPosition.Column - 1);
                if (stringStart > 0 && stringStart == fullLine.IndexOf("\""))
                {
                    // Open file completion if caret is after the first " of the line
                    provider = _fileCompletionDataProvider;
                    provider.PreSelection = fullLine.Substring(stringStart, caretPosition.Column - stringStart);
                }
            }
            if (provider == _completionDataProvider)
            {
                // Regular auto-complete for symbols
                if (word.Offset + word.Length != caretPosition.Column)
                {
                    if (_codeCompletionWindow != null)
                    {
                        _codeCompletionWindow.Close();
                    }
                    return;
                }
                provider.PreSelection = word.Word;
            }

            if (_codeCompletionWindow != null)
            {
                _codeCompletionWindow.RefreshCompletionData(File.File.FullName, keyValue);
                return;
            }

            try
            {
                _codeCompletionWindow = CompletionWindow.ShowCompletionWindow(
                    ParentForm,                                                 // The parent window for the completion window
                    this,                                                       // The text editor to show the window for
                    File.File.FullName,                                         // Filename - will be passed back to the provider
                    provider,                                                   // Provider to get the list of possible completions
                    keyValue                                                    // Key pressed - will be passed to the provider
                    );
            }
            catch (ArgumentOutOfRangeException)
            {
                _codeCompletionWindow = null;
            }
            if (_codeCompletionWindow != null)             // ShowCompletionWindow can return null when the provider returns an empty list
            {
                _codeCompletionWindow.CloseWhenCaretAtBeginning = false;
                _codeCompletionWindow.Closed += CloseCodeCompletionWindow;
            }
        }