PostgreSQL in a String
This is a Visual Studio extension that adds highlighting for PostgreSQL syntax in C# string literals.
Applies only to C#
Supports regular quoted strings
Supports parametrized queries. Parameters prefixed with an
Correctly handles string escape sequences.
PostgreSQL in a String uses an ANTLR 4 lexer to tokenize PostgreSQL syntax.
How to enable and disable highlighting
The extension does not automatically detect string literals with PostgreSQL syntax. The syntax highlighting must be explicitly enabled for a single string literal, a code region or whole project.
Inline rule configuration
Highlighting can be enabled inline by prefixing a string literal with a comment containing
When the string literal is inside an enabled region, its highlighting can be disabled inline by prefixing it with a comment containing
Region rule configuration
Enable or disable highlighting in code regions with rule configuration comments. A region configuration will override highlighting of every string literal after it, except for those prefixed with inline rule configuration, until the next region configuration or end of file.
The rule parts can be mixed, e.g.
To have the highlighting enabled by default for an entire project, add the following section in the
This may be useful when you have a separate data access project where most of the strings are database queries.
Rule configuration comments can contain explanations similar to what ESLint rule configuration comments allow.
To add an explanation to the configuration, add two dashes after the rule name (separated by some whitespace) and place your explanation after the dashes.
The default highlight colors were selected for VS dark theme but they can be customized in
The default colors except for parameter color are a mix of 50% default string color and 50% default SQL token color. This means that the highlighted text will have an orange tint, which is by design, to not overwhelm you when combined with other C# syntax as it is still just a string.
Possible further improvements