mirror of
https://github.com/M455YN/csharp-razor-taghelpers.git
synced 2026-12-01 03:57:05 +00:00
Enhanced C# and .NET development in VS Code with IntelliSense and hover support for custom Razor Tag Helpers.
- JavaScript 100%
ssms.js as CSharpShooter SQL's (ac743e0): with an SSMS running, the .sql file is handed over by explorer.exe, the file association's DDE, so it opens as a tab taking that SSMS's connection; with none, SSMS starts connected by the project's connection string, as before. |
||
|---|---|---|
| .github | ||
| .vscode | ||
| scripts | ||
| test | ||
| .gitignore | ||
| .npmignore | ||
| CHANGELOG.md | ||
| definition.js | ||
| diagnostics.js | ||
| extension.js | ||
| folding.js | ||
| inlayHints.js | ||
| LICENSE | ||
| logo.png | ||
| logo.svg | ||
| outline.js | ||
| package-lock.json | ||
| package.json | ||
| README.md | ||
| sqlHighlight.js | ||
| sqlQuery.js | ||
| ssms.js | ||
| tagHelperScan.js | ||
| tagHelpersTree.js | ||
| whatsNew.js | ||
C# Razor Tag Helper Support
C# Razor Tag Helper Support is a Visual Studio Code extension that
extends the official C# extension with additional support for custom
Razor Tag Helpers in Razor views (.cshtml / .razor).
The extension scans C# projects to detect Tag Helper classes and provides improved editor assistance when working with them.
Features
Automatic Tag Helper Discovery
- Scans
.csfiles in the current workspace - Detects classes that implement Razor Tag Helpers
- Resolves tag names from
HtmlTargetElementattributes - Extracts public properties to determine available attributes
Tag Name IntelliSense
- Provides suggestions for detected Tag Helpers while typing HTML tags in Razor views
- Integrates with the IntelliSense provided by the official C# extension
Attribute IntelliSense
- Suggests attributes that belong to the detected Tag Helper
- Filters attribute suggestions based on the current tag
- Inserts attributes using snippets with the cursor positioned inside quotes
Hover Documentation
- Displays documentation for Tag Helpers and their attributes
- Uses XML documentation comments (
/// <summary>) from the C# source code - Shows helpful tooltips directly in Razor files
Tag Helper Folding
- Adds fold markers for discovered Tag Helper elements in
.cshtml/.razorfiles - Collapses multi-line opening tags (typical for a
<grid>whoseselectattribute holds a large SQL string) - Collapses matching open/close Tag Helper pairs, including nesting
- Ignores markup that appears inside C# verbatim strings, quoted attributes, and comments
- Command C# Razor Tag Helper Support: Fold All Tag Helpers folds every Tag Helper in the current file
- Multi-line attributes (especially
select/lookup-sqlwith SQL) get their own fold, so the query can be collapsed without hiding the rest of the tag - Can be turned off with
csharpRazorTagHelpers.enableFolding
Select Attribute Value
- Command C# Razor Tag Helper Support: Select Attribute Value
selects only the inner value of the attribute under the cursor
(the SQL inside
select="@(@" ... ")", not the whole<grid>) - Also available from the editor context menu (right-click) in
.cshtml/.razorfiles - If the cursor is on the tag name or between attributes, the
selectattribute is used when present - Expand Selection (
Shift+Alt+Right/Alt+Shift+Right) grows from the SQL, to the whole attribute, to the whole Tag Helper
Go to Definition (F12)
F12on a Tag Helper element name (<grid>,</filters>) jumps to the C# Tag Helper classF12on an attribute name jumps to the corresponding C# property (including properties inherited from a base Tag Helper)
SQL highlighting
-
Highlights SQL keywords, comments, strings, and numbers inside configured Tag Helper attributes (default:
select,insert,update,delete,move,lookup-sql,sqlon any tag) -
Restrict or extend via
csharpRazorTagHelpers.sqlHighlighting.rules, for example only<grid>and<filter>:"csharpRazorTagHelpers.sqlHighlighting.rules": [ { "tag": "grid", "attributes": ["select", "insert", "update", "delete"] }, { "tag": "filter", "attributes": ["lookup-sql"] } ] -
tagcan be a helper name or*(any element).attributescan include*(every attribute of that tag) -
Turn off with
csharpRazorTagHelpers.sqlHighlighting.enabled
SQL in SQL Server Management Studio, and its syntax errors
- Open … in SQL Server Management Studio above each of those
attributes opens its SQL in SSMS (as a tab of the one already running,
else the newest installed, started connected), runnable: the
C# string's
""made", and adeclarefor each variable the app passes in (@UserEmployeeId,@$DateFrom, a table for one readfrom), to be given values. SSMS connects with the server, database and login of a connection string of the nearestappsettings*.jsonabove the page (asked when several; the password is never passed). Each save of that query in SSMS puts it back into the attribute (the declares and their values left out, the""doubled again), the page left unsaved; it asks first if the attribute was changed meanwhile (csharpRazorTagHelpers.sqlSsmsSyncBackturns it off). SSMS logs in with Windows authentication by default;sqlSsmsAuthenticationset toconnectionStringlogs in as the connection string says. Turn off withcsharpRazorTagHelpers.sqlCodeLens.enabled - With the CSharpShooter SQL extension installed, the SQL's syntax
errors are underlined as you type, from its SQL Tools Service, with no
connection to a server. Turn off with
csharpRazorTagHelpers.sqlDiagnostics.enabled
Outline
- Tag Helpers appear in Outline / breadcrumbs as nested symbols
(
grid#grid-talent-matrix,filter[programId])
Copy Attribute Value
- Command Copy Attribute Value (also in the editor context menu)
copies the inner value (e.g. SQL in
select) to the clipboard
Diagnostics
- Warns about unknown attributes on a known Tag Helper (typos like
hide-item-buton-p); HTML,data-*,aria-*, andasp-*are ignored - Warns when a helper is used outside its
ParentTag(e.g.<filter>outside<filters-group>) - Toggle with
csharpRazorTagHelpers.diagnostics.enabled
What's New
- After a fresh install or an update, a What's New tab opens with
the same
CHANGELOG.mdas on GitHub (markdown, not a webview) - Reopen anytime: C# Razor Tag Helper Support: What's New
- Turn off auto-open with
csharpRazorTagHelpers.showWhatsNewOnUpdate
How It Works
- The extension scans the workspace for
.csfiles. - Tag Helper classes are detected automatically.
- Tag names and attributes are extracted from the C# code.
- IntelliSense suggestions are provided inside Razor views.
Supported Files
.cshtml.razor.cs(for Tag Helper detection)
Requirements
- Visual Studio Code
License
MIT