Visual Studio extension: Color C++ Miscs.
Branch | Build Status |
---|---|
master |
Extension allows colorizing certain C++ code parts using regular expressions.
Extension works in files of ContentType
"C/C++"
, eg .cpp
or .h
files.
- Edit region
rules
from functionClassifier.Classify
of a fileClassifier.cs
. Existing rules are left as an example. - Either delete them all and add your own rules, or begin with editing existing ones.
- Finally, compile, test and (re)install output
.vsix
extension by running it.
In order to add a regex rule, add another Colorize
to Colorizes
List in a rules
region mentioned above.
Structure of Colorizes
is self-explaining, yet let's highlight it here:
public struct Replacement
{
public string Name;
public IClassificationType Color;
}
public struct Condition
{
public string Name;
public List<string>? CantBeClassifiedAs;
public List<string>? MustBeClassifiedAs;
public List<string>? MustBeClassifiedAsAnyOf;
}
public struct Colorize
{
public Regex Regex;
public List<Condition>? Conditions;
public List<Replacement> Replacements;
}
public struct Colors
{
public string Name;
public IClassificationType Color;
}
Note that classifications are not documented.
I lost way too much time asking for the documentation.
Finally, in order to change colors, edit them in Definitions.cs
, Style.cs
, Default.cs
and Classifier.cs
.
Sorry, I didn't found any easy way to use them, eg by regex RGB. Same as witch classifications, MSVC extension writing support is almost not existing. Let me not rant about it. It's enough that .NET sucks, aswell as all vsix api. I will never get my lost time back.
The following code adds a rule that will change color of all keywords private
to Red
.
Note that the keywords is being found by regex, it must be classified as keyword
and cannot be part of neither a comment (normal: comment
, triple slash aka xml: XML Doc Comment
) nor a string literal (string
).
// private
Colorizes.Add(new Colorize(){
Regex = new Regex
(
@"(?<Access>" + Utils.IdentifierBeginningBoundary + @"private" + Utils.IdentifierEndingBoundary + @")"
),
Conditions = new List<Condition>(){
new Condition(){
Name = "Access",
CantBeClassifiedAs = new List<string>(){"comment", "XML Doc Comment", "string"},
MustBeClassifiedAs = new List<string>(){"keyword"},
},
},
Replacements = new List<Replacement>(){
new Replacement(){Name = "Access", Color = Red},
},
});
Wish you best luck with creating your own regex rules.