private void ApplyFormatting(SettingsItem item, IClassificationFormatMap formatMap)
        {
            if (!item.IsActive)
            {
                return;
            }

            var classificationType = ClassificationRegistry.GetClassificationType(item.ClassificationId);

            if (classificationType == null)
            {
                return;
            }
            var oldFormatting   = formatMap.GetTextProperties(classificationType);
            var foregroundBrush = item.ForegroundColor == Colors.Transparent ? null : new SolidColorBrush(item.ForegroundColor);
            var backgroundBrush = item.BackgroundColor == Colors.Transparent ? null : new SolidColorBrush(item.BackgroundColor);
            var formatting      = TextFormattingRunProperties.CreateTextFormattingRunProperties(foregroundBrush, backgroundBrush, oldFormatting.Typeface, null, null, oldFormatting.TextDecorations, oldFormatting.TextEffects, oldFormatting.CultureInfo);

            formatting = Settings.Settings.Instance.UpdateProperties(item, formatting);
            var identifierPosition = formatMap.CurrentPriorityOrder.IndexOf(classificationType);

            if (identifierPosition < 0)
            {
                return;
            }
            var afterIdentifierClassification = formatMap.CurrentPriorityOrder[identifierPosition /* + 1*/];

            // formatMap.AddExplicitTextProperties(classificationType, formatting, afterIdentifierClassification);
            formatMap.AddExplicitTextProperties(classificationType, formatting, afterIdentifierClassification);
        }
Пример #2
0
        private void SetProperties(IClassificationType type, IStyle style, IClassificationFormatMap map)
        {
            var props = map.GetExplicitTextProperties(type)
                        .SetTypeface(new Typeface(style.Font))
                        .SetForeground(style.Foreground)
                        .SetBackground(style.Background)
                        .SetForegroundOpacity(style.Opacity)
                        .SetFontRenderingEmSize(style.Size)
                        .SetItalic(style.Italic)
                        .SetBold(style.Bold);

            var textDecorations = new TextDecorationCollection();

            //? props.TextDecorations.Add(TextDecorations.Underline);
            if (style.Underline)
            {
                textDecorations.Add(TextDecorations.Underline);
            }

            //? props.TextDecorations.Add(TextDecorations.Strikethrough);
            if (style.Strikethrough)
            {
                textDecorations.Add(TextDecorations.Strikethrough);
            }

            //? remove this line when using TextDecorations.Add()
            props = props.SetTextDecorations(textDecorations);

            map.AddExplicitTextProperties(type, props);
        }
Пример #3
0
        internal void Initialize(IClassificationTypeRegistryService service,
                                 IClassificationFormatMapService ClassificationFormatMapService)
        {
            try
            {
                if (initialized)
                {
                    return;
                }

                string ffn = _buffer.GetFFN().Result;
                if (ffn == null)
                {
                    return;
                }

                LanguageServer.IGrammarDescription _grammar_description = LanguageServer.GrammarDescriptionFactory.Create(ffn);
                if (_grammar_description == null)
                {
                    return;
                }

                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                _lsptype_to_classifiertype = new Dictionary <int, IClassificationType>();
                for (int i = 0; i < _grammar_description.Map.Length; ++i)
                {
                    int    key = i;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType == null?service.CreateClassificationType(val, new IClassificationType[] { })
                                                                          : identiferClassificationType;

                    IClassificationFormatMap classificationFormatMap = ClassificationFormatMapService.GetClassificationFormatMap(category: "text");
                    Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                              .GetExplicitTextProperties(classificationType);
                    System.Drawing.Color color = !Themes.IsInvertedTheme() ? _grammar_description.MapColor[key]
                        : _grammar_description.MapInvertedColor[key];
                    System.Windows.Media.Color newColor = System.Windows.Media.Color.FromArgb(color.A, color.R, color.G, color.B);
                    Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties newProperties = identifierProperties.SetForeground(newColor);
                    classificationFormatMap.AddExplicitTextProperties(classificationType, newProperties);
                }
                {
                    int    key = (int)SymbolKind.Variable;
                    string val = _grammar_description.Map[0];
                    _lsptype_to_classifiertype[key] = service.GetClassificationType(val);
                }
                {
                    int    key = (int)SymbolKind.Enum;
                    string val = _grammar_description.Map[1];
                    _lsptype_to_classifiertype[key] = service.GetClassificationType(val);
                }
                initialized = true;
            }
            catch (Exception)
            {
                //Logger.Log.Notify(exception.StackTrace);
            }
        }
Пример #4
0
        private static void IncreaseServiceFormatPriority(IClassificationFormatMap formatMap, IClassificationTypeRegistryService registry, string formatName,
                                                          IClassificationType highestPriorityType)
        {
            IClassificationType         predefinedClassificationType = registry.GetClassificationType(formatName);
            IClassificationType         artificialClassType          = registry.CreateTransientClassificationType(predefinedClassificationType);
            TextFormattingRunProperties properties = formatMap.GetExplicitTextProperties(predefinedClassificationType);

            formatMap.AddExplicitTextProperties(artificialClassType, properties, highestPriorityType);
            formatMap.SwapPriorities(artificialClassType, predefinedClassificationType);
            formatMap.SwapPriorities(highestPriorityType, predefinedClassificationType);
        }
Пример #5
0
        internal void Initialize(IClassificationTypeRegistryService service,
                                 IClassificationFormatMapService ClassificationFormatMapService)
        {
            try
            {
                if (initialized)
                {
                    return;
                }

                string ffn = _buffer.GetFFN();
                if (ffn == null)
                {
                    return;
                }

                Workspaces.Document document = Workspaces.Workspace.Instance.FindDocument(ffn);
                LanguageServer.IParserDescription _grammar_description = LanguageServer.ParserDescriptionFactory.Create(document);
                if (_grammar_description == null)
                {
                    return;
                }

                _to_classifiertype = new Dictionary <int, IClassificationType>();

                IClassificationFormatMap classificationFormatMap = ClassificationFormatMapService.GetClassificationFormatMap(category: "text");
                // hardwire colors to VS's colors of selected types.
                System.Collections.ObjectModel.ReadOnlyCollection <IClassificationType> list_of_formats = classificationFormatMap.CurrentPriorityOrder;

                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationNonterminalDef;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrNonterminalDef")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable CS0168 // Variable is declared but never used
                        catch (Exception eeks) { }
#pragma warning restore CS0168 // Variable is declared but never used
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationNonterminalRef;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrNonterminalRef")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationTerminalDef;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrTerminalDef")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationTerminalRef;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrTerminalRef")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationComment;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrComment")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationKeyword;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrKeyword")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationLiteral;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrLiteral")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationModeDef;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrModeDef")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationModeRef;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrModeRef")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationChannelDef;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrChannelDef")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationChannelRef;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrChannelRef")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationPunctuation;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrPunctuation")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                {
                    int    i   = (int)LanguageServer.Antlr4ParsingResults.AntlrClassifications.ClassificationOperator;
                    string val = _grammar_description.Map[i];
                    IClassificationType identiferClassificationType = service.GetClassificationType(val);
                    IClassificationType classificationType          = identiferClassificationType ?? service.CreateClassificationType(val, Array.Empty <IClassificationType>());
                    IClassificationType t = list_of_formats.Where(f => f != null && f.Classification == Options.Option.GetString("AntlrOperator")).FirstOrDefault();
                    if (t != null)
                    {
                        try
                        {
                            Microsoft.VisualStudio.Text.Formatting.TextFormattingRunProperties identifierProperties = classificationFormatMap
                                                                                                                      .GetExplicitTextProperties(t);
                            classificationFormatMap.AddExplicitTextProperties(classificationType, identifierProperties);
                        }
#pragma warning disable 0168
                        catch (Exception eeks) { }
#pragma warning restore 0168
                    }
                    _to_classifiertype[i] = classificationType;
                }
                initialized = true;
            }
#pragma warning disable 0168
            catch (Exception eeks) { }
#pragma warning restore 0168
        }
Пример #6
0
 public void AddExplicitTextProperties(IClassificationType classificationType, TextFormattingRunProperties properties) =>
 categoryMap.AddExplicitTextProperties(classificationType, properties);