Example #1
0
        public static ImmutableArray <string> GetClassificationsForSpan(IWpfTextView view, Span span)
        {
            ThreadHelper.ThrowIfNotOnUIThread();

            // If the cursor is after the last character return empty array.
            if (span.Start == view.TextBuffer.CurrentSnapshot.Length)
            {
                return(ImmutableArray <string> .Empty);
            }

            // The span to classify must have a length.
            var snapshotSpan = span.Length == 0
                ? new SnapshotSpan(view.TextSnapshot, span.Start, 1)
                : new SnapshotSpan(view.TextSnapshot, span);

            var classificationService = VSServiceHelpers.GetMefExport <IClassifierAggregatorService>();
            var classifier            = (IAccurateClassifier)classificationService.GetClassifier(view.TextBuffer);

            var classifiedSpans = classifier.GetAllClassificationSpans(snapshotSpan, CancellationToken.None);

            var classifications = ImmutableArray.CreateBuilder <string>();

            foreach (var classifiedSpan in classifiedSpans)
            {
                CollectClassifications(classifiedSpan.ClassificationType, classifications);
            }

            return(classifications.ToImmutable());
Example #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MainWindowControl"/> class.
        /// </summary>
        public MainWindowControl()
        {
            DataContext = _viewModel = new MainWindowControlViewModel();
            InitializeComponent();

            _activeWindowTracker = new ActiveWindowTracker();
            _activeWindowTracker.PropertyChanged += ActiveWindowPropertyChanged;

            var editorFormatMapService = VSServiceHelpers.GetMefExport <IEditorFormatMapService>();
            var editorFormatMap        = editorFormatMapService.GetEditorFormatMap("text");

            editorFormatMap.FormatMappingChanged += (object s, FormatItemsEventArgs e) => UpdateClassifications(e.ChangedItems);

            void UpdateClassifications(ReadOnlyCollection <string> definitionNames)
            {
                _viewModel.OnThemeChanged(definitionNames.ToLookup(name => name));
            }
        }