public ContextManager(IContextBuilder contextBuilder, IRepositoryManager repositoryManager, ITagger tagger, IBagOfWords bagOfWords) { this.contextBuilder = contextBuilder; this.repositoryManager = repositoryManager; this.tagger = tagger; this.bagOfWords = bagOfWords; }
public void SetUp() { _factory = new MockRepository(MockBehavior.Loose); _mode = _factory.Create<ISubstituteConfirmMode>(); _textBuffer = EditorUtil.CreateBuffer("cat", "dog", "bird", "tree"); _taggerRaw = new SubstituteConfirmTagger(_textBuffer, _mode.Object); _tagger = _taggerRaw; }
public void Create(params string[] lines) { _textView = EditorUtil.CreateView(lines); _buffer = EditorUtil.FactoryService.Vim.CreateBuffer(_textView); _search = _buffer.IncrementalSearch; _taggerRaw = new IncrementalSearchTagger(_buffer); _tagger = _taggerRaw; }
internal bool IsInterested(ITextView textView, out ITagger<ITag> tagger) { if (!_isResharperInstalled) { tagger = null; return false; } return TryGetResharperTagger(textView.TextBuffer, out tagger); }
public RenameTrackingTestState( string markup, string languageName, bool onBeforeGlobalSymbolRenamedReturnValue = true, bool onAfterGlobalSymbolRenamedReturnValue = true) { this.Workspace = CreateTestWorkspace(markup, languageName, TestExportProvider.CreateExportProviderWithCSharpAndVisualBasic()); _hostDocument = Workspace.Documents.First(); _view = _hostDocument.GetTextView(); _view.Caret.MoveTo(new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value)); _editorOperations = Workspace.GetService<IEditorOperationsFactoryService>().GetEditorOperations(_view); _historyRegistry = Workspace.ExportProvider.GetExport<ITextUndoHistoryRegistry>().Value; _mockRefactorNotifyService = new MockRefactorNotifyService { OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue, OnAfterSymbolRenamedReturnValue = onAfterGlobalSymbolRenamedReturnValue }; var optionService = this.Workspace.Services.GetService<IOptionService>(); // Mock the action taken by the workspace INotificationService var notificationService = Workspace.Services.GetService<INotificationService>() as INotificationServiceCallback; var callback = new Action<string, string, NotificationSeverity>((message, title, severity) => _notificationMessage = message); notificationService.NotificationCallback = callback; var tracker = new RenameTrackingTaggerProvider( _historyRegistry, Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value, Workspace.ExportProvider.GetExport<IInlineRenameService>().Value, Workspace.ExportProvider.GetExport<IDiagnosticAnalyzerService>().Value, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService), Workspace.ExportProvider.GetExports<IAsynchronousOperationListener, FeatureMetadata>()); _tagger = tracker.CreateTagger<RenameTrackingTag>(_hostDocument.GetTextBuffer()); if (languageName == LanguageNames.CSharp) { _codeFixProvider = new CSharpRenameTrackingCodeFixProvider( Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value, _historyRegistry, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)); } else if (languageName == LanguageNames.VisualBasic) { _codeFixProvider = new VisualBasicRenameTrackingCodeFixProvider( Workspace.ExportProvider.GetExport<Host.IWaitIndicator>().Value, _historyRegistry, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)); } else { throw new ArgumentException("Invalid langauge name: " + languageName, "languageName"); } }
public RenameTrackingTestState( TestWorkspace workspace, string languageName, bool onBeforeGlobalSymbolRenamedReturnValue = true, bool onAfterGlobalSymbolRenamedReturnValue = true) { this.Workspace = workspace; _hostDocument = Workspace.Documents.First(); _view = _hostDocument.GetTextView(); _view.Caret.MoveTo(new SnapshotPoint(_view.TextSnapshot, _hostDocument.CursorPosition.Value)); _editorOperations = Workspace.GetService <IEditorOperationsFactoryService>().GetEditorOperations(_view); _historyRegistry = Workspace.ExportProvider.GetExport <ITextUndoHistoryRegistry>().Value; _mockRefactorNotifyService = new MockRefactorNotifyService { OnBeforeSymbolRenamedReturnValue = onBeforeGlobalSymbolRenamedReturnValue, OnAfterSymbolRenamedReturnValue = onAfterGlobalSymbolRenamedReturnValue }; // Mock the action taken by the workspace INotificationService var notificationService = Workspace.Services.GetService <INotificationService>() as INotificationServiceCallback; var callback = new Action <string, string, NotificationSeverity>((message, title, severity) => _notificationMessage = message); notificationService.NotificationCallback = callback; var tracker = new RenameTrackingTaggerProvider( Workspace.ExportProvider.GetExportedValue <IThreadingContext>(), _historyRegistry, Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value, Workspace.ExportProvider.GetExport <IInlineRenameService>().Value, Workspace.ExportProvider.GetExport <IDiagnosticAnalyzerService>().Value, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService), Workspace.ExportProvider.GetExportedValue <IAsynchronousOperationListenerProvider>()); _tagger = tracker.CreateTagger <RenameTrackingTag>(_hostDocument.GetTextBuffer()); if (languageName == LanguageNames.CSharp) { _codeFixProvider = new CSharpRenameTrackingCodeFixProvider( Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value, _historyRegistry, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)); } else if (languageName == LanguageNames.VisualBasic) { _codeFixProvider = new VisualBasicRenameTrackingCodeFixProvider( Workspace.ExportProvider.GetExport <Host.IWaitIndicator>().Value, _historyRegistry, SpecializedCollections.SingletonEnumerable(_mockRefactorNotifyService)); } else { throw new ArgumentException("Invalid language name: " + languageName, nameof(languageName)); } }
public void Create(params string[] lines) { _textView = EditorUtil.CreateView(lines); _buffer = EditorUtil.FactoryService.Vim.CreateBuffer(_textView); _globalSettings = _buffer.Settings.GlobalSettings; _globalSettings.IncrementalSearch = true; _globalSettings.WrapScan = true; _search = _buffer.IncrementalSearch; _taggerRaw = new IncrementalSearchTagger(_buffer); _tagger = _taggerRaw; }
public void NoopTagger() { ITagger noopTagger = NoopTags.NoopTagger; Assert.Same(NoopTags.NoopTagContext, noopTagger.Empty); Assert.Same(NoopTags.NoopTagContext, noopTagger.CurrentTagContext); Assert.Same(NoopTags.NoopTagContextBuilder, noopTagger.EmptyBuilder); Assert.Same(NoopTags.NoopTagContextBuilder, noopTagger.ToBuilder(TAG_CONTEXT)); Assert.Same(NoopTags.NoopTagContextBuilder, noopTagger.CurrentBuilder); Assert.Same(NoopScope.Instance, noopTagger.WithTagContext(TAG_CONTEXT)); }
internal NameParser( ITagger tagger, IModelLoader modelLoader, IFormatter <Name> formatter, IIndividualChecker individualChecker) { Tagger = tagger; HMM = modelLoader.LoadHMM(); Formatter = formatter; IndividualChecker = individualChecker; }
public void Create(params string[] lines) { _textView = EditorUtil.CreateTextView(lines); _buffer = EditorUtil.FactoryService.Vim.CreateBuffer(_textView); _globalSettings = _buffer.LocalSettings.GlobalSettings; _globalSettings.IncrementalSearch = true; _globalSettings.WrapScan = true; _search = _buffer.IncrementalSearch; _taggerRaw = new IncrementalSearchTagger(_buffer); _tagger = _taggerRaw; }
public static Dictionary <string, object[]> Tag(string tagName, Sentence sentence) { if (!IsTagRegistered(sentence.Locale, tagName)) { throw new InvalidOperationException("No tagger is registered for tag-name: " + tagName); } ITagger tagger = s_taggers[sentence.Locale][tagName.ToLower()]; return(tagger.Tag(sentence)); }
public ViewManagerTest() { clock = TestClock.Create(); statsComponent = new StatsComponent(new SimpleEventQueue(), clock); tagsComponent = new TagsComponent(); tagger = tagsComponent.Tagger; viewManager = statsComponent.ViewManager; statsRecorder = statsComponent.StatsRecorder; }
private void Create(params string[] lines) { _textBuffer = CreateTextBuffer(lines); // Setup a sychronization context we can control _synchronizationContext = new TestableSynchronizationContext(); _synchronizationContext.Install(); _asyncTaggerSource = new TestableAsyncTaggerSource(_textBuffer); _asyncTagger = new AsyncTagger <string, TextMarkerTag>(_asyncTaggerSource); _asyncTaggerInterface = _asyncTagger; }
public ITagger GetTagger(string name) { List <Type> types = new List <Type>(); types.AddRange(Assembly.Load(new AssemblyName("CherubNLP")) .GetTypes().Where(x => !x.IsAbstract && !x.FullName.StartsWith("<>f__AnonymousType")).ToList()); Type type = types.FirstOrDefault(x => x.Name == name); var instance = (ITagger)Activator.CreateInstance(type); return(_tagger = instance); }
internal IClassificationTypeRegistryService ClassificationRegistry = null; // Set via MEF public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag { //create a single tagger for each buffer. if (!factory.IsXSharpDocument(buffer)) { return(null); } ITagger <T> outliner = buffer.Properties.GetOrCreateSingletonProperty <ITagger <T> >( () => new XSharpOutliningTagger(buffer, aggregator, ClassificationRegistry) as ITagger <T>); return(outliner); }
internal void AddTaggers(ITextBuffer textBuffer, IList <ITagger <T> > newTaggers) { var bufferTaggerFactories = this.TagAggregatorFactoryService.GuardedOperations.FindEligibleFactories(this.TagAggregatorFactoryService.GetBufferTaggersForType(textBuffer.ContentType, typeof(T)), textBuffer.ContentType, this.TagAggregatorFactoryService.ContentTypeRegistryService); foreach (var factory in bufferTaggerFactories) { ITaggerProvider provider = null; ITagger <T> tagger = null; try { provider = factory.Value; tagger = provider.CreateTagger <T>(textBuffer); } catch (Exception e) { object errorSource = (provider != null) ? (object)provider : factory; this.TagAggregatorFactoryService.GuardedOperations.HandleException(errorSource, e); } this.RegisterTagger(tagger, newTaggers); } if (this.textView != null) { var viewTaggerFactories = this.TagAggregatorFactoryService.GuardedOperations.FindEligibleFactories(this.TagAggregatorFactoryService.GetViewTaggersForType(textBuffer.ContentType, typeof(T)).Where(f => (f.Metadata.TextViewRoles == null) || this.textView.Roles.ContainsAny(f.Metadata.TextViewRoles)), textBuffer.ContentType, this.TagAggregatorFactoryService.ContentTypeRegistryService); foreach (var factory in viewTaggerFactories) { IViewTaggerProvider provider = null; ITagger <T> tagger = null; try { provider = factory.Value; tagger = provider.CreateTagger <T>(this.textView, textBuffer); } catch (Exception e) { object errorSource = (provider != null) ? (object)provider : factory; this.TagAggregatorFactoryService.GuardedOperations.HandleException(errorSource, e); } this.RegisterTagger(tagger, newTaggers); } } }
public void Dispose() { if (this._tagger != null) { this._tagger.TagsChanged -= new EventHandler <SnapshotSpanEventArgs>(this.OnTagsChanged); //this._tagger.Release(); if (this._tagger is IDisposable) { (this._tagger as IDisposable).Dispose(); } this._tagger = null; } }
/// <summary> /// Create a tagger that does error checking on the view/buffer combination. /// </summary> public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag { ITagger <T> tagger = null; // Only attempt to spell check on the view's edit buffer (and multiple views could have that buffer open simultaneously so // only create one instance of the spell checker. if ((buffer == textView.TextBuffer) && (typeof(T) == typeof(IErrorTag))) { ErrorHighLightChecker errorChecker = buffer.Properties.GetOrCreateSingletonProperty(typeof(ErrorHighLightChecker), () => new ErrorHighLightChecker(this, textView, buffer)); tagger = new ErrorHighLightTagger(errorChecker) as ITagger <T>; } return(tagger); }
public JadeTokenizer(JadeClassifierProvider provider) { this.CComments = false; this.MultilineCppComments = true; if (provider != null && provider.JsTaggerProvider != null) { this._jsBuffer = provider.BufferFactoryService.CreateTextBuffer(provider.JsContentType); this._jsTagger = provider.JsTaggerProvider.CreateTagger <ClassificationTag>(this._jsBuffer); } if (provider != null && provider.CssClassifierProvider != null) { this._cssBuffer = provider.BufferFactoryService.CreateTextBuffer(provider.CssContentType); this._cssClassifier = provider.CssClassifierProvider.GetClassifier(this._cssBuffer); } }
async Task InitializeAsync(ITextBuffer buffer, ITagger <IClassificationTag> tagger, IRoslynDocumentationProviderFactory docFactory) { ProfileOptimizationHelper.StartProfile("startup-roslyn"); var refs = new MetadataReference[] { CreateMetadataReference(typeof(int).Assembly, docFactory), }; await InitializeAsync(buffer, csharpCode, refs, LanguageNames.CSharp, tagger, new CSharpCompilationOptions(OutputKind.DynamicallyLinkedLibrary, allowUnsafe : true), new CSharpParseOptions()); await InitializeAsync(buffer, visualBasicCode, refs, LanguageNames.VisualBasic, tagger, new VisualBasicCompilationOptions(OutputKind.DynamicallyLinkedLibrary), new VisualBasicParseOptions()); // The tagger is async, give it a few secs before disposing it await Task.Delay(2000); (tagger as IDisposable)?.Dispose(); }
public ITagger <TTagType> CreateTagger(ITextBuffer buffer) { if (taggerAdapters.Count == 0) { Singleton = createTagger(buffer); Debug.WriteLine($"SLVS SingletonDisposableTaggerManager ({this.GetHashCode()}): Created new singleton tagger: {Singleton.GetType().Name}"); } var tagger = new FlyweightTaggerWrapper(Singleton, RemoveTagger); taggerAdapters.Add(tagger); Debug.WriteLine($"SLVS SingletonDisposableTaggerManager ({this.GetHashCode()}): Created new flyweight tagger. New count: {taggerAdapters.Count}. Singleton: {Singleton.GetType().Name}, hash code: {Singleton.GetHashCode()}"); return(tagger); }
private void RemoveTagger(ITagger <TTagType> tagger) { taggerAdapters.Remove(tagger); Debug.WriteLine($"SLVS SingletonDisposableTaggerManager ({this.GetHashCode()}): Flyweight tagger removed. Remaining count: {taggerAdapters.Count}. Singleton: {Singleton.GetType().Name}, hash code: {Singleton.GetHashCode()}"); if (taggerAdapters.Count == 0) { if (Singleton is IDisposable disposable) { Debug.WriteLine($"SLVS SingletonDisposableTaggerManager ({this.GetHashCode()}): Disposed singleton tagger: {Singleton.GetType().Name}"); disposable.Dispose(); } Singleton = null; } }
public MediaImporter(ILogger logger, IMediaFactory mediaFactory, IEntityRepository repository, ITagger tagger) { if (logger == null) throw new ArgumentNullException("logger"); if (mediaFactory == null) throw new ArgumentNullException("mediaFactory"); if (repository == null) throw new ArgumentNullException("repository"); if (tagger == null) throw new ArgumentNullException("tagger"); this.logger = logger; this.mediaFactory = mediaFactory; this.repository = repository; this.tagger = tagger; }
public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag { ITagger <T> tagger = null; // Only attempt to spell check on the view's edit buffer (and multiple views could have that buffer open simultaneously so // only create one instance of the spell checker. if ((buffer == textView.TextBuffer) && (typeof(T) == typeof(IErrorTag))) { var filePath = GetFileNameFor(buffer); if (filePath != null) { tagger = new MessageTagger(filePath, this, buffer) as ITagger <T>; } } return(tagger); }
public ITagger <T> CreateTagger <T>(ITextBuffer buffer) where T : ITag { ITagger <T> result = null; try { //AntlrLanguagePackage package = AntlrLanguagePackage.Instance; VSColorTheme.ThemeChanged += UpdateTheme; result = buffer.Properties.GetOrCreateSingletonProperty(() => new AntlrClassifier(buffer)) as ITagger <T>; AntlrClassifier classifier = result as AntlrClassifier; classifier.Initialize(ClassificationTypeRegistry, ClassificationFormatMapService); } catch (Exception) { } return(result); }
/// <summary> /// Create a tagger that does lint checking on the view/buffer combination. /// </summary> public ITagger <T> CreateTagger <T>(ITextView textView, ITextBuffer buffer) where T : ITag { ITagger <T> tagger = null; // Only attempt to lint check on the view's edit buffer (and multiple views could have that buffer open simultaneously so // only create one instance of the lint checker. if ((buffer == textView.TextBuffer) && (typeof(T) == typeof(IErrorTag))) { var lintChecker = buffer.Properties.GetOrCreateSingletonProperty(typeof(LintChecker), () => new LintChecker(this, textView, buffer)); // This is a thin wrapper around the LintChecker that can be disposed of without shutting down the LintChecker // (unless it was the last tagger on the lint checker). tagger = new LintTagger(lintChecker) as ITagger <T>; } return(tagger); }
private void Create(params string[] lines) { lines = lines.Length > 0 ? lines : DefaultText; _textBuffer = EditorUtil.CreateBuffer(lines); _globalSettings = new GlobalSettings(); _globalSettings.IgnoreCase = true; _globalSettings.HighlightSearch = true; _vimData = new VimData(); _searchService = VimUtil.CreateSearchService(); _taggerRaw = new HighlightIncrementalSearchTagger( _textBuffer, _globalSettings, VimUtil.CreateTextStructureNavigator(_textBuffer, WordKind.NormalWord), _searchService, _vimData); _tagger = _taggerRaw; }
public TextViewCaretListener(ITextView textView, ITagger <T> tagger) { this.tagger = tagger; this.textView = textView; this.textView.Closed += this.TextView_Closed; this.textView.LayoutChanged += this.TextView_LayoutChanged; this.textView.Caret.PositionChanged += this.Caret_PositionChanged; this.textView.GotAggregateFocus += this.TextView_GotAggregateFocus; this.textView.LostAggregateFocus += this.TextView_LostAggregateFocus; // Send an update of the initial caret position for this text view. // This allows the SARIF explorer to properly receive the caret // entered notifications for a newly created text view. // This allows the SARIF explorer to proper set selection to items // on initial load. _ = ThreadHelper.JoinableTaskFactory.RunAsync(() => this.UpdateInitialCaretPositionAsync()); }
private void RegisterTagger(ITagger <T> tagger, IList <ITagger <T> > newTaggers) { if (tagger != null) { newTaggers.Add(tagger); if (!this.uniqueTaggers.TryGetValue(tagger, out var count)) { count = new BoxedInt(); this.uniqueTaggers.Add(tagger, count); // We only want to subscribe once to the tags changed event // (even if we get multiple instances of the same tagger). tagger.TagsChanged += SourceTaggerTagsChanged; } ++(count.Value); } }
/// <inheritdoc/> public void CreateListener(ITextView textView, ITagger <T> tagger) { using (this.existingListenersLock.EnterUpgradeableReadLock()) { if (this.existingListeners.ContainsKey(textView)) { return; } using (this.existingListenersLock.EnterWriteLock()) { var newTagger = new TextViewCaretListener <T>(textView, tagger); this.existingListeners.Add(textView, newTagger); newTagger.CaretEnteredTag += this.Tagger_CaretEnteredTag; newTagger.CaretLeftTag += this.Tagger_CaretLeftTag; textView.Closed += this.TextView_Closed; } } }
/// <summary> /// This method is to try to account for ReSharper versions that are not released at /// this time. Instead of looking for the version specific names we just look at the /// jet brains assembly that have the correct tagger name /// /// One problem here is that the tagger implementations are shared between a couple /// of JetBrains products including dotCover. Hence we need to keep in mind both the /// assembly and tagger name here /// </summary> private bool TryGetGeneralTagger(ITextBuffer textBuffer, out ITagger <ITag> tagger) { foreach (var provider in GetTaggerProvidersSafe()) { var providerType = provider.GetType(); if (providerType.Name == ResharperTaggerProviderName && providerType.Assembly.FullName.StartsWith("JetBrains", StringComparison.OrdinalIgnoreCase)) { var taggerResult = provider.SafeCreateTagger <ITag>(textBuffer); if (taggerResult.IsSuccess) { tagger = taggerResult.Value; return(true); } } } tagger = null; return(false); }
public GlslCompletionSource(ITextBuffer buffer, IEnumerable <Completion> staticCompletions, ImageSource identifier, ITagger <GlslTokenTag> tagger) { currentBuffer = buffer; this.staticCompletions = staticCompletions; imgIdentifier = identifier; queryIdentifiers = (snapshotSpan) => { var tokens = tagger.GetTags(new NormalizedSnapshotSpanCollection(snapshotSpan)); //only those tokens that are identifiers and do not overlap the input position because we do not want to add char that started session to completions var filtered = from token in tokens where token.Tag.Type == GlslTokenTypes.Identifier && !token.Span.Contains(snapshotSpan.End - 1) let text = token.Span.GetText() orderby text select text; return(filtered.Distinct()); }; }
private static void RegisterTagger(string locale, string tagName, ITagger tagger) { if (IsTagRegistered(locale, tagName)) { throw new Exception(String.Format("{0} and {1} taggers for locale \"{2}\" share common tag name {3}", tagger.GetType().Name, s_taggers[locale][tagName].GetType().Name, locale, tagName)); } locale = locale.ToLower(); tagName = tagName.ToLower(); if (!s_taggers.ContainsKey(locale)) { s_taggers.Add(locale, new Dictionary <string, ITagger>()); } s_taggers[locale].Add(tagName, tagger); }
static void Main(string[] args) { logger = Log4NetLogger.GetDefaultLogger(typeof(Program)); try { logger.Info("Ebla Started"); Console.WriteLine("Ebla version 3.0.0.0"); Console.WriteLine("Enter \"{0}\" for instructions", commandHelp); artistCache = new EntityCache<IArtist>(); workCache = new EntityCache<IWork>(); artistStore = new SQLiteArtistDatabase(); workStore = new SQLiteWorkDatabase(artistCache, workCache); repository = new EntityRepository(logger, artistCache, artistStore, workCache, workStore); repository.Initialize(); tagger = new Tagger(); mediaFactory = new MediaFactory(logger); mediaImporter = new MediaImporter(logger, mediaFactory, repository, tagger); var exit = false; while (!exit) { Console.Write(prompt); exit = Execute(Console.ReadLine()); } } catch (Exception ex) { logger.Error("Program.Main", ex); Console.WriteLine("ERROR"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ReadLine(); } }
static void Main(string[] args) { logger = Log4NetLogger.GetDefaultLogger(typeof(Program)); try { logger.Info("Ebla Started"); Console.WriteLine("Ebla version 3.0.0.0"); Console.WriteLine("Enter \"{0}\" for instructions", commandHelp); artistCache = new EntityCache <IArtist>(); workCache = new EntityCache <IWork>(); artistStore = new SQLiteArtistDatabase(); workStore = new SQLiteWorkDatabase(artistCache, workCache); repository = new EntityRepository(logger, artistCache, artistStore, workCache, workStore); repository.Initialize(); tagger = new Tagger(); mediaFactory = new MediaFactory(logger); mediaImporter = new MediaImporter(logger, mediaFactory, repository, tagger); var exit = false; while (!exit) { Console.Write(prompt); exit = Execute(Console.ReadLine()); } } catch (Exception ex) { logger.Error("Program.Main", ex); Console.WriteLine("ERROR"); Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); Console.ReadLine(); } }
protected ITagger <T> GetTagger <T>(ITextBuffer buffer, Func <string, ITagger <ITag> > getter) where T : ITag { var t = typeof(T).Name; ITextDocument textDocument; buffer.Properties.TryGetProperty(typeof(ITextDocument), out textDocument); var docName = textDocument.FilePath; ITagger <ITag> tagger = null; if (Dic[t].ContainsKey(docName)) { tagger = Dic[t][docName]; } else { tagger = getter(docName); Dic[t][docName] = tagger; } return(tagger as ITagger <T>); }
private void RegisterTagger(ITagger <T> tagger, IList <ITagger <T> > newTaggers) { if (tagger != null) { newTaggers.Add(tagger); int taggerIndex = this.uniqueTaggers.FindIndex((tuple) => object.ReferenceEquals(tuple.Item1, tagger)); // Only subscribe to the event if we've never seen this tagger before if (taggerIndex == -1) { tagger.TagsChanged += SourceTaggerTagsChanged; uniqueTaggers.Add(Tuple.Create(tagger, 1)); } else { // Increase the reference count for the existing tagger uniqueTaggers[taggerIndex] = Tuple.Create(tagger, uniqueTaggers[taggerIndex].Item2 + 1); } } }
/// <summary> /// The various JetBrains products reuse at a code base level certain constructs /// such as ITagger<T> implementations. For example both R# and dotTrace and /// dotCover use the VsDocumentMarkerTaggerProvider. If multiple products are /// installed then MEF composition will return them in a non-deterministic /// order. They all have the same fully qualified name. The only way to /// distinguish them is to look at the assembly name containing the type /// </summary> private bool TryGetSpecificTagger(ITextBuffer textBuffer, out bool sawName, out ITagger <ITag> tagger) { sawName = false; tagger = null; foreach (var pair in TaggerProviders) { var provider = pair.Value; var providerType = provider.GetType(); // First step is to check the name of the tagger. The ReSharper taggers we care // about all have the same name if (providerType.Name == ResharperTaggerProviderName) { // Next we need to make sure this is actually a ReSharper tagger. Both dotCover // and ReSharper use the same tagger name. The only way to differentiate them is // to look at the assembly version var version = ResharperVersionUtility.DetectFromAssembly(providerType.Assembly); if (version != ReSharperVersion.Unknown) { SetReSharperVersion(version); var taggerResult = provider.SafeCreateTagger <ITag>(textBuffer); if (taggerResult.IsSuccess) { tagger = taggerResult.Value; return(true); } } else { sawName = true; } } } return(false); }
internal bool IsInterested(ITextView textView, out ITagger<ITag> tagger) { if (!_reSharperUtil.IsInstalled) { tagger = null; return false; } if (!_versionInfo.HasValue) { // There is a possible race in MEF construction which would allow this method to be // called before we had the list of ITaggerProvider instances to query. In that case // defer to the next check. if (TaggerProviders == null) { tagger = null; return false; } _versionInfo = DetectVersionInfo(); } return IsInterested(textView.TextBuffer, out tagger); }
public ES6Classifier(IClassificationTypeRegistryService registry, ITextBuffer buffer) { _keyword = registry.GetClassificationType(PredefinedClassificationTypeNames.Keyword); _identifier = registry.GetClassificationType(PredefinedClassificationTypeNames.Identifier); _tagger = buffer.Properties.GetProperty<ITagger<ClassificationTag>>(_jsTaggerType); }
public void SetUp() { tagger = new PosTagger.Tagger(new MorfeuszConverter()); }
bool IExternalEditAdapter.IsInterested(ITextView textView, out ITagger<ITag> tagger) { tagger = null; return true; }
bool IExternalEditAdapter.IsInterested(ITextView textView, out ITagger<ITag> tagger) { return IsInterested(textView, out tagger); }
/// <summary> /// Get the R# tagger for the ITextBuffer if it exists /// </summary> private bool TryGetResharperTagger(ITextBuffer textBuffer, out ITagger<ITag> tagger) { Contract.Assert(_isResharperInstalled); // This is available as a post construction MEF import so it's very possible // that this is null if it's not initialized if (TaggerProviders == null) { tagger = null; return false; } // R# exposes it's ITaggerProvider instances for the "text" content type. As much as // I would like to query to make sure they always support the content type we don't // have access to the metadata and have to hard code "text" here if (!textBuffer.ContentType.IsOfType("text")) { tagger = null; return false; } // The various JetBrains products reuse at a code base level certain constructs // such as ITagger<T> implementations. For example both R# and dotTrace and // dotCover use the VsDocumentMarkerTaggerProvider. If multiple products are // installed then MEF composition will return them in a non-deterministic // order. They all have the same fully qualified name. The only way to // distinguish them is to look at the assembly name containing the type bool sawName = false; foreach (var pair in TaggerProviders) { var provider = pair.Value; var providerType = provider.GetType(); if (providerType.Name == ResharperTaggerProviderName) { if (providerType.Assembly.FullName.StartsWith(ResharperAssembylName)) { var taggerResult = provider.SafeCreateTagger<ITag>(textBuffer); if (taggerResult.IsSuccess) { tagger = taggerResult.Value; return true; } } else { sawName = true; } } } // It's unclear if the Dev10 portion changes in R# builds for Dev11 or not. Once // a R# 7.0 build is available we can verify this to be the case or not. Until then // assume the name does change and bind to the short name here. Will at least // work for customers with only R# installed on VS11 if (sawName) { foreach (var pair in TaggerProviders) { var provider = pair.Value; var providerType = provider.GetType(); if (providerType.Name == ResharperTaggerProviderName) { var taggerResult = provider.SafeCreateTagger<ITag>(textBuffer); if (taggerResult.IsSuccess) { tagger = taggerResult.Value; return true; } } } } tagger = null; return false; }
/// <summary> /// Enumerates all of the classifications in reverse starting at start to the beginning of the file. /// </summary> private static IEnumerator<ITagSpan<ClassificationTag>> EnumerateClassificationsInReverse(ITagger<ClassificationTag> classifier, SnapshotPoint start) { if (classifier == null) { yield break; } var curLine = start.GetContainingLine(); var spanEnd = start; for (; ; ) { var classifications = classifier.GetTags( new NormalizedSnapshotSpanCollection(new SnapshotSpan(curLine.Start, spanEnd)) ); foreach (var classification in classifications.Reverse()) { yield return classification; } yield return null; if (curLine.LineNumber == 0) { break; } curLine = start.Snapshot.GetLineFromLineNumber(curLine.LineNumber - 1); spanEnd = curLine.End; } }
/// <summary> /// The various JetBrains products reuse at a code base level certain constructs /// such as ITagger<T> implementations. For example both R# and dotTrace and /// dotCover use the VsDocumentMarkerTaggerProvider. If multiple products are /// installed then MEF composition will return them in a non-deterministic /// order. They all have the same fully qualified name. The only way to /// distinguish them is to look at the assembly name containing the type /// </summary> private bool TryGetSpecificTagger(ITextBuffer textBuffer, out bool sawName, out ITagger<ITag> tagger) { sawName = false; tagger = null; foreach (var pair in TaggerProviders) { var provider = pair.Value; var providerType = provider.GetType(); if (providerType.Name == ResharperTaggerProviderName) { EnsureReShaprerVersion(providerType); if (_reSharperVersion.Value != ReSharperVersion.Unknown) { var taggerResult = provider.SafeCreateTagger<ITag>(textBuffer); if (taggerResult.IsSuccess) { tagger = taggerResult.Value; return true; } } else { sawName = true; } } } return false; }
/// <summary> /// This method is to try to account for ReSharper versions that are not released at /// this time. Instead of looking for the version specific names we just look at the /// jet brains assembly that have the correct tagger name /// /// One problem here is that the tagger implementations are shared between a couple /// of JetBrains products including dotCover. Hence we need to keep in mind both the /// assembly and tagger name here /// </summary> private bool TryGetGeneralTagger(ITextBuffer textBuffer, out ITagger<ITag> tagger) { foreach (var provider in GetTaggerProvidersSafe()) { var providerType = provider.GetType(); if (providerType.Name == ResharperTaggerProviderName && providerType.Assembly.FullName.StartsWith("JetBrains", StringComparison.OrdinalIgnoreCase)) { var taggerResult = provider.SafeCreateTagger<ITag>(textBuffer); if (taggerResult.IsSuccess) { tagger = taggerResult.Value; return true; } } } tagger = null; return false; }
public void Init( bool forSearch = true, string lastSearch = null, params string[] lines) { lines = lines.Length > 0 ? lines : DefaultText; _textBuffer = EditorUtil.CreateBuffer(lines); _settings = new Mock<IVimGlobalSettings>(); _search = new Mock<ISearchService>(); _nav = new Mock<ITextStructureNavigator>(MockBehavior.Strict); _taggerRaw = new HighlightIncrementalSearchTagger( _textBuffer, _settings.Object, _nav.Object, _search.Object); _tagger = _taggerRaw; if (forSearch) { _settings.SetupGet(x => x.IgnoreCase).Returns(true); _settings.SetupGet(x => x.HighlightSearch).Returns(true); } if (lastSearch != null) { _search.SetupGet(x => x.LastSearch).Returns(new SearchData(SearchText.NewPattern(lastSearch), SearchKind.Forward, SearchOptions.None)); } }
public SmartIndent(ITextView textView, IEditorOptions editorOptions, ITagger<ClassificationTag> classifier) { _textView = textView; _editorOptions = editorOptions; _classifier = classifier; _textView.Properties.AddProperty(typeof(SmartIndent), this); }
/// <summary> /// Get the R# tagger for the ITextBuffer if it exists /// </summary> private bool TryGetResharperTagger(ITextBuffer textBuffer, out ITagger<ITag> tagger) { Contract.Assert(_isResharperInstalled); // This is available as a post construction MEF import so it's very possible // that this is null if it's not initialized if (TaggerProviders == null) { tagger = null; return false; } // R# exposes it's ITaggerProvider instances for the "text" content type. As much as // I would like to query to make sure they always support the content type we don't // have access to the metadata and have to hard code "text" here if (!textBuffer.ContentType.IsOfType("text")) { tagger = null; return false; } foreach (var pair in TaggerProviders) { var provider = pair.Value; var name = provider.GetType().Name; if (name == ResharperTaggerName) { var taggerResult = provider.SafeCreateTagger<ITag>(textBuffer); if (taggerResult.IsSuccess) { tagger = taggerResult.Value; return true; } } } tagger = null; return false; }
/// <summary> /// The various JetBrains products reuse at a code base level certain constructs /// such as ITagger<T> implementations. For example both R# and dotTrace and /// dotCover use the VsDocumentMarkerTaggerProvider. If multiple products are /// installed then MEF composition will return them in a non-deterministic /// order. They all have the same fully qualified name. The only way to /// distinguish them is to look at the assembly name containing the type /// </summary> private bool TryGetSpecificTagger(ITextBuffer textBuffer, out bool sawName, out ITagger<ITag> tagger) { sawName = false; tagger = null; foreach (var provider in GetTaggerProvidersSafe()) { var providerType = provider.GetType(); // First step is to check the name of the tagger. The ReSharper taggers we care // about all have the same name if (providerType.Name == ResharperTaggerProviderName) { // Next we need to make sure this is actually a ReSharper tagger. Both dotCover // and ReSharper use the same tagger name. The only way to differentiate them is // to look at the assembly version var version = ResharperVersionUtility.DetectFromAssembly(providerType.Assembly); if (version != ReSharperVersion.Unknown) { SetReSharperVersion(version); var taggerResult = provider.SafeCreateTagger<ITag>(textBuffer); if (taggerResult.IsSuccess) { tagger = taggerResult.Value; return true; } } else { sawName = true; } } } return false; }
/// <summary> /// Get the R# tagger for the ITextBuffer if it exists /// </summary> private bool IsInterested(ITextBuffer textBuffer, out ITagger<ITag> tagger) { Contract.Assert(_reSharperUtil.IsInstalled); Contract.Assert(_versionInfo.HasValue); // R# exposes it's ITaggerProvider instances for the "text" content type. As much as // I would like to query to make sure they always support the content type we don't // have access to the metadata and have to hard code "text" here if (!textBuffer.ContentType.IsOfType("text")) { tagger = null; return false; } var versionInfo = _versionInfo.Value; if (!versionInfo.UseTagBasedDetection) { // Version 10 and above doesn't use tag detection, it just looks for the key. No need // for a specific ITagger here. tagger = null; return true; } tagger = versionInfo.TaggerProvider != null ? versionInfo.TaggerProvider.SafeCreateTagger<ITag>(textBuffer).GetValueOrDefault() : null; return tagger != null; }
/// <summary> /// Get the R# tagger for the ITextBuffer if it exists /// </summary> private bool TryGetResharperTagger(ITextBuffer textBuffer, out ITagger<ITag> tagger) { Contract.Assert(_isResharperInstalled); // This is available as a post construction MEF import so it's very possible // that this is null if it's not initialized if (TaggerProviders == null) { tagger = null; return false; } // R# exposes it's ITaggerProvider instances for the "text" content type. As much as // I would like to query to make sure they always support the content type we don't // have access to the metadata and have to hard code "text" here if (!textBuffer.ContentType.IsOfType("text")) { tagger = null; return false; } bool sawName; if (TryGetSpecificTagger(textBuffer, out sawName, out tagger)) { return true; } if (sawName && TryGetGeneralTagger(textBuffer, out tagger)) { return true; } tagger = null; return false; }
private void Create(params string[] lines) { _textBuffer = EditorUtil.CreateTextBuffer(lines); _globalSettings = new GlobalSettings(); _globalSettings.IgnoreCase = true; _globalSettings.HighlightSearch = true; _vimData = new VimData(); _searchService = VimUtil.CreateSearchService(); _taggerRaw = new HighlightIncrementalSearchTagger( _textBuffer, _globalSettings, VimUtil.CreateTextStructureNavigator(_textBuffer, WordKind.NormalWord), _searchService, _vimData); _tagger = _taggerRaw; }
private void TestInitialise(string gherkinFileLocation) { var registry = MockRepository.GenerateMock<IClassificationTypeRegistryService>(); registry.Stub(service => service.GetClassificationType(null)) .IgnoreArguments() .WhenCalled(invocation => { invocation.ReturnValue = new MockClassificationType { Classification = (string)invocation.Arguments.First() }; }); buffer = MockRepository.GenerateMock<ITextBuffer>(); buffer.Stub(textBuffer => textBuffer.Properties).Return(new PropertyCollection()); featureFileContent = new StreamReader(gherkinFileLocation).ReadToEnd(); buffer.Stub(b => b.CurrentSnapshot).Return(new MockTextSnapshot(featureFileContent)); //var gherkinFileEditorParser = new GherkinFileEditorParser(); //gherkinFileEditorParser.InitialiseWithBuffer(_buffer); //_buffer.Properties.AddProperty(typeof(GherkinFileEditorParser), gherkinFileEditorParser); playTagger = new PlayTagger(new TokenParser(buffer)); //gherkinFileEditorParser.FirstParse(); }
/// <summary> /// The various JetBrains products reuse at a code base level certain constructs /// such as ITagger<T> implementations. For example both R# and dotTrace and /// dotCover use the VsDocumentMarkerTaggerProvider. If multiple products are /// installed then MEF composition will return them in a non-deterministic /// order. They all have the same fully qualified name. The only way to /// distinguish them is to look at the assembly name containing the type /// </summary> private bool TryGetSpecificTagger(ITextBuffer textBuffer, out bool sawName, out ITagger<ITag> tagger) { sawName = false; tagger = null; foreach (var pair in TaggerProviders) { var provider = pair.Value; var providerType = provider.GetType(); if (providerType.Name == ResharperTaggerProviderName) { var fullName = providerType.Assembly.FullName; if (fullName.StartsWith(ResharperAssemblyName2010) || fullName.StartsWith(ResharperAssemblyName2012)) { var taggerResult = provider.SafeCreateTagger<ITag>(textBuffer); if (taggerResult.IsSuccess) { tagger = taggerResult.Value; return true; } } else { sawName = true; } } } return false; }