diff --git a/CodeiumVS/SuggestionUI/SuggestionTagger.cs b/CodeiumVS/SuggestionUI/SuggestionTagger.cs index 98abefc..54abd9c 100644 --- a/CodeiumVS/SuggestionUI/SuggestionTagger.cs +++ b/CodeiumVS/SuggestionUI/SuggestionTagger.cs @@ -248,10 +248,6 @@ void AddInsertionTextBlock(int start, int end, string line) if (line.Length <= suggestionIndex) return; string remainder = line.Substring(start, end - start); - - ITextSnapshotLine snapshotLine = view.TextSnapshot.GetLineFromLineNumber(currentTextLineN); - var lineFormat = view.TextViewLines.GetCharacterBounds(snapshotLine.Start); - var textBlock = CreateTextBox(remainder, greyBrush); GetTagger().UpdateAdornment(textBlock); } diff --git a/CodeiumVS/SuggestionUI/TextViewListener.cs b/CodeiumVS/SuggestionUI/TextViewListener.cs index b1ef2a6..f352b30 100644 --- a/CodeiumVS/SuggestionUI/TextViewListener.cs +++ b/CodeiumVS/SuggestionUI/TextViewListener.cs @@ -71,7 +71,7 @@ public async void GetCompletion() await package.LogAsync( $"RequestProposalsAsync - Language: {_language.Name}; Caret: {caretPosition}; ASCII: {_document.Encoding.IsSingleByte}"); - string text = _view.TextSnapshot.GetText(); + string text = _document.TextBuffer.CurrentSnapshot.GetText(); int cursorPosition = _document.Encoding.IsSingleByte ? caretPosition : Utf16OffsetToUtf8Offset(text, caretPosition); @@ -159,6 +159,20 @@ List> ParseCompletion(IList comple completionText = completionText.Substring(offset); string completionID = completionItem.completion.completionId; var set = new Tuple(completionText, completionID); + + // Filter out completions that don't match the current intellisense prefix + ICompletionSession session = m_provider.CompletionBroker.GetSessions(_view).FirstOrDefault(); + if (session != null && session.SelectedCompletionSet != null) + { + string intellisenseSuggestion = session.SelectedCompletionSet.SelectionStatus.Completion.InsertionText; + ITrackingSpan intellisenseSpan = session.SelectedCompletionSet.ApplicableTo; + SnapshotSpan span = intellisenseSpan.GetSpan(intellisenseSpan.TextBuffer.CurrentSnapshot); + string intellisenseInsertion = intellisenseSuggestion.Substring(span.Length); + if (!completionText.StartsWith(intellisenseInsertion)) + { + continue; + } + } list.Add(set); } @@ -220,7 +234,7 @@ internal CodeiumCompletionHandler(IVsTextView textViewAdapter, ITextView view, _textViewAdapter = textViewAdapter; // add the command to the command chain textViewAdapter.AddCommandFilter(this, out m_nextCommandHandler); - ShowIntellicodeMsg(); + // ShowIntellicodeMsg(); } private void OnContentTypeChanged(object sender, ContentTypeChangedEventArgs e) @@ -315,6 +329,7 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv } // check for a commit character + bool regenerateSuggestion = false; if (!hasCompletionUpdated && nCmdID == (uint)VSConstants.VSStd2KCmdID.TAB) { @@ -322,11 +337,21 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv if (tagger != null) { - if (tagger.IsSuggestionActive() && tagger.CompleteText()) + if (tagger.IsSuggestionActive()) { - ClearCompletionSessions(); - OnSuggestionAccepted(currentCompletionID); - return VSConstants.S_OK; + // If there is an active Intellisense session, let that one get accepted first. + ICompletionSession session = m_provider.CompletionBroker.GetSessions(_view).FirstOrDefault(); + if (session != null && session.SelectedCompletionSet != null) + { + tagger.ClearSuggestion(); + regenerateSuggestion = true; + } + if (tagger.CompleteText()) + { + ClearCompletionSessions(); + OnSuggestionAccepted(currentCompletionID); + return VSConstants.S_OK; + } } else { tagger.ClearSuggestion(); } } @@ -357,7 +382,7 @@ public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pv if (hasCompletionUpdated) { ClearSuggestion(); } // gets lsp completions on added character or deletions - if (!typedChar.Equals(char.MinValue) || commandID == (uint)VSConstants.VSStd2KCmdID.RETURN) + if (!typedChar.Equals(char.MinValue) || commandID == (uint)VSConstants.VSStd2KCmdID.RETURN || regenerateSuggestion) { _ = Task.Run(() => GetCompletion()); handled = true; diff --git a/CodeiumVS/Windows/ChatToolWindow.cs b/CodeiumVS/Windows/ChatToolWindow.cs index 0d0769c..800e872 100644 --- a/CodeiumVS/Windows/ChatToolWindow.cs +++ b/CodeiumVS/Windows/ChatToolWindow.cs @@ -152,6 +152,7 @@ public async Task ReloadAsync() { "app_name", "Visual Studio" }, { "web_server_url", serverUrl }, { "has_dev_extension", "false" }, + { "has_index_service", "true" }, { "open_file_pointer_enabled", "true" }, { "diff_view_enabled", "true" }, { "insert_at_cursor_enabled", "true" },