Пример #1
0
        /// <summary>
        /// Gets the current selection or the word at the caret.
        /// </summary>
        public static Range GetCodeActionRange(this TextEditor editor)
        {
            if (editor.IsSomethingSelected)
            {
                return(new Range {
                    Start = editor.SelectionRegion.Begin.CreatePosition(),
                    End = editor.SelectionRegion.End.CreatePosition()
                });
            }

            // Use the word at the caret.
            WordAtPosition wordAtPosition = editor.GetWordAtCaret();

            if (!wordAtPosition.IsInvalid)
            {
                return(new Range {
                    Start = new Position {
                        Character = wordAtPosition.StartColumn - 1,
                        Line = editor.CaretLine - 1
                    },
                    End = new Position {
                        Character = wordAtPosition.EndColumn - 1,
                        Line = editor.CaretLine - 1
                    }
                });
            }

            // Just use the caret position as the range.
            return(new Range {
                Start = editor.CaretLocation.CreatePosition(),
                End = editor.CaretLocation.CreatePosition()
            });
        }
Пример #2
0
        string PromptForNewNameForRename()
        {
            WordAtPosition word = Editor.GetWordAtCaret();

            if (word.IsEmpty || word.IsInvalid)
            {
                return(null);
            }

            return(RenameItemDialog.PromptForNewName(word.Text));
        }
Пример #3
0
        bool ShouldTriggerCompletionOnCharTyped(
            WordAtPosition word,
            CodeCompletionContext completionContext,
            CompletionTriggerInfo triggerInfo)
        {
            if (session.IsCompletionTriggerCharacter(triggerInfo.TriggerCharacter))
            {
                return(true);
            }

            return(ShouldTriggerCompletionAtPosition(word, completionContext));
        }
Пример #4
0
        static bool ShouldTriggerCompletionAtPosition(
            WordAtPosition word,
            CodeCompletionContext completionContext)
        {
            if (word.IsEmpty)
            {
                // No word near caret - do not trigger code completion.
                return(false);
            }
            else if (word.EndColumn != completionContext.TriggerLineOffset)
            {
                // Not at the end of the word. For example, a space was typed after
                // the end of the word
                return(false);
            }

            return(true);
        }
Пример #5
0
        bool ShouldTriggerCompletion(
            WordAtPosition word,
            CodeCompletionContext completionContext,
            CompletionTriggerInfo triggerInfo)
        {
            switch (triggerInfo.CompletionTriggerReason)
            {
            case CompletionTriggerReason.CharTyped:
                return(ShouldTriggerCompletionOnCharTyped(word, completionContext, triggerInfo));

            case CompletionTriggerReason.BackspaceOrDeleteCommand:
                return(ShouldTriggerCompletionAtPosition(word, completionContext));

            default:
                // Always trigger when Ctrl+Space typed.
                return(true);
            }
        }
Пример #6
0
        public async override Task <ICompletionDataList> HandleCodeCompletionAsync(
            CodeCompletionContext completionContext,
            CompletionTriggerInfo triggerInfo,
            CancellationToken token = default(CancellationToken))
        {
            if (Editor.EditMode == EditMode.TextLink)
            {
                return(null);
            }

            if (!session.IsCompletionProvider)
            {
                return(null);
            }

            try {
                WordAtPosition word = Editor.GetWordAtPosition(completionContext);

                if (!ShouldTriggerCompletion(word, completionContext, triggerInfo))
                {
                    return(null);
                }

                var completionList = await session.GetCompletionList(fileName, completionContext, this, token);

                if (!word.IsEmpty)
                {
                    completionList.TriggerWordLength    = word.Length;
                    completionContext.TriggerLineOffset = word.StartColumn;
                }

                return(completionList);
            } catch (OperationCanceledException) {
                // Ignore.
            } catch (Exception ex) {
                LanguageClientLoggingService.LogError("HandleCodeCompletionAsync error.", ex);
            }

            return(null);
        }
Пример #7
0
        bool IsWordAtCurrentCaretPosition()
        {
            WordAtPosition word = Editor.GetWordAtCaret();

            return(word.IsEmpty);
        }