public void SubjectBuffersConnected( ITextView textView, ConnectionReason reason, IReadOnlyCollection <ITextBuffer> subjectBuffers) { IntellisenseManager manager = textView.Properties.GetOrCreateSingletonProperty( delegate { return(new IntellisenseManager(this, textView)); }); // Create the appropriate Intellisense controllers for the content types in the buffer graph. It's important that we do // this after creating the brokers, as the controllers will most likely start using the brokers immediately. for (int f = 0; f < this.IntellisenseControllerFactories.Count; ++f) { var factory = this.IntellisenseControllerFactories[f]; // filter subject buffers to get the ones that match the factory content types FrugalList <ITextBuffer> matchingSubjectBuffers = new FrugalList <ITextBuffer>(); foreach (string factoryContentType in factory.Metadata.ContentTypes) { foreach (ITextBuffer subjectBuffer in subjectBuffers) { if (subjectBuffer.ContentType.IsOfType(factoryContentType) && !matchingSubjectBuffers.Contains(subjectBuffer)) { matchingSubjectBuffers.Add(subjectBuffer); } } } if (matchingSubjectBuffers.Count > 0) { // This controller factory is registered for the content type we understand. Go ahead and create // one. Note that this won't give us a handle to a controller object. We wouldn't be able to do anything // with such a reference anyway. if (manager.Controllers[f] == null) { manager.Controllers[f] = this.GuardedOperations.InstantiateExtension (factory, factory, provider => provider.TryCreateIntellisenseController(textView, matchingSubjectBuffers)); } else { foreach (ITextBuffer matchingSubjectBuffer in matchingSubjectBuffers) { manager.Controllers[f].ConnectSubjectBuffer(matchingSubjectBuffer); } } } } }
public IEnumerable <ITextBuffer> ResolveBuffersForCommand <TArgs>() where TArgs : EditorCommandArgs { var sourceSnapshotPoints = new FrugalList <SnapshotPoint>(new[] { _textView.Caret.Position.BufferPosition }); var resolvedBuffers = new FrugalList <ITextBuffer>(); for (int i = 0; i < sourceSnapshotPoints.Count; i++) { SnapshotPoint curSnapshotPoint = sourceSnapshotPoints[i]; if (curSnapshotPoint.Snapshot is IProjectionSnapshot curProjectionSnapshot) { sourceSnapshotPoints.AddRange(curProjectionSnapshot.MapToSourceSnapshots(curSnapshotPoint)); } // As the set of buffers isn't likely to exceed 5, just use the list to determine whether we've seen it before ITextBuffer curBuffer = curSnapshotPoint.Snapshot.TextBuffer; if (!resolvedBuffers.Contains(curBuffer)) { resolvedBuffers.Add(curBuffer); } } return(resolvedBuffers); }