private static void CreateClassificationTypeMap()
 {
     if (_tokenClassificationTypeMap == null || !_tokenClassificationTypeMap.Any())
     {
         _tokenClassificationTypeMap = new Dictionary <PSTokenType, IClassificationType>();
         _tokenClassificationTypeMap[PSTokenType.Attribute]          = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellAttribute);
         _tokenClassificationTypeMap[PSTokenType.Command]            = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellCommand);
         _tokenClassificationTypeMap[PSTokenType.CommandArgument]    = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellCommandArgument);
         _tokenClassificationTypeMap[PSTokenType.CommandParameter]   = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellCommandParameter);
         _tokenClassificationTypeMap[PSTokenType.Comment]            = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellComment);
         _tokenClassificationTypeMap[PSTokenType.GroupEnd]           = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellGroupEnd);
         _tokenClassificationTypeMap[PSTokenType.GroupStart]         = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellGroupStart);
         _tokenClassificationTypeMap[PSTokenType.Keyword]            = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellKeyword);
         _tokenClassificationTypeMap[PSTokenType.LineContinuation]   = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellLineContinuation);
         _tokenClassificationTypeMap[PSTokenType.LoopLabel]          = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellLoopLabel);
         _tokenClassificationTypeMap[PSTokenType.Member]             = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellMember);
         _tokenClassificationTypeMap[PSTokenType.NewLine]            = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellNewLine);
         _tokenClassificationTypeMap[PSTokenType.Number]             = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellNumber);
         _tokenClassificationTypeMap[PSTokenType.Operator]           = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellOperator);
         _tokenClassificationTypeMap[PSTokenType.Position]           = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellPosition);
         _tokenClassificationTypeMap[PSTokenType.StatementSeparator] = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellStatementSeparator);
         _tokenClassificationTypeMap[PSTokenType.String]             = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellString);
         _tokenClassificationTypeMap[PSTokenType.Type]     = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellType);
         _tokenClassificationTypeMap[PSTokenType.Unknown]  = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellUnknown);
         _tokenClassificationTypeMap[PSTokenType.Variable] = ClassificationTypeRegistryService.GetClassificationType(Classifications.PowerShellVariable);
     }
 }
Beispiel #2
0
        protected override IList <ClassificationSpan> DoGetClassificationSpans(Microsoft.VisualStudio.Text.SnapshotSpan span)
        {
            var result = base.DoGetClassificationSpans(span);

            if (ShouldOverrideOutputWindowTextClassification &&
                (result == null || result.Count == 0))
            {
                var c = ClassificationTypeRegistryService.GetClassificationType(OutputWindowTextClassificationOverride);

                result.Add(new ClassificationSpan(new SnapshotSpan(span.Start, span.Length), c));
            }

            return(result);
        }
        protected virtual IList <ClassificationSpan> DoGetClassificationSpans(SnapshotSpan span)
        {
            List <ClassificationSpan> result = new List <ClassificationSpan>();

            try
            {
                if (!IsEnabled)
                {
                    return(result);
                }

                if (span == null || span.IsEmpty)
                {
                    return(result);
                }

                string spanText = span.GetText();

                foreach (var ctmp in ClassificationTypesMatchPatterns)
                {
                    if (!ctmp.IsMatch(spanText))
                    {
                        continue;
                    }
                    else
                    {
                        var c = ClassificationTypeRegistryService.GetClassificationType(ctmp.ClassificationTypeName);

                        result.Add(
                            new ClassificationSpan(
                                new SnapshotSpan(span.Start, span.Length), c));
                        break;
                    }
                }
            }
            catch (Exception ex)
            {
                // TODO: logging
                //ex.Log();
            }

            return(result);
        }
Beispiel #4
0
        public IEnumerable <ITagSpan <RegionTag> > GetTags(NormalizedSnapshotSpanCollection snapShotSpans)
        {
            foreach (SnapshotSpan snapshotSpan in snapShotSpans.Where(IsRegionOrEndRegion))
            {
                SnapshotPoint?point = View.Caret.Position.Point.GetPoint(SourceBuffer, View.Caret.Position.Affinity);

                int pointPosition          = point.HasValue ? snapshotSpan.Snapshot.GetLineNumberFromPosition(point.Value) : -1;
                int lineNumberFromPosition = snapshotSpan.Snapshot.GetLineNumberFromPosition(snapshotSpan.Start);
                int index = snapshotSpan.GetText().IndexOf(Constants.RegionIndicatorCharacter);

                SnapshotSpan newSpan = new SnapshotSpan(snapshotSpan.Snapshot, (int)snapshotSpan.Start + index, snapshotSpan.Length - index);

                string classificationTypeNames = lineNumberFromPosition != pointPosition
                    ? Constants.InactiveRegionClassificationTypeNames
                    : Constants.ActiveRegionClassificationTypeNames;

                yield return(new TagSpan <RegionTag>(newSpan, new RegionTag(ClassificationTypeRegistryService.GetClassificationType(classificationTypeNames))));
            }
        }
Beispiel #5
0
        protected override IList <ClassificationSpan> DoGetClassificationSpans(SnapshotSpan span)
        {
            List <ClassificationSpan> result = new List <ClassificationSpan>();

            try
            {
                if (!IsEnabled)
                {
                    return(result);
                }

                if (span == null || span.IsEmpty)
                {
                    return(result);
                }

                string spanText = span.GetText();

                if (spanText.IsNullOrEmpty())
                {
                    return(result);
                }

                var matchClassification = ClassificationTypeRegistryService.GetClassificationType(ClassificationNames.FindResultsOutputMatch);
                var textClassification  = ClassificationTypeRegistryService.GetClassificationType(ClassificationNames.OutputText);

                var find = Dte.Find;

                // get searched text
                var searchedText = find.FindWhat;

                // escape regex special characters
                var pattern = Regex.Escape(searchedText);

                var regexOptions = RegexOptions.None;

                // match whole word?
                if (find.MatchWholeWord)
                {
                    pattern = @"\b{0}\b".FormatWith(pattern);
                }

                // match case?
                if (!find.MatchCase)
                {
                    regexOptions = RegexOptions.IgnoreCase;
                }

                Regex regex   = new Regex(pattern, regexOptions);
                var   matches = regex.Matches(spanText);

                //+ gray out path part if needed
                if (matches.Count > 0 && ShouldOverrideOutputWindowTextClassification)
                {
                    var lineNumberPartIndex = spanText.IndexOf("):");

                    if (lineNumberPartIndex < matches[0].Index)
                    {
                        result.Add(new ClassificationSpan(new SnapshotSpan(span.Start, lineNumberPartIndex + 2), textClassification));
                    }
                }

                //+ highlight matches
                foreach (Match match in matches)
                {
                    result.Add(new ClassificationSpan(new SnapshotSpan(span.Start + match.Index, match.Length), matchClassification));
                }

                //+ gray out lines without results
                if (ShouldOverrideOutputWindowTextClassification)
                {
                    var isResultsHeader = spanText.StartsWith("Find all \"");

                    if (result.Count == 0 || isResultsHeader)
                    {
                        result.Add(new ClassificationSpan(new SnapshotSpan(span.Start, span.End), textClassification));
                    }
                }
            }
            catch (Exception ex)
            {
                //tODO: log
                //ex.Log();
            }

            return(result);
        }
Beispiel #6
0
 private IClassificationType GetOrRetreiveClassification(ref IClassificationType target, string name)
 {
     return(target ?? (target = ClassificationTypeRegistryService.GetClassificationType(name)));
 }
Beispiel #7
0
        protected void RefreshClassifications()
        {
            // read color settings from VSCommands category and apply them to classification types

            const uint flags = (uint)(
                __FCSTORAGEFLAGS.FCSF_LOADDEFAULTS | __FCSTORAGEFLAGS.FCSF_PROPAGATECHANGES);

            try
            {
                var x = FontAndColorStorageService.OpenCategory(new Guid("{b0e6a221-92fd-4d72-be80-04a36b591fcb}"), flags);
                foreach (var item in ClassificationTypesMatchPatterns)
                {
                    try
                    {
                        if (FontAndColorStorageService.GetItem(item.ClassificationTypeName, item.ColorableItemInfos) < 0)
                        {
                            // Logger.TraceDiagnosticWarning(() => "Unable to load classification data for {0}".FormatWith(item.ClassificationTypeName));
                            continue;
                        }

                        var ct = ClassificationTypeRegistryService.GetClassificationType(item.ClassificationTypeName);

                        var fm = ClassificationFormatMapService.GetClassificationFormatMap(ClassificationMapName);

                        var currentTp = fm.GetTextProperties(ct);

                        var tp = currentTp.SetForeground(item.ColorableItemInfos[0].GetForeground());

                        tp = tp.SetBackground(item.ColorableItemInfos[0].GetBackground());

                        var fontFlags = (FONTFLAGS)item.ColorableItemInfos[0].dwFontFlags;

                        if (fontFlags.IsFlagSet(FONTFLAGS.FF_BOLD))
                        {
                            tp = tp.SetBold(true);
                        }
                        else
                        {
                            tp = tp.SetBold(false);
                        }

                        fm.SetTextProperties(ct, tp);
                    }
                    catch (Exception ex)
                    {
                        // TODO: logging
                        // Logger.LogException(ex);
                    }
                }

                FontAndColorStorageService.CloseCategory();
            }
            catch (Exception ex)
            {
                // TODO: logging
            }
            finally
            {
                FontAndColorStorageService.CloseCategory();
            }
        }
 internal PowerShellClassifier(ITextBuffer bufferToClassify)
     : base(bufferToClassify)
 {
     _scriptGaps = ClassificationTypeRegistryService.GetClassificationType("PS1ScriptGaps");
 }