public void AugmentCompletionSession(Microsoft.VisualStudio.Language.Intellisense.ICompletionSession session, IList <Microsoft.VisualStudio.Language.Intellisense.CompletionSet> completionSets) { TextExtent extent; var trackSpan = FindTokenSpanAtPosition(session.GetTriggerPoint(textBuffer), session, out extent); var textToComplete = extent.Span.Snapshot.GetText(extent.Span.Start.Position, extent.Span.Length); var textToCompleteLower = textToComplete.ToLower(); var completionList = CompletionCodeContainer.Instance.GetCompletionListForFile(textDocument.FilePath, textBuffer); var completionSet = new CompletionSet ( "Tokens", //the non-localized title of the tab "Tokens", //the display title of the tab trackSpan, completionList.Where(compl => { string complStr = ((string)compl.Properties[CompletionCodeContainer.lowerDisplayName]); if (complStr.Contains(textToCompleteLower) && complStr != textToCompleteLower) { return(true); } else { return(false); } }), null ); completionSets.Insert(0, completionSet); }
public void AugmentCompletionSession(Intel.ICompletionSession session, IList <Intel.CompletionSet> completionSets) { var position = session.GetTriggerPoint(_buffer).GetPoint(_buffer.CurrentSnapshot); var line = position.GetContainingLine(); if (line == null) { return; } var text = line.GetText(); var linePosition = position - line.Start; foreach (var source in completionSources) { var span = source.GetInvocationSpan(text, linePosition, position); if (span == null) { continue; } if (span.Value.Length == 0) { return; } var trackingSpan = _buffer.CurrentSnapshot.CreateTrackingSpan(span.Value.Start + line.Start, span.Value.Length, SpanTrackingMode.EdgeInclusive); completionSets.Add(new StringCompletionSet( source.GetType().Name, trackingSpan, source.GetEntries(text[span.Value.Start], session.TextView.Caret.Position.BufferPosition) )); } }
public int Exec(ref Guid pguidCmdGroup, uint nCmdID, uint nCmdexecopt, IntPtr pvaIn, IntPtr pvaOut) { if (pguidCmdGroup != VSConstants.VSStd2K || !IsValidTextBuffer()) { return(Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut)); } // This filter should only have do anything inside a string literal, or when opening a string literal. var classifications = GetCaretClassifications(); bool isInString = classifications.Contains(_standardClassifications.StringLiteral); bool isInComment = classifications.Contains(_standardClassifications.Comment); var command = (VSConstants.VSStd2KCmdID)nCmdID; if (!isInString && !isInComment) { if (command != VSConstants.VSStd2KCmdID.TYPECHAR) { return(Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut)); } char ch = GetTypeChar(pvaIn); if (ch != '"' && ch != '\'' && ch != '@') { return(Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut)); } } bool closedCompletion = false; bool handled = false; // 1. Pre-process switch (command) { case VSConstants.VSStd2KCmdID.TYPECHAR: char ch = GetTypeChar(pvaIn); if (ch == '"' || ch == '\'' && _currentSession != null) { // If the user commits a completion from a closing quote, do // not immediately re-open the completion window below. closedCompletion = _currentSession != null; // If the user typed a closing quote, remove any trailing semicolon to match if (_currentSession != null) { var s = _currentSession.SelectedCompletionSet.SelectionStatus; if (s.IsSelected && s.Completion.InsertionText.EndsWith(ch + ";", StringComparison.Ordinal)) { s.Completion.InsertionText = s.Completion.InsertionText.TrimEnd(';'); } } var c = Complete(force: false, dontAdvance: true); // If the completion inserted a quote, don't add another one handled = c != null && c.InsertionText.EndsWith(ch.ToString(), StringComparison.Ordinal); } else if (ch == '/') { var c = Complete(force: false, dontAdvance: true); // If the completion inserted a slash, don't add another one. handled = c != null && c.InsertionText.EndsWith("/", StringComparison.Ordinal); // We will re-open completion after handling the keypress, to // show completions for this folder. } else if (isInComment && ch == '@') { var c = Complete(force: false, dontAdvance: true); handled = c != null; // We will re-open completion after handling the keypress, to // show completions for this folder. } break; case VSConstants.VSStd2KCmdID.AUTOCOMPLETE: case VSConstants.VSStd2KCmdID.SHOWMEMBERLIST: case VSConstants.VSStd2KCmdID.COMPLETEWORD: // Never handle this command; we always want JSLS to try too. StartSession(); break; case VSConstants.VSStd2KCmdID.RETURN: handled = Complete(false) != null; break; case VSConstants.VSStd2KCmdID.TAB: handled = Complete(true) != null; break; case VSConstants.VSStd2KCmdID.CANCEL: handled = Cancel(); break; } int hresult = VSConstants.S_OK; if (!handled) { hresult = Next.Exec(pguidCmdGroup, nCmdID, nCmdexecopt, pvaIn, pvaOut); } if (!ErrorHandler.Succeeded(hresult)) { return(hresult); } switch (command) { case VSConstants.VSStd2KCmdID.TYPECHAR: char ch = GetTypeChar(pvaIn); if (ch == ':' || ch == ' ') { Cancel(); } else if (ch == '"' || ch == '\'' || ch == '/' || ch == '.' || ch == '@' || (!char.IsPunctuation(ch) && !char.IsControl(ch))) { if (!closedCompletion) { StartSession(); } } else if (_currentSession != null) { Filter(); } break; case VSConstants.VSStd2KCmdID.DELETE: case VSConstants.VSStd2KCmdID.DELETEWORDLEFT: case VSConstants.VSStd2KCmdID.DELETEWORDRIGHT: case VSConstants.VSStd2KCmdID.BACKSPACE: if (_currentSession == null) { StartSession(); } else { var p = _currentSession.GetTriggerPoint(TextView.TextBuffer.CurrentSnapshot); if (p != null && (p.Value.Position >= p.Value.Snapshot.Length || p.Value.GetChar() != _currentSession.CompletionSets[0].Completions[0].InsertionText[0]) ) { Cancel(); } } Filter(); break; } return(hresult); }