├── .github └── FUNDING.yml ├── .gitignore ├── BlazmExtension ├── BlazmExtension.Tests │ ├── BlazmExtension.Tests.csproj │ ├── ExtensionTests.cs │ └── GlobalUsings.cs ├── BlazmExtension.sln └── BlazmExtension │ ├── BlazmExtension.csproj │ ├── BlazmExtensionPackage.cs │ ├── Commands │ ├── CreateCodebehindCommand.cs │ ├── CreateIsolatedCssCommand.cs │ ├── CreateIsolatedJavaScriptCommand.cs │ ├── CreatebUnitTestCsCommand.cs │ ├── CreatebUnitTestRazorCommand.cs │ ├── ExtractToComponent.cs │ ├── FindComponentUsagesCommand.cs │ ├── FindComponentUsagesSECommand.cs │ ├── MoveCodebehindToRazor.cs │ ├── MoveNamespaceCommand.cs │ ├── QuickSaveCommand.cs │ ├── RoutingWindowCommand.cs │ ├── RunDotnetWatchCommand.cs │ └── SwitchToNestedFile.cs │ ├── Dialogs │ ├── ComponentReferences │ │ ├── ComponentReferencesControl.xaml │ │ ├── ComponentReferencesControl.xaml.cs │ │ └── ComponentReferencesWindow.cs │ ├── FileNameDialog.xaml │ ├── FileNameDialog.xaml.cs │ └── Routing │ │ ├── ProvideToolboxControlAttribute.cs │ │ ├── RoutingItem.cs │ │ ├── RoutingWindow.cs │ │ ├── RoutingWindowControl.xaml │ │ └── RoutingWindowControl.xaml.cs │ ├── Extensions │ ├── EnvDteExtensionMethods.cs │ ├── ProjectHelpers.cs │ ├── StringExtensions.cs │ └── TypeDefinitionExtensions.cs │ ├── Properties │ └── AssemblyInfo.cs │ ├── Resources │ ├── CSFileNode.png │ ├── CSRazorFile.png │ ├── Icon.png │ ├── Images.png │ ├── JSScript.png │ ├── StyleSheet.png │ └── bunit.png │ ├── Singletons │ └── ComponentNameProvider.cs │ ├── VSCommandTable.cs │ ├── VSCommandTable.vsct │ ├── source.extension.cs │ └── source.extension.vsixmanifest ├── Images ├── ComponentUsagesExample.png ├── RazorMenuContext.png ├── Routes.png ├── SolutionRazorContext.png ├── SolutionRazorCsContext.png └── bUnit.png ├── LICENSE └── README.md /.github/FUNDING.yml: -------------------------------------------------------------------------------- 1 | # These are supported funding model platforms 2 | github: EngstromJimmy 3 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | ## Ignore Visual Studio temporary files, build results, and 2 | ## files generated by popular Visual Studio add-ons. 3 | ## 4 | ## Get latest from https://github.com/github/gitignore/blob/main/VisualStudio.gitignore 5 | 6 | # User-specific files 7 | *.rsuser 8 | *.suo 9 | *.user 10 | *.userosscache 11 | *.sln.docstates 12 | 13 | # User-specific files (MonoDevelop/Xamarin Studio) 14 | *.userprefs 15 | 16 | # Mono auto generated files 17 | mono_crash.* 18 | 19 | # Build results 20 | [Dd]ebug/ 21 | [Dd]ebugPublic/ 22 | [Rr]elease/ 23 | [Rr]eleases/ 24 | x64/ 25 | x86/ 26 | [Ww][Ii][Nn]32/ 27 | [Aa][Rr][Mm]/ 28 | [Aa][Rr][Mm]64/ 29 | bld/ 30 | [Bb]in/ 31 | [Oo]bj/ 32 | [Ll]og/ 33 | [Ll]ogs/ 34 | 35 | # Visual Studio 2015/2017 cache/options directory 36 | .vs/ 37 | # Uncomment if you have tasks that create the project's static files in wwwroot 38 | #wwwroot/ 39 | 40 | # Visual Studio 2017 auto generated files 41 | Generated\ Files/ 42 | 43 | # MSTest test Results 44 | [Tt]est[Rr]esult*/ 45 | [Bb]uild[Ll]og.* 46 | 47 | # NUnit 48 | *.VisualState.xml 49 | TestResult.xml 50 | nunit-*.xml 51 | 52 | # Build Results of an ATL Project 53 | [Dd]ebugPS/ 54 | [Rr]eleasePS/ 55 | dlldata.c 56 | 57 | # Benchmark Results 58 | BenchmarkDotNet.Artifacts/ 59 | 60 | # .NET Core 61 | project.lock.json 62 | project.fragment.lock.json 63 | artifacts/ 64 | 65 | # ASP.NET Scaffolding 66 | ScaffoldingReadMe.txt 67 | 68 | # StyleCop 69 | StyleCopReport.xml 70 | 71 | # Files built by Visual Studio 72 | *_i.c 73 | *_p.c 74 | *_h.h 75 | *.ilk 76 | *.meta 77 | *.obj 78 | *.iobj 79 | *.pch 80 | *.pdb 81 | *.ipdb 82 | *.pgc 83 | *.pgd 84 | *.rsp 85 | *.sbr 86 | *.tlb 87 | *.tli 88 | *.tlh 89 | *.tmp 90 | *.tmp_proj 91 | *_wpftmp.csproj 92 | *.log 93 | *.tlog 94 | *.vspscc 95 | *.vssscc 96 | .builds 97 | *.pidb 98 | *.svclog 99 | *.scc 100 | 101 | # Chutzpah Test files 102 | _Chutzpah* 103 | 104 | # Visual C++ cache files 105 | ipch/ 106 | *.aps 107 | *.ncb 108 | *.opendb 109 | *.opensdf 110 | *.sdf 111 | *.cachefile 112 | *.VC.db 113 | *.VC.VC.opendb 114 | 115 | # Visual Studio profiler 116 | *.psess 117 | *.vsp 118 | *.vspx 119 | *.sap 120 | 121 | # Visual Studio Trace Files 122 | *.e2e 123 | 124 | # TFS 2012 Local Workspace 125 | $tf/ 126 | 127 | # Guidance Automation Toolkit 128 | *.gpState 129 | 130 | # ReSharper is a .NET coding add-in 131 | _ReSharper*/ 132 | *.[Rr]e[Ss]harper 133 | *.DotSettings.user 134 | 135 | # TeamCity is a build add-in 136 | _TeamCity* 137 | 138 | # DotCover is a Code Coverage Tool 139 | *.dotCover 140 | 141 | # AxoCover is a Code Coverage Tool 142 | .axoCover/* 143 | !.axoCover/settings.json 144 | 145 | # Coverlet is a free, cross platform Code Coverage Tool 146 | coverage*.json 147 | coverage*.xml 148 | coverage*.info 149 | 150 | # Visual Studio code coverage results 151 | *.coverage 152 | *.coveragexml 153 | 154 | # NCrunch 155 | _NCrunch_* 156 | .*crunch*.local.xml 157 | nCrunchTemp_* 158 | 159 | # MightyMoose 160 | *.mm.* 161 | AutoTest.Net/ 162 | 163 | # Web workbench (sass) 164 | .sass-cache/ 165 | 166 | # Installshield output folder 167 | [Ee]xpress/ 168 | 169 | # DocProject is a documentation generator add-in 170 | DocProject/buildhelp/ 171 | DocProject/Help/*.HxT 172 | DocProject/Help/*.HxC 173 | DocProject/Help/*.hhc 174 | DocProject/Help/*.hhk 175 | DocProject/Help/*.hhp 176 | DocProject/Help/Html2 177 | DocProject/Help/html 178 | 179 | # Click-Once directory 180 | publish/ 181 | 182 | # Publish Web Output 183 | *.[Pp]ublish.xml 184 | *.azurePubxml 185 | # Note: Comment the next line if you want to checkin your web deploy settings, 186 | # but database connection strings (with potential passwords) will be unencrypted 187 | *.pubxml 188 | *.publishproj 189 | 190 | # Microsoft Azure Web App publish settings. Comment the next line if you want to 191 | # checkin your Azure Web App publish settings, but sensitive information contained 192 | # in these scripts will be unencrypted 193 | PublishScripts/ 194 | 195 | # NuGet Packages 196 | *.nupkg 197 | # NuGet Symbol Packages 198 | *.snupkg 199 | # The packages folder can be ignored because of Package Restore 200 | **/[Pp]ackages/* 201 | # except build/, which is used as an MSBuild target. 202 | !**/[Pp]ackages/build/ 203 | # Uncomment if necessary however generally it will be regenerated when needed 204 | #!**/[Pp]ackages/repositories.config 205 | # NuGet v3's project.json files produces more ignorable files 206 | *.nuget.props 207 | *.nuget.targets 208 | 209 | # Microsoft Azure Build Output 210 | csx/ 211 | *.build.csdef 212 | 213 | # Microsoft Azure Emulator 214 | ecf/ 215 | rcf/ 216 | 217 | # Windows Store app package directories and files 218 | AppPackages/ 219 | BundleArtifacts/ 220 | Package.StoreAssociation.xml 221 | _pkginfo.txt 222 | *.appx 223 | *.appxbundle 224 | *.appxupload 225 | 226 | # Visual Studio cache files 227 | # files ending in .cache can be ignored 228 | *.[Cc]ache 229 | # but keep track of directories ending in .cache 230 | !?*.[Cc]ache/ 231 | 232 | # Others 233 | ClientBin/ 234 | ~$* 235 | *~ 236 | *.dbmdl 237 | *.dbproj.schemaview 238 | *.jfm 239 | *.pfx 240 | *.publishsettings 241 | orleans.codegen.cs 242 | 243 | # Including strong name files can present a security risk 244 | # (https://github.com/github/gitignore/pull/2483#issue-259490424) 245 | #*.snk 246 | 247 | # Since there are multiple workflows, uncomment next line to ignore bower_components 248 | # (https://github.com/github/gitignore/pull/1529#issuecomment-104372622) 249 | #bower_components/ 250 | 251 | # RIA/Silverlight projects 252 | Generated_Code/ 253 | 254 | # Backup & report files from converting an old project file 255 | # to a newer Visual Studio version. Backup files are not needed, 256 | # because we have git ;-) 257 | _UpgradeReport_Files/ 258 | Backup*/ 259 | UpgradeLog*.XML 260 | UpgradeLog*.htm 261 | ServiceFabricBackup/ 262 | *.rptproj.bak 263 | 264 | # SQL Server files 265 | *.mdf 266 | *.ldf 267 | *.ndf 268 | 269 | # Business Intelligence projects 270 | *.rdl.data 271 | *.bim.layout 272 | *.bim_*.settings 273 | *.rptproj.rsuser 274 | *- [Bb]ackup.rdl 275 | *- [Bb]ackup ([0-9]).rdl 276 | *- [Bb]ackup ([0-9][0-9]).rdl 277 | 278 | # Microsoft Fakes 279 | FakesAssemblies/ 280 | 281 | # GhostDoc plugin setting file 282 | *.GhostDoc.xml 283 | 284 | # Node.js Tools for Visual Studio 285 | .ntvs_analysis.dat 286 | node_modules/ 287 | 288 | # Visual Studio 6 build log 289 | *.plg 290 | 291 | # Visual Studio 6 workspace options file 292 | *.opt 293 | 294 | # Visual Studio 6 auto-generated workspace file (contains which files were open etc.) 295 | *.vbw 296 | 297 | # Visual Studio 6 auto-generated project file (contains which files were open etc.) 298 | *.vbp 299 | 300 | # Visual Studio 6 workspace and project file (working project files containing files to include in project) 301 | *.dsw 302 | *.dsp 303 | 304 | # Visual Studio 6 technical files 305 | *.ncb 306 | *.aps 307 | 308 | # Visual Studio LightSwitch build output 309 | **/*.HTMLClient/GeneratedArtifacts 310 | **/*.DesktopClient/GeneratedArtifacts 311 | **/*.DesktopClient/ModelManifest.xml 312 | **/*.Server/GeneratedArtifacts 313 | **/*.Server/ModelManifest.xml 314 | _Pvt_Extensions 315 | 316 | # Paket dependency manager 317 | .paket/paket.exe 318 | paket-files/ 319 | 320 | # FAKE - F# Make 321 | .fake/ 322 | 323 | # CodeRush personal settings 324 | .cr/personal 325 | 326 | # Python Tools for Visual Studio (PTVS) 327 | __pycache__/ 328 | *.pyc 329 | 330 | # Cake - Uncomment if you are using it 331 | # tools/** 332 | # !tools/packages.config 333 | 334 | # Tabs Studio 335 | *.tss 336 | 337 | # Telerik's JustMock configuration file 338 | *.jmconfig 339 | 340 | # BizTalk build output 341 | *.btp.cs 342 | *.btm.cs 343 | *.odx.cs 344 | *.xsd.cs 345 | 346 | # OpenCover UI analysis results 347 | OpenCover/ 348 | 349 | # Azure Stream Analytics local run output 350 | ASALocalRun/ 351 | 352 | # MSBuild Binary and Structured Log 353 | *.binlog 354 | 355 | # NVidia Nsight GPU debugger configuration file 356 | *.nvuser 357 | 358 | # MFractors (Xamarin productivity tool) working folder 359 | .mfractor/ 360 | 361 | # Local History for Visual Studio 362 | .localhistory/ 363 | 364 | # Visual Studio History (VSHistory) files 365 | .vshistory/ 366 | 367 | # BeatPulse healthcheck temp database 368 | healthchecksdb 369 | 370 | # Backup folder for Package Reference Convert tool in Visual Studio 2017 371 | MigrationBackup/ 372 | 373 | # Ionide (cross platform F# VS Code tools) working folder 374 | .ionide/ 375 | 376 | # Fody - auto-generated XML schema 377 | FodyWeavers.xsd 378 | 379 | # VS Code files for those working on multiple tools 380 | .vscode/* 381 | !.vscode/settings.json 382 | !.vscode/tasks.json 383 | !.vscode/launch.json 384 | !.vscode/extensions.json 385 | *.code-workspace 386 | 387 | # Local History for Visual Studio Code 388 | .history/ 389 | 390 | # Windows Installer files from build outputs 391 | *.cab 392 | *.msi 393 | *.msix 394 | *.msm 395 | *.msp 396 | 397 | # JetBrains Rider 398 | *.sln.iml 399 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension.Tests/BlazmExtension.Tests.csproj: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | net8.0 5 | enable 6 | enable 7 | 8 | false 9 | true 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension.Tests/ExtensionTests.cs: -------------------------------------------------------------------------------- 1 | using BlazmExtension.Extensions; 2 | 3 | namespace BlazmExtension.Tests 4 | { 5 | [TestClass] 6 | public class ExtensionTests 7 | { 8 | [DataRow(null, 0, null)] 9 | [DataRow("", 0, null)] 10 | [DataRow(" ", 0, null)] 11 | [DataRow("

", 16, null)] // very end of string 12 | [DataRow("

", 15, "em")] 13 | [DataRow("

", 14, "em")] 14 | [DataRow("

", 13, "em")] 15 | [DataRow("

", 12, "em")] 16 | [DataRow("

", 11, null)] // before "" 17 | [DataRow("

", 10, "em")] 18 | [DataRow("

", 9, "em")] 19 | [DataRow("

", 8, "em")] 20 | [DataRow("

", 7, null)] // before "" 21 | [DataRow("

", 6, "p")] 22 | [DataRow("

", 5, "p")] 23 | [DataRow("

", 4, "p")] 24 | [DataRow("

", 3, null)] // before "

" 25 | [DataRow("

", 2, "p")] 26 | [DataRow("

", 1, "p")] 27 | [DataRow("

", 0, null)] // very start of string 28 | 29 | [DataRow("

stuff

", 21, null)] // very end of string 30 | [DataRow("

stuff

", 20, "p")] 31 | [DataRow("

stuff

", 18, "p")] 32 | [DataRow("

stuff

", 17, null)] // after "
" before "

" 33 | [DataRow("

stuff

", 16, "em")] 34 | [DataRow("

stuff

", 13, "em")] 35 | [DataRow("

stuff

", 12, null)] // before " 36 | [DataRow("

stuff

", 7, null)] // after "" 37 | [DataRow("

stuff

", 6, "em")] 38 | [DataRow("

stuff

", 5, "em")] 39 | [DataRow("

stuff

", 4, "em")] 40 | [DataRow("

stuff

", 3, null)] // before "

" and "" 41 | [DataRow("

stuff

", 1, "p")] 42 | [DataRow("

stuff

", 2, "p")] 43 | [DataRow("

stuff

", 0, null)] // before '<' 44 | [TestMethod] 45 | public void GetComponentNameOnCursor(string lineText, int cursorPosition, string expectedComponentName) 46 | { 47 | var componentName = lineText.GetComponentNameOnCursor(cursorPosition); 48 | Assert.AreEqual(expectedComponentName, componentName); 49 | } 50 | 51 | 52 | } 53 | } -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension.Tests/GlobalUsings.cs: -------------------------------------------------------------------------------- 1 | global using Microsoft.VisualStudio.TestTools.UnitTesting; -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension.sln: -------------------------------------------------------------------------------- 1 |  2 | Microsoft Visual Studio Solution File, Format Version 12.00 3 | # Visual Studio Version 17 4 | VisualStudioVersion = 17.6.33513.286 5 | MinimumVisualStudioVersion = 10.0.40219.1 6 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazmExtension", "BlazmExtension\BlazmExtension.csproj", "{A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}" 7 | EndProject 8 | Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BlazmExtension.Tests", "BlazmExtension.Tests\BlazmExtension.Tests.csproj", "{20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}" 9 | EndProject 10 | Global 11 | GlobalSection(SolutionConfigurationPlatforms) = preSolution 12 | Debug|Any CPU = Debug|Any CPU 13 | Debug|arm64 = Debug|arm64 14 | Debug|x86 = Debug|x86 15 | Release|Any CPU = Release|Any CPU 16 | Release|arm64 = Release|arm64 17 | Release|x86 = Release|x86 18 | EndGlobalSection 19 | GlobalSection(ProjectConfigurationPlatforms) = postSolution 20 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 21 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Debug|Any CPU.Build.0 = Debug|Any CPU 22 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Debug|arm64.ActiveCfg = Debug|arm64 23 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Debug|arm64.Build.0 = Debug|arm64 24 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Debug|x86.ActiveCfg = Debug|x86 25 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Debug|x86.Build.0 = Debug|x86 26 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Release|Any CPU.ActiveCfg = Release|Any CPU 27 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Release|Any CPU.Build.0 = Release|Any CPU 28 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Release|arm64.ActiveCfg = Release|arm64 29 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Release|arm64.Build.0 = Release|arm64 30 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Release|x86.ActiveCfg = Release|x86 31 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664}.Release|x86.Build.0 = Release|x86 32 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Debug|Any CPU.ActiveCfg = Debug|Any CPU 33 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Debug|Any CPU.Build.0 = Debug|Any CPU 34 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Debug|arm64.ActiveCfg = Debug|Any CPU 35 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Debug|arm64.Build.0 = Debug|Any CPU 36 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Debug|x86.ActiveCfg = Debug|Any CPU 37 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Debug|x86.Build.0 = Debug|Any CPU 38 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Release|Any CPU.ActiveCfg = Release|Any CPU 39 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Release|Any CPU.Build.0 = Release|Any CPU 40 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Release|arm64.ActiveCfg = Release|Any CPU 41 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Release|arm64.Build.0 = Release|Any CPU 42 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Release|x86.ActiveCfg = Release|Any CPU 43 | {20AE9FEC-3E7C-4FE5-AC8A-10FFBA935246}.Release|x86.Build.0 = Release|Any CPU 44 | EndGlobalSection 45 | GlobalSection(SolutionProperties) = preSolution 46 | HideSolutionNode = FALSE 47 | EndGlobalSection 48 | GlobalSection(ExtensibilityGlobals) = postSolution 49 | SolutionGuid = {83195532-D0CD-48F5-9790-390DB385DAF8} 50 | EndGlobalSection 51 | EndGlobal 52 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/BlazmExtension.csproj: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | $(MSBuildExtensionsPath32)\Microsoft\VisualStudio\v$(VisualStudioVersion) 5 | latest 6 | 7 | 8 | 9 | Debug 10 | AnyCPU 11 | 2.0 12 | {82b43b9b-a64c-4715-b499-d71e9ca2bd60};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC} 13 | {A11ACA63-2F3C-4EAB-802B-6CBDA22E3664} 14 | Library 15 | Properties 16 | BlazmExtension 17 | BlazmExtension 18 | v4.8 19 | true 20 | true 21 | true 22 | true 23 | false 24 | true 25 | true 26 | Program 27 | $(DevEnvDir)devenv.exe 28 | /rootsuffix Exp 29 | 30 | 31 | true 32 | full 33 | false 34 | bin\Debug\ 35 | DEBUG;TRACE 36 | prompt 37 | 4 38 | 39 | 40 | pdbonly 41 | true 42 | bin\Release\ 43 | TRACE 44 | prompt 45 | 4 46 | 47 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | ComponentReferencesControl.xaml 63 | 64 | 65 | 66 | FileNameDialog.xaml 67 | 68 | 69 | 70 | 71 | 72 | RoutingWindowControl.xaml 73 | 74 | 75 | 76 | 77 | 78 | 79 | 80 | 81 | 82 | 83 | True 84 | True 85 | source.extension.vsixmanifest 86 | 87 | 88 | True 89 | True 90 | VSCommandTable.vsct 91 | 92 | 93 | 94 | 95 | 96 | 97 | 98 | 99 | 100 | Designer 101 | VsixManifestGenerator 102 | source.extension.cs 103 | 104 | 105 | 106 | PreserveNewest 107 | true 108 | 109 | 110 | 111 | 112 | Menus.ctmenu 113 | VsctGenerator 114 | VSCommandTable.cs 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 | 128 | 129 | 130 | compile; build; native; contentfiles; analyzers; buildtransitive 131 | 132 | 133 | 6.0.16 134 | 135 | 136 | 4.5.0 137 | 138 | 139 | 17.4.33103.184 140 | 141 | 142 | runtime; build; native; contentfiles; analyzers; buildtransitive 143 | all 144 | 145 | 146 | 0.11.5 147 | 148 | 149 | 150 | 151 | Designer 152 | MSBuild:Compile 153 | 154 | 155 | MSBuild:Compile 156 | Designer 157 | 158 | 159 | MSBuild:Compile 160 | Designer 161 | 162 | 163 | 164 | 165 | 166 | 173 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/BlazmExtensionPackage.cs: -------------------------------------------------------------------------------- 1 | global using Community.VisualStudio.Toolkit; 2 | global using Microsoft.VisualStudio.Shell; 3 | global using System; 4 | global using Task = System.Threading.Tasks.Task; 5 | using BlazmExtension.Dialogs.Routing; 6 | using BlazmExtension.Dialogs.ComponentReferences; 7 | using Microsoft.VisualStudio.Shell.Interop; 8 | using System.Runtime.InteropServices; 9 | using System.Threading; 10 | 11 | namespace BlazmExtension 12 | { 13 | [ProvideToolWindow(typeof(ComponentReferencesWindow))] 14 | [ProvideToolWindow(typeof(RoutingWindow))] 15 | [ProvideAutoLoad(UIContextGuids80.SolutionExists, PackageAutoLoadFlags.BackgroundLoad)] 16 | [PackageRegistration(UseManagedResourcesOnly = true, AllowsBackgroundLoading = true)] 17 | [InstalledProductRegistration(Vsix.Name, Vsix.Description, Vsix.Version)] 18 | [ProvideMenuResource("Menus.ctmenu", 1)] 19 | [ProvideUIContextRule(PackageGuids.RazorContextGuidString, 20 | name: nameof(PackageGuids.RazorContextGuidString), 21 | expression: "DotRazor", 22 | termNames: new[] { "DotRazor" }, 23 | termValues: new[] { "HierSingleSelectionName:.razor$" })] 24 | [ProvideUIContextRule(PackageGuids.RazorCsContextGuidString, 25 | name: nameof(PackageGuids.RazorCsContextGuidString), 26 | expression: "DotRazorcs", 27 | termNames: new[] { "DotRazorcs" }, 28 | termValues: new[] { "HierSingleSelectionName:.razor.cs$" })] 29 | [Guid(PackageGuids.BlazmExtensionString)] 30 | public sealed class BlazmExtensionPackage : ToolkitPackage 31 | { 32 | protected override async Task InitializeAsync(CancellationToken cancellationToken, IProgress progress) 33 | { 34 | await this.RegisterCommandsAsync(); 35 | } 36 | } 37 | } -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/CreateCodebehindCommand.cs: -------------------------------------------------------------------------------- 1 | using System.Collections.Generic; 2 | using EnvDTE; 3 | using EnvDTE80; 4 | using System.IO; 5 | using System.Linq; 6 | using System.Text; 7 | using System.Text.RegularExpressions; 8 | using System.Windows.Documents; 9 | 10 | namespace BlazmExtension 11 | { 12 | [Command(PackageIds.CreateCodebehind)] 13 | internal sealed class CreateICodebehindCommand : BaseCommand 14 | { 15 | protected override Task InitializeCompletedAsync() 16 | { 17 | Command.Supported = false; 18 | return base.InitializeCompletedAsync(); 19 | } 20 | 21 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 22 | { 23 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 24 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 25 | UIHierarchy uih = (UIHierarchy)dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object; 26 | Array selectedItems = (Array)uih.SelectedItems; 27 | foreach (UIHierarchyItem selItem in selectedItems) 28 | { 29 | ProjectItem projectItem = selItem.Object as ProjectItem; 30 | 31 | if (projectItem != null) 32 | { 33 | string razorFilePath = projectItem.FileNames[1]; 34 | 35 | string fileText = File.ReadAllText(razorFilePath); 36 | string razorNamespace = ""; 37 | List typeParamInfos = GetTypeParametersWithConstraints(fileText); 38 | 39 | // A very simple example of parsing the namespace from the Razor file 40 | string namespaceDirective = "@namespace"; 41 | int namespaceIndex = fileText.IndexOf(namespaceDirective); 42 | 43 | if (namespaceIndex != -1) 44 | { 45 | int namespaceStart = namespaceIndex + namespaceDirective.Length; 46 | 47 | // This assumes that the namespace directive is followed by a space, 48 | // and the namespace ends with a newline. Adjust if necessary. 49 | int namespaceEnd = fileText.IndexOf(Environment.NewLine, namespaceStart); 50 | 51 | if (namespaceEnd != -1) 52 | { 53 | razorNamespace = fileText.Substring(namespaceStart, namespaceEnd - namespaceStart).Trim(); 54 | } 55 | else 56 | { 57 | // If there's no newline after the namespace directive, just take everything that follows it 58 | razorNamespace = fileText.Substring(namespaceStart).Trim(); 59 | } 60 | } 61 | 62 | 63 | 64 | if (string.IsNullOrEmpty(razorNamespace)) 65 | { 66 | 67 | // Get the path to the project and the file 68 | string projectPath = Path.GetDirectoryName(projectItem.ContainingProject.FullName); 69 | string filePath = Path.GetDirectoryName(projectItem.FileNames[1]); 70 | 71 | // Get the default namespace of the project 72 | string defaultNamespace = projectItem.ContainingProject.Properties.Item("DefaultNamespace").Value.ToString(); 73 | 74 | // Remove the project path from the file path 75 | string relativePath = filePath.Substring(projectPath.Length); 76 | 77 | // Remove leading directory separator if it exists 78 | if (relativePath.StartsWith(Path.DirectorySeparatorChar.ToString())) 79 | { 80 | relativePath = relativePath.Substring(1); 81 | } 82 | 83 | // Replace the directory separator characters with dots 84 | string namespaceSuffix = relativePath.Replace(Path.DirectorySeparatorChar, '.'); 85 | 86 | // Concatenate the default namespace with the namespace suffix to get the full namespace 87 | razorNamespace = string.IsNullOrEmpty(namespaceSuffix) ? defaultNamespace : $"{defaultNamespace}.{namespaceSuffix}"; 88 | 89 | } 90 | 91 | string fullPath = projectItem.Properties.Item("FullPath").Value.ToString(); 92 | 93 | var newfilePath = fullPath + ".cs"; 94 | if (!File.Exists(newfilePath)) 95 | { 96 | StringBuilder content = new StringBuilder(); 97 | content.AppendLine($"namespace {razorNamespace};"); 98 | content.Append($"public partial class {Path.GetFileNameWithoutExtension(fullPath)}"); 99 | if (typeParamInfos is { Count: > 0 }) 100 | { 101 | var typeParamsStr = $"<{string.Join(", ", typeParamInfos.Select(x => x.Name))}>"; 102 | var typeParamConstraints = string.Join(" ", typeParamInfos.Select(x => x.Constraint).Where(x => !string.IsNullOrWhiteSpace(x))); 103 | 104 | content.Append(typeParamsStr); 105 | if (!string.IsNullOrWhiteSpace(typeParamConstraints)) 106 | { 107 | content.Append($" {typeParamConstraints}"); 108 | } 109 | } 110 | content.AppendLine(); 111 | content.AppendLine("{"); 112 | content.AppendLine(""); 113 | content.AppendLine("}"); 114 | 115 | File.WriteAllText(newfilePath, content.ToString()); 116 | } 117 | } 118 | } 119 | } 120 | 121 | private List GetTypeParametersWithConstraints(string fileStr) 122 | { 123 | Regex regex = new Regex(@"@typeparam\s+(\w+)\s*(where\s+\w+\s*:\s*\w+)*"); 124 | MatchCollection matches = regex.Matches(fileStr); 125 | 126 | List typeParamtersWithConstraints = new (); 127 | foreach (Match match in matches) 128 | { 129 | string typeParam = match.Groups[1].Value; 130 | string constraint = match.Groups[2].Value; 131 | 132 | 133 | typeParamtersWithConstraints.Add(new (typeParam, constraint)); 134 | } 135 | return typeParamtersWithConstraints; 136 | } 137 | 138 | internal sealed record TypeParamInfo(string Name, string Constraint); 139 | } 140 | } 141 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/CreateIsolatedCssCommand.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using System.IO; 4 | 5 | namespace BlazmExtension 6 | { 7 | [Command(PackageIds.CreateIsolatedCss)] 8 | internal sealed class CreateIsolatedCssCommand : BaseCommand 9 | { 10 | protected override Task InitializeCompletedAsync() 11 | { 12 | Command.Supported = false; 13 | return base.InitializeCompletedAsync(); 14 | } 15 | 16 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 17 | { 18 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 19 | UIHierarchy uih = (UIHierarchy)dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object; 20 | Array selectedItems = (Array)uih.SelectedItems; 21 | foreach (UIHierarchyItem selItem in selectedItems) 22 | { 23 | ProjectItem prjItem = selItem.Object as ProjectItem; 24 | string filePath = prjItem.Properties.Item("FullPath").Value.ToString(); 25 | 26 | var newfilePath = filePath + ".css"; 27 | if (!File.Exists(newfilePath)) 28 | { 29 | File.WriteAllText(newfilePath, ""); 30 | } 31 | } 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/CreateIsolatedJavaScriptCommand.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using Microsoft.VisualStudio.Shell; 4 | using Microsoft.VisualStudio.Shell.Interop; 5 | using System.ComponentModel.Design; 6 | using System.IO; 7 | using System.Linq; 8 | using System.Security.Policy; 9 | 10 | namespace BlazmExtension 11 | { 12 | [Command(PackageIds.CreateIsolatedJavaScript)] 13 | internal sealed class CreateIsolatedJavaScriptCommand : BaseCommand 14 | { 15 | 16 | protected override Task InitializeCompletedAsync() 17 | { 18 | Command.Supported = false; 19 | return base.InitializeCompletedAsync(); 20 | } 21 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 22 | { 23 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 24 | UIHierarchy uih = (UIHierarchy)dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object; 25 | Array selectedItems = (Array)uih.SelectedItems; 26 | foreach (UIHierarchyItem selItem in selectedItems) 27 | { 28 | ProjectItem prjItem = selItem.Object as ProjectItem; 29 | string filePath = prjItem.Properties.Item("FullPath").Value.ToString(); 30 | 31 | var newfilePath = filePath + ".js"; 32 | if (!File.Exists(newfilePath)) 33 | { 34 | File.WriteAllText(newfilePath, ""); 35 | } 36 | } 37 | } 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/CreatebUnitTestCsCommand.cs: -------------------------------------------------------------------------------- 1 | using BlazmExtension.Extensions; 2 | using EnvDTE; 3 | using EnvDTE80; 4 | using Microsoft.ServiceHub.Framework.Services; 5 | using Mono.Cecil; 6 | using Mono.Cecil.Cil; 7 | using System.Collections.Generic; 8 | using System.IO; 9 | using System.Linq; 10 | using System.Management; 11 | using System.Net.Http; 12 | using System.Reflection.Emit; 13 | using System.Text; 14 | using System.Windows.Forms; 15 | using static BlazmExtension.Dialogs.Routing.RoutingWindowControl; 16 | 17 | namespace BlazmExtension 18 | { 19 | [Command(PackageIds.CreatebUnitTestCs)] 20 | internal sealed class CreatebUnitTestCsCommand : BaseCommand 21 | { 22 | public bool RenderAsRazor = false; 23 | protected override Task InitializeCompletedAsync() 24 | { 25 | Command.Supported = false; 26 | return base.InitializeCompletedAsync(); 27 | } 28 | 29 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 30 | { 31 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 32 | UIHierarchy uih = (UIHierarchy)dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object; 33 | Array selectedItems = (Array)uih.SelectedItems; 34 | 35 | var items = ProjectHelpers.GetAllRazorComponentsFromAssembly(dte.Solution); 36 | foreach (UIHierarchyItem selItem in selectedItems) 37 | { 38 | ProjectItem prjItem = selItem.Object as ProjectItem; 39 | string filePath = prjItem.Properties.Item("FullPath").Value.ToString(); 40 | 41 | var type = items.FirstOrDefault(c => c.Path == filePath); 42 | if (type == null) 43 | { 44 | type = items.FirstOrDefault(c => c.Name == Path.GetFileNameWithoutExtension(filePath)); 45 | } 46 | 47 | if (type == null) 48 | { 49 | System.Windows.Forms.MessageBox.Show("Could not find component, you can try to build you project first"); 50 | } 51 | 52 | //Generate bUnit test in xUnit based on type name, inject, etc 53 | var test = GenerateTest(type.TypeDefinition); 54 | Clipboard.SetText(test); 55 | } 56 | 57 | 58 | } 59 | 60 | 61 | 62 | 63 | 64 | public string GenerateTest(TypeDefinition type) 65 | { 66 | var sb = new StringBuilder(); 67 | sb.AppendLine($" public class {type.Name}Tests : TestContext"); 68 | 69 | sb.AppendLine(" {"); 70 | sb.AppendLine($" [Fact]"); 71 | sb.AppendLine($" public void {type.Name}Test()"); 72 | sb.AppendLine(" {"); 73 | sb.AppendLine($" //Arrange"); 74 | //Add injects 75 | sb.Append(type.GetInjectDeclarations()); 76 | sb.Append(type.GetParameterDeclarations(false)); 77 | 78 | sb.Append($" var cut = RenderComponent<{type.Name}>("); 79 | if (type.GetParameters().Any()) 80 | { 81 | sb.AppendLine("parameters => parameters"); 82 | //Todo: Add Childcontent parameters and RenderFragments 83 | 84 | 85 | foreach (var property in type.GetParameters()) 86 | { 87 | if (property.Name == "ChildContent") 88 | { 89 | sb.AppendLine($" .AddChildContent({TypeDefinitionExtensions.FirstCharToLowerCase(property.Name)})"); 90 | } 91 | else 92 | { 93 | sb.AppendLine($" .Add(p => p.{property.Name}, {TypeDefinitionExtensions.FirstCharToLowerCase(property.Name)})"); 94 | } 95 | } 96 | foreach (var property in type.GetCascadingParameters()) 97 | { 98 | sb.AppendLine($" .Add(p => p.{property.Name}, {TypeDefinitionExtensions.FirstCharToLowerCase(property.Name)})"); 99 | 100 | } 101 | } 102 | sb.AppendLine($" );"); 103 | 104 | //Handle EventCallbacks 105 | //Handle ChildContent 106 | //Handle RenderFragments 107 | //Handle RenderFragment 108 | 109 | 110 | 111 | 112 | 113 | sb.AppendLine($" //Act"); 114 | sb.AppendLine($""); 115 | sb.AppendLine($" //Assert"); 116 | sb.AppendLine(" }"); 117 | sb.AppendLine(" }"); 118 | 119 | return sb.ToString(); 120 | } 121 | } 122 | } 123 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/CreatebUnitTestRazorCommand.cs: -------------------------------------------------------------------------------- 1 | using BlazmExtension.Extensions; 2 | using Community.VisualStudio.Toolkit; 3 | using EnvDTE; 4 | using EnvDTE80; 5 | using Microsoft.ServiceHub.Framework.Services; 6 | using Mono.Cecil; 7 | using Mono.Cecil.Cil; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Management; 12 | using System.Net.Http; 13 | using System.Reflection.Emit; 14 | using System.Text; 15 | using System.Windows.Forms; 16 | using static BlazmExtension.Dialogs.Routing.RoutingWindowControl; 17 | 18 | namespace BlazmExtension 19 | { 20 | [Command(PackageIds.CreatebUnitTestRazor)] 21 | internal sealed class CreatebUnitTestRazorCommand : BaseCommand 22 | { 23 | public bool RenderAsRazor = true; 24 | protected override Task InitializeCompletedAsync() 25 | { 26 | Command.Supported = false; 27 | return base.InitializeCompletedAsync(); 28 | } 29 | 30 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 31 | { 32 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 33 | UIHierarchy uih = (UIHierarchy)dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object; 34 | Array selectedItems = (Array)uih.SelectedItems; 35 | 36 | var items = ProjectHelpers.GetAllRazorComponentsFromAssembly(dte.Solution); 37 | foreach (UIHierarchyItem selItem in selectedItems) 38 | { 39 | ProjectItem prjItem = selItem.Object as ProjectItem; 40 | string filePath = prjItem.Properties.Item("FullPath").Value.ToString(); 41 | 42 | var type = items.FirstOrDefault(c => c.Path == filePath); 43 | if (type == null) 44 | { 45 | type = items.FirstOrDefault(c => c.Name == Path.GetFileNameWithoutExtension(filePath)); 46 | } 47 | 48 | if (type == null) 49 | { 50 | System.Windows.Forms.MessageBox.Show("Could not find component, you can try to build you project first"); 51 | } 52 | 53 | //Generate bUnit test in xUnit based on type name, inject, etc 54 | var test = GenerateTest(type.TypeDefinition); 55 | Clipboard.SetText(test); 56 | } 57 | 58 | 59 | } 60 | 61 | 62 | public string GenerateTest(TypeDefinition type) 63 | { 64 | var sb = new StringBuilder(); 65 | sb.AppendLine($"@inherits TestContext"); 66 | sb.AppendLine($"@using Bunit"); 67 | sb.AppendLine($"@using {type.Namespace};"); 68 | 69 | sb.AppendLine($"@code"); 70 | sb.AppendLine(" {"); 71 | sb.AppendLine($" [Fact]"); 72 | sb.AppendLine($" public void {type.Name}Test()"); 73 | sb.AppendLine(" {"); 74 | sb.AppendLine($" //Arrange"); 75 | sb.AppendLine(type.GetInjectDeclarations()); 76 | sb.AppendLine(type.GetParameterDeclarations()); 77 | 78 | sb.Append($" var cut = Render(@"); 79 | foreach (var property in type.GetCascadingParameters()) 80 | { 81 | sb.AppendLine($""); 82 | sb.Append(" "); 83 | } 84 | 85 | sb.AppendLine($"<{type.Name}"); 86 | foreach (var property in type.GetParametersWithoutRenderFragments()) 87 | { 88 | sb.Append(" "); 89 | sb.AppendLine($"{property.Name}=\"@{TypeDefinitionExtensions.FirstCharToLowerCase(property.Name)}\""); 90 | } 91 | sb.AppendLine(" >"); 92 | 93 | //Add all Renderfragments 94 | foreach (var property in type.GetParametersRenderFragments()) 95 | { 96 | sb.Append(" "); 97 | sb.AppendLine($"<{property.Name}>"); 98 | sb.Append($"{property.Name} fragment"); 99 | sb.AppendLine($""); 100 | } 101 | sb.AppendLine($" "); 102 | foreach (var property in type.GetCascadingParameters()) 103 | { 104 | sb.Append(" "); 105 | sb.Append($""); 106 | } 107 | sb.Append($");"); 108 | sb.AppendLine($""); 109 | sb.AppendLine($" //Act"); 110 | sb.AppendLine($""); 111 | sb.AppendLine($" //Assert"); 112 | sb.AppendLine(" }"); 113 | sb.AppendLine(" }"); 114 | 115 | return sb.ToString(); 116 | } 117 | } 118 | } 119 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/ExtractToComponent.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using Microsoft.VisualStudio.Shell; 4 | using Microsoft.VisualStudio.Shell.Interop; 5 | using Microsoft.VisualStudio.Text.Editor; 6 | using Microsoft.VisualStudio.Text; 7 | using Microsoft.VisualStudio.TextManager.Interop; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text.RegularExpressions; 12 | using System.Windows.Interop; 13 | using StageCoder; 14 | 15 | namespace BlazmExtension; 16 | 17 | [Command(PackageIds.ExtractToComponent)] 18 | internal sealed class ExtractToComponentCommand : BaseCommand 19 | { 20 | protected override Task InitializeCompletedAsync() 21 | { 22 | Command.Supported = false; 23 | return base.InitializeCompletedAsync(); 24 | } 25 | 26 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 27 | { 28 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 29 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 30 | 31 | var document = dte.ActiveDocument; 32 | var selection = (TextSelection)dte.ActiveDocument.Selection; 33 | var importsPath = Path.GetDirectoryName(document.FullName); 34 | 35 | //Get name for component 36 | string componentname = ""; 37 | System.Windows.Window window = (System.Windows.Window)HwndSource.FromHwnd(dte.MainWindow.HWnd).RootVisual; 38 | FileNameDialog dialog = new FileNameDialog() 39 | { 40 | 41 | Owner = window 42 | }; 43 | 44 | bool? result = dialog.ShowDialog(); 45 | if (result.HasValue && result.Value) 46 | { 47 | componentname = (result.HasValue && result.Value) ? dialog.Input : string.Empty; 48 | 49 | if (componentname == string.Empty) 50 | { 51 | componentname = "Component"; 52 | } 53 | componentname = Path.GetFileNameWithoutExtension(componentname); 54 | componentname = char.ToUpper(componentname[0]) + componentname.Substring(1); // capitalize the first letter 55 | 56 | var newcomponentPath = importsPath + "\\" + componentname + ".razor"; 57 | if (!File.Exists(newcomponentPath)) 58 | { 59 | File.WriteAllText(newcomponentPath, selection.Text); 60 | } 61 | 62 | selection.Text = $"<{componentname} />"; 63 | 64 | dte.ItemOperations.OpenFile(newcomponentPath); 65 | } 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/FindComponentUsagesCommand.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using Microsoft.VisualStudio.Shell.Interop; 3 | using System.Text.RegularExpressions; 4 | using BlazmExtension.Dialogs.ComponentReferences; 5 | using System.IO; 6 | using System.Text; 7 | using BlazmExtension.Extensions; 8 | 9 | namespace BlazmExtension 10 | { 11 | [Command(PackageIds.FindComponentUsages)] 12 | internal sealed class FindComponentUsagesCommand : BaseCommand 13 | { 14 | protected override Task InitializeCompletedAsync() 15 | { 16 | Command.Supported = false; 17 | return base.InitializeCompletedAsync(); 18 | } 19 | 20 | public static FindComponentUsagesCommand Instance { get; private set; } 21 | 22 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 23 | { 24 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 25 | 26 | var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE)); 27 | 28 | // Get the current document and caret position 29 | var activeDocument = dte.ActiveDocument; 30 | var textSelection = (TextSelection)activeDocument.Selection; 31 | var point = textSelection.ActivePoint; 32 | var lineText = point.CreateEditPoint().GetLines(point.Line, point.Line + 1); 33 | int cursorPos = point.DisplayColumn - 1; // Convert to 0-based indexing 34 | var componentName = lineText.GetComponentNameOnCursor(cursorPos); 35 | 36 | 37 | if (string.IsNullOrEmpty(componentName)) 38 | { 39 | try 40 | { 41 | componentName = Path.GetFileNameWithoutExtension(dte.ActiveDocument.FullName); 42 | } 43 | catch { } 44 | } 45 | 46 | if (string.IsNullOrWhiteSpace(componentName)) 47 | { 48 | VsShellUtilities.ShowMessageBox( 49 | ServiceProvider.GlobalProvider, 50 | "Unable to determine the component name.", 51 | "Error", 52 | OLEMSGICON.OLEMSGICON_CRITICAL, 53 | OLEMSGBUTTON.OLEMSGBUTTON_OK, 54 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); 55 | return; 56 | } 57 | 58 | try 59 | { 60 | ToolWindowPane window = Package.FindToolWindow(typeof(ComponentReferencesWindow), 0, true); 61 | if ((null == window) || (null == window.Frame)) 62 | { 63 | throw new NotSupportedException("Cannot create tool window"); 64 | } 65 | 66 | IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; 67 | var control = (ComponentReferencesControl)window.Content; 68 | control.Initialize(componentName); 69 | Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); 70 | } 71 | catch (Exception ex) 72 | { 73 | 74 | } 75 | } 76 | } 77 | } -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/FindComponentUsagesSECommand.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using Microsoft.VisualStudio.Shell.Interop; 3 | using System.Text.RegularExpressions; 4 | using BlazmExtension.Dialogs.ComponentReferences; 5 | using System.IO; 6 | using EnvDTE80; 7 | 8 | namespace BlazmExtension 9 | { 10 | [Command(PackageIds.FindComponentUsagesSE)] 11 | internal sealed class FindComponentUsagesSECommand : BaseCommand 12 | { 13 | protected override Task InitializeCompletedAsync() 14 | { 15 | Command.Supported = false; 16 | return base.InitializeCompletedAsync(); 17 | } 18 | 19 | public static FindComponentUsagesSECommand Instance { get; private set; } 20 | 21 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 22 | { 23 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 24 | 25 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 26 | UIHierarchy uih = (UIHierarchy)dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object; 27 | Array selectedItems = (Array)uih.SelectedItems; 28 | 29 | string fileNameWithoutExtension = null; 30 | // Ensure only one item is selected 31 | if (selectedItems.Length == 1) 32 | { 33 | UIHierarchyItem selItem = selectedItems.GetValue(0) as UIHierarchyItem; 34 | 35 | if (selItem.Object is ProjectItem prjItem) 36 | { 37 | string filePath = prjItem.Properties.Item("FullPath").Value.ToString(); 38 | 39 | // Check if the file is a Razor file 40 | if (Path.GetExtension(filePath).Equals(".razor", StringComparison.OrdinalIgnoreCase)) 41 | { 42 | fileNameWithoutExtension = Path.GetFileNameWithoutExtension(filePath); 43 | } 44 | } 45 | } 46 | else if (selectedItems.Length == 0) 47 | { 48 | VsShellUtilities.ShowMessageBox( 49 | ServiceProvider.GlobalProvider, 50 | "Error: No files selected.", 51 | "Error", 52 | OLEMSGICON.OLEMSGICON_CRITICAL, 53 | OLEMSGBUTTON.OLEMSGBUTTON_OK, 54 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); 55 | return; 56 | } 57 | else 58 | { 59 | VsShellUtilities.ShowMessageBox( 60 | ServiceProvider.GlobalProvider, 61 | "Error: Multiple files selected.", 62 | "Error", 63 | OLEMSGICON.OLEMSGICON_CRITICAL, 64 | OLEMSGBUTTON.OLEMSGBUTTON_OK, 65 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); 66 | return; 67 | } 68 | 69 | if (string.IsNullOrWhiteSpace(fileNameWithoutExtension)) 70 | { 71 | VsShellUtilities.ShowMessageBox( 72 | ServiceProvider.GlobalProvider, 73 | "Unable to determine the component name.", 74 | "Error", 75 | OLEMSGICON.OLEMSGICON_CRITICAL, 76 | OLEMSGBUTTON.OLEMSGBUTTON_OK, 77 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); 78 | return; 79 | return; 80 | } 81 | 82 | try 83 | { 84 | ToolWindowPane window = Package.FindToolWindow(typeof(ComponentReferencesWindow), 0, true); 85 | if ((null == window) || (null == window.Frame)) 86 | { 87 | throw new NotSupportedException("Cannot create tool window"); 88 | } 89 | 90 | IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; 91 | var control = (ComponentReferencesControl)window.Content; 92 | control.Initialize(fileNameWithoutExtension); 93 | Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); 94 | } 95 | catch (Exception ex) 96 | { 97 | 98 | } 99 | } 100 | } 101 | } -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/MoveCodebehindToRazor.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using Microsoft.VisualStudio.Shell; 4 | using Microsoft.VisualStudio.Shell.Interop; 5 | using Microsoft.VisualStudio.Text.Editor; 6 | using Microsoft.VisualStudio.Text; 7 | using Microsoft.VisualStudio.TextManager.Interop; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text.RegularExpressions; 12 | using System.Text; 13 | using Microsoft.CodeAnalysis.CSharp; 14 | using Microsoft.CodeAnalysis; 15 | using Microsoft.CodeAnalysis.CSharp.Syntax; 16 | using System.Diagnostics; 17 | using Microsoft.AspNetCore.Razor.Language; 18 | using Microsoft.AspNetCore.Razor.Language.Intermediate; 19 | using System; 20 | using Microsoft.VisualStudio; 21 | using System.Runtime.InteropServices; 22 | using System.Windows.Threading; 23 | 24 | namespace BlazmExtension 25 | { 26 | [Command(PackageIds.MoveCodebehind)] 27 | internal sealed class MoveCodebehindToRazorCommand : BaseCommand 28 | { 29 | protected override Task InitializeCompletedAsync() 30 | { 31 | Command.Supported = false; 32 | return base.InitializeCompletedAsync(); 33 | } 34 | 35 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 36 | { 37 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 38 | 39 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 40 | UIHierarchy uih = (UIHierarchy)dte.Windows.Item(EnvDTE.Constants.vsWindowKindSolutionExplorer).Object; 41 | Array selectedItems = (Array)uih.SelectedItems; 42 | foreach (UIHierarchyItem selItem in selectedItems) 43 | { 44 | if ((int)VSConstants.MessageBoxResult.IDOK == VsShellUtilities.ShowMessageBox( 45 | Package, 46 | "This feature is in beta, please make sure you backup or commit your razor and code-behind code", 47 | "Commit or backup your code", 48 | OLEMSGICON.OLEMSGICON_INFO, 49 | OLEMSGBUTTON.OLEMSGBUTTON_OKCANCEL, 50 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST)) 51 | { 52 | ProjectItem prjItem = selItem.Object as ProjectItem; 53 | string filePath = prjItem.Properties.Item("FullPath").Value.ToString(); 54 | 55 | 56 | if (!filePath.EndsWith(".razor.cs")) 57 | { 58 | VsShellUtilities.ShowMessageBox( 59 | Package, 60 | "Please make sure you have selected a Razor code-behind file (.razor.cs) to use this command.", 61 | "Error", 62 | OLEMSGICON.OLEMSGICON_CRITICAL, 63 | OLEMSGBUTTON.OLEMSGBUTTON_OK, 64 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); 65 | return; 66 | } 67 | 68 | var codeBehindPath = filePath; 69 | //Remove the ".cs" from the end 70 | var razorPath = Path.ChangeExtension(codeBehindPath, ""); 71 | 72 | if (!File.Exists(razorPath)) 73 | { 74 | VsShellUtilities.ShowMessageBox( 75 | Package, 76 | $"The corresponding Razor file '{razorPath}' does not exist.", 77 | "Error", 78 | OLEMSGICON.OLEMSGICON_CRITICAL, 79 | OLEMSGBUTTON.OLEMSGBUTTON_OK, 80 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); 81 | return; 82 | } 83 | 84 | var codeBehindText = File.ReadAllText(codeBehindPath); 85 | 86 | SyntaxTree tree = CSharpSyntaxTree.ParseText(codeBehindText); 87 | CompilationUnitSyntax root = tree.GetCompilationUnitRoot(); 88 | var members = tree.GetRoot().DescendantNodes().OfType(); 89 | 90 | StringBuilder methods = new(); 91 | StringBuilder usings = new(); 92 | StringBuilder fields = new(); 93 | StringBuilder properties = new(); 94 | StringBuilder inject = new(); 95 | StringBuilder attributes = new(); 96 | StringBuilder implements = new(); 97 | StringBuilder inherits = new(); 98 | StringBuilder pagedirective = new(); 99 | StringBuilder nestedclasses = new(); 100 | 101 | foreach (var u in root.Usings) 102 | { 103 | usings.AppendLine($"@{u.ToString().TrimEnd(';')}"); 104 | } 105 | 106 | foreach (var member in members) 107 | { 108 | //Any class attributes 109 | var classnode = member as ClassDeclarationSyntax; 110 | if (classnode != null) 111 | { 112 | foreach (var nestedclass in FindNestedClasses(classnode)) 113 | { 114 | nestedclasses.AppendLine(nestedclass.ToString()); 115 | } 116 | 117 | if (classnode.BaseList != null) 118 | { 119 | var list = classnode.BaseList.Types; 120 | foreach (var t in list) 121 | { 122 | if (list.ToString().StartsWith("I")) 123 | { 124 | implements.AppendLine($"@implements {t.ToString()}"); 125 | } 126 | else 127 | { 128 | inherits.AppendLine($"@inherits {t}"); 129 | } 130 | } 131 | } 132 | 133 | foreach (var al in classnode.AttributeLists) 134 | { 135 | foreach (var attribute in al.Attributes) 136 | { 137 | attributes.AppendLine($"@attribute [{attribute.ToString()}]"); 138 | } 139 | } 140 | } 141 | 142 | //If the members are not from the component class then ignore them 143 | var parent = member.Parent as ClassDeclarationSyntax; 144 | if (parent != null) 145 | { 146 | if (parent.Identifier.Text != Path.GetFileNameWithoutExtension(filePath).TrimSuffix(".razor")) 147 | { 148 | continue; 149 | } 150 | } 151 | 152 | 153 | var property = member as PropertyDeclarationSyntax; 154 | if (property != null) 155 | { 156 | //If it has an Inject attribute, then we need to add it to the razor file at the top 157 | if (HasInjectAttribute(property)) 158 | { 159 | var typename = ((IdentifierNameSyntax)property.Type).Identifier.Value; 160 | inject.AppendLine($"@inject {typename} {property.Identifier.Text}"); 161 | } 162 | else 163 | { 164 | properties.AppendLine(property.ToString()); 165 | } 166 | } 167 | 168 | var field = member as FieldDeclarationSyntax; 169 | if (field != null) 170 | { 171 | fields.AppendLine(field.ToString()); 172 | } 173 | 174 | var method = member as MethodDeclarationSyntax; 175 | if (method != null) 176 | { 177 | methods.AppendLine(method.ToString()); 178 | } 179 | } 180 | 181 | var razorContent = File.ReadAllText(razorPath); 182 | //Page 183 | var pageDirectivePattern = new Regex(@"@page\s+(?:""(?[^""]*)""|'(?[^']*)')?", RegexOptions.Multiline); 184 | var matches = pageDirectivePattern.Matches(razorContent); 185 | if (matches.Count > 0) 186 | { 187 | //Add the using to the usings sb 188 | foreach (Match match in matches) 189 | { 190 | var block = match.Groups["route"].Value; 191 | if (!ContainsLine(pagedirective, block)) 192 | { 193 | pagedirective.AppendLine($"""@page "{block}" """); 194 | } 195 | } 196 | //Remove the usings from the razor file 197 | razorContent = pageDirectivePattern.Replace(razorContent, ""); 198 | } 199 | 200 | 201 | //Usings 202 | var usingPattern = new Regex(@"@using\s+(?[\s\S]*?)(\r\n|\r|\n)", RegexOptions.Multiline); 203 | var usingMatches = usingPattern.Matches(razorContent); 204 | if (usingMatches.Count > 0) 205 | { 206 | //Add the using to the usings sb 207 | foreach (Match usingMatch in usingMatches) 208 | { 209 | var usingBlock = usingMatch.Groups["content"].Value; 210 | var newblock = $"@using {usingBlock}"; 211 | if (!ContainsLine(usings, newblock)) 212 | { 213 | usings.AppendLine(newblock); 214 | } 215 | } 216 | //Remove the usings from the razor file 217 | razorContent = usingPattern.Replace(razorContent, ""); 218 | } 219 | 220 | 221 | //Injects 222 | var injectPattern = new Regex(@"@inject\s+(?[\s\S]*?)(\r\n|\r|\n)", RegexOptions.Multiline); 223 | var injectMatches = injectPattern.Matches(razorContent); 224 | if (injectMatches.Count > 0) 225 | { 226 | //Add the using to the inject sb 227 | foreach (Match match in injectMatches) 228 | { 229 | var block = match.Groups["content"].Value; 230 | var newblock = $"@inject {block}"; 231 | if (!ContainsLine(inject, block)) 232 | { 233 | inject.AppendLine(newblock); 234 | } 235 | } 236 | //Remove the usings from the razor file 237 | razorContent = injectPattern.Replace(razorContent, ""); 238 | } 239 | 240 | 241 | 242 | //Attributes 243 | var attributePattern = new Regex(@"@attribute\s+(?[\s\S]*?)(\r\n|\r|\n)", RegexOptions.Multiline); 244 | var attributeMatches = attributePattern.Matches(razorContent); 245 | if (attributeMatches.Count > 0) 246 | { 247 | foreach (Match match in attributeMatches) 248 | { 249 | var block = match.Groups["content"].Value; 250 | var newblock = $"@attribute {block}"; 251 | if (!ContainsLine(attributes, newblock)) 252 | { 253 | attributes.AppendLine(newblock); 254 | } 255 | } 256 | //Remove the usings from the razor file 257 | razorContent = attributePattern.Replace(razorContent, ""); 258 | } 259 | 260 | //Implements 261 | var implementsPattern = new Regex(@"@implements\s+(?[\s\S]*?)(\r\n|\r|\n)", RegexOptions.Multiline); 262 | var implementsMatches = implementsPattern.Matches(razorContent); 263 | if (implementsMatches.Count > 0) 264 | { 265 | foreach (Match match in implementsMatches) 266 | { 267 | var block = match.Groups["content"].Value; 268 | var newblock = $"@implements {block}"; 269 | if (!ContainsLine(implements, newblock)) 270 | { 271 | implements.AppendLine(newblock); 272 | } 273 | } 274 | //Remove the usings from the razor file 275 | razorContent = implementsPattern.Replace(razorContent, ""); 276 | } 277 | 278 | //Inherits 279 | var inheritsPattern = new Regex(@"@inherits\s+(?[\s\S]*?)(\r\n|\r|\n)", RegexOptions.Multiline); 280 | var inheritsMatches = inheritsPattern.Matches(razorContent); 281 | if (inheritsMatches.Count > 0) 282 | { 283 | foreach (Match match in inheritsMatches) 284 | { 285 | var block = match.Groups["content"].Value; 286 | var newblock = $"@inherits {block}"; 287 | if (!ContainsLine(inherits, newblock)) 288 | { 289 | inherits.AppendLine(newblock); 290 | } 291 | } 292 | razorContent = inheritsPattern.Replace(razorContent, ""); 293 | } 294 | //Remove any new lines at the top of the razor file 295 | razorContent = Regex.Replace(razorContent, @"^\s*[\r\n]+", string.Empty, RegexOptions.Multiline); 296 | 297 | 298 | 299 | //Add content to razor file 300 | var codeBlockPattern = new Regex(@"@code\s*{(?[\s\S]*?)}", RegexOptions.Multiline); 301 | var codeMatch = codeBlockPattern.Match(razorContent); 302 | var updatedCodeBlock = Environment.NewLine + properties.ToString() + fields.ToString() + methods.ToString() + nestedclasses.ToString(); 303 | if (codeMatch.Success) 304 | { 305 | var codeBlock = codeMatch.Groups["content"].Value; 306 | updatedCodeBlock = codeBlock + updatedCodeBlock; 307 | razorContent = codeBlockPattern.Replace(razorContent, $"@code {{{updatedCodeBlock}}}"); 308 | } 309 | else 310 | { 311 | razorContent = razorContent + Environment.NewLine + $"@code {{{updatedCodeBlock} }}"; 312 | } 313 | 314 | //Add page, usings, injects, attributes, implements, inherits to razor file 315 | razorContent = pagedirective.ToString() + usings.ToString() + inject.ToString() + attributes.ToString() + implements.ToString() + inherits.ToString() + razorContent; 316 | 317 | File.WriteAllText(razorPath, razorContent); 318 | File.Delete(codeBehindPath); 319 | 320 | 321 | try 322 | { 323 | if (System.IO.File.Exists(razorPath)) 324 | { 325 | Window window = dte.ItemOperations.OpenFile(razorPath); 326 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 327 | await Dispatcher.CurrentDispatcher.BeginInvoke(new Action(() => { 328 | dte.ExecuteCommand("Edit.FormatDocument"); 329 | }), DispatcherPriority.ApplicationIdle, null); 330 | } 331 | else 332 | { 333 | System.Diagnostics.Debug.WriteLine($"File does not exist: {filePath}"); 334 | } 335 | } 336 | catch (COMException ex) 337 | { 338 | System.Diagnostics.Debug.WriteLine($"Error opening and formatting file: {ex.Message}"); 339 | } 340 | } 341 | } 342 | } 343 | 344 | private static bool HasInjectAttribute(PropertyDeclarationSyntax propertyNode) 345 | { 346 | foreach (var attributeList in propertyNode.AttributeLists) 347 | { 348 | foreach (var attribute in attributeList.Attributes) 349 | { 350 | if (attribute.Name.ToString().EndsWith("Inject")) 351 | { 352 | return true; 353 | } 354 | } 355 | } 356 | 357 | return false; 358 | } 359 | bool ContainsLine(StringBuilder sb, string targetLine) 360 | { 361 | string[] lines = sb.ToString().Split(new[] { "\r\n", "\r", "\n" }, StringSplitOptions.None); 362 | return lines.Any(line => line.Trim() == targetLine.Trim()); 363 | } 364 | 365 | private static List FindNestedClasses(ClassDeclarationSyntax classDeclaration) 366 | { 367 | var nestedClasses = new List(); 368 | 369 | foreach (var member in classDeclaration.Members) 370 | { 371 | if (member is ClassDeclarationSyntax nestedClass) 372 | { 373 | nestedClasses.Add(nestedClass); 374 | } 375 | } 376 | 377 | return nestedClasses; 378 | } 379 | } 380 | } 381 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/MoveNamespaceCommand.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using Microsoft.VisualStudio.Shell; 4 | using Microsoft.VisualStudio.Shell.Interop; 5 | using Microsoft.VisualStudio.Text.Editor; 6 | using Microsoft.VisualStudio.Text; 7 | using Microsoft.VisualStudio.TextManager.Interop; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text.RegularExpressions; 12 | 13 | namespace BlazmExtension 14 | { 15 | [Command(PackageIds.MoveNamespace)] 16 | internal sealed class MoveNamespaceCommand : BaseCommand 17 | { 18 | protected override Task InitializeCompletedAsync() 19 | { 20 | Command.Supported = false; 21 | return base.InitializeCompletedAsync(); 22 | } 23 | 24 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 25 | { 26 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 27 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 28 | 29 | var document = dte.ActiveDocument; 30 | var selection = (TextSelection)dte.ActiveDocument.Selection; 31 | 32 | var usings = ExtractUsings(selection.Text); 33 | if (usings.Count > 0) 34 | { 35 | var importsPath = FindImportsPath(document.FullName); 36 | if (importsPath != null) 37 | { 38 | AddUsingsToImportsFile(usings, importsPath); 39 | selection.Text = ""; 40 | } 41 | else 42 | { 43 | VsShellUtilities.ShowMessageBox( 44 | Package, 45 | "Unable to locate the _Imports.razor file.", 46 | "Error", 47 | OLEMSGICON.OLEMSGICON_CRITICAL, 48 | OLEMSGBUTTON.OLEMSGBUTTON_OK, 49 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); 50 | } 51 | } 52 | } 53 | 54 | private static List ExtractUsings(string text) 55 | { 56 | var regex = new Regex(@"^@using\s+.+\s*$", RegexOptions.Multiline); 57 | var matches = regex.Matches(text); 58 | 59 | return matches.Cast().Select(m => m.Value.Trim()).ToList(); 60 | } 61 | 62 | private static string FindImportsPath(string documentPath) 63 | { 64 | var directory = new DirectoryInfo(Path.GetDirectoryName(documentPath)); 65 | string importsPath; 66 | 67 | while (directory != null) 68 | { 69 | importsPath = Path.Combine(directory.FullName, "_Imports.razor"); 70 | if (File.Exists(importsPath)) 71 | { 72 | return importsPath; 73 | } 74 | 75 | directory = directory.Parent; 76 | } 77 | 78 | return null; 79 | } 80 | 81 | private static void AddUsingsToImportsFile(List usings, string importsPath) 82 | { 83 | var existingUsings = File.ReadAllLines(importsPath).ToList(); 84 | 85 | foreach (var usingDirective in usings) 86 | { 87 | if (!existingUsings.Contains(usingDirective)) 88 | { 89 | existingUsings.Add(usingDirective); 90 | } 91 | } 92 | 93 | File.WriteAllLines(importsPath, existingUsings); 94 | } 95 | 96 | private static void RemoveUsingsFromBuffer(List usings, ITextBuffer textBuffer, ITextEdit edit, int start, int end) 97 | { 98 | foreach (var usingDirective in usings) 99 | { 100 | var usingSpan = new SnapshotSpan(textBuffer.CurrentSnapshot, start, end - start); 101 | var usingLine = usingSpan.GetText().IndexOf(usingDirective, StringComparison.Ordinal); 102 | 103 | if (usingLine >= 0) 104 | { 105 | var lineStart = usingSpan.Start + usingLine; 106 | var lineEnd = lineStart + usingDirective.Length; 107 | edit.Delete(lineStart, lineEnd - lineStart); 108 | } 109 | } 110 | } 111 | } 112 | } 113 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/QuickSaveCommand.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using Microsoft.VisualStudio.Shell; 4 | using Microsoft.VisualStudio.Shell.Interop; 5 | using Microsoft.VisualStudio.Text.Editor; 6 | using Microsoft.VisualStudio.Text; 7 | using Microsoft.VisualStudio.TextManager.Interop; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text.RegularExpressions; 12 | using System.Windows.Interop; 13 | using StageCoder; 14 | using System.ComponentModel.Design; 15 | using System.IO.Packaging; 16 | using BlazmExtension.Dialogs.Routing; 17 | using System.Threading; 18 | 19 | namespace BlazmExtension; 20 | 21 | [Command(PackageIds.QuickSave)] 22 | internal sealed class QuickSaveCommand : BaseCommand 23 | { 24 | protected override Task InitializeCompletedAsync() 25 | { 26 | 27 | 28 | return base.InitializeCompletedAsync(); 29 | } 30 | public static QuickSaveCommand Instance 31 | { 32 | get; 33 | private set; 34 | } 35 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 36 | { 37 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 38 | 39 | try 40 | { 41 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 42 | if (dte.ActiveDocument != null) 43 | { 44 | SaveDocument(dte.ActiveDocument); 45 | } 46 | 47 | } 48 | catch (Exception ex ) 49 | { 50 | 51 | throw; 52 | } 53 | 54 | 55 | } 56 | 57 | private void SaveDocument(Document document) 58 | { 59 | ThreadHelper.ThrowIfNotOnUIThread(); 60 | string filePath = document.FullName; 61 | TextDocument textDocument = (TextDocument)document.Object("TextDocument"); 62 | File.WriteAllText(filePath, textDocument.CreateEditPoint().GetText(textDocument.EndPoint)); 63 | 64 | document.Saved = true; 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/RoutingWindowCommand.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using Microsoft.VisualStudio.Shell; 4 | using Microsoft.VisualStudio.Shell.Interop; 5 | using Microsoft.VisualStudio.Text.Editor; 6 | using Microsoft.VisualStudio.Text; 7 | using Microsoft.VisualStudio.TextManager.Interop; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text.RegularExpressions; 12 | using System.Windows.Interop; 13 | using StageCoder; 14 | using System.ComponentModel.Design; 15 | using System.IO.Packaging; 16 | using BlazmExtension.Dialogs.Routing; 17 | using System.Threading; 18 | 19 | namespace BlazmExtension; 20 | 21 | [Command(PackageIds.RoutingWindow)] 22 | internal sealed class RoutingWindowCommand : BaseCommand 23 | { 24 | protected override Task InitializeCompletedAsync() 25 | { 26 | Command.Supported = false; 27 | return base.InitializeCompletedAsync(); 28 | } 29 | public static RoutingWindowCommand Instance 30 | { 31 | get; 32 | private set; 33 | } 34 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 35 | { 36 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 37 | 38 | try 39 | { 40 | ToolWindowPane window = Package.FindToolWindow(typeof(RoutingWindow), 0, true); 41 | if ((null == window) || (null == window.Frame)) 42 | { 43 | throw new NotSupportedException("Cannot create tool window"); 44 | } 45 | 46 | IVsWindowFrame windowFrame = (IVsWindowFrame)window.Frame; 47 | Microsoft.VisualStudio.ErrorHandler.ThrowOnFailure(windowFrame.Show()); 48 | 49 | } 50 | catch (Exception ex ) 51 | { 52 | 53 | throw; 54 | } 55 | 56 | 57 | } 58 | } 59 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/RunDotnetWatchCommand.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using Microsoft.VisualStudio.Shell; 4 | using Microsoft.VisualStudio.Shell.Interop; 5 | using Microsoft.VisualStudio.Text.Editor; 6 | using Microsoft.VisualStudio.Text; 7 | using Microsoft.VisualStudio.TextManager.Interop; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text.RegularExpressions; 12 | using System.Windows.Interop; 13 | using StageCoder; 14 | using System.ComponentModel.Design; 15 | using System.IO.Packaging; 16 | using BlazmExtension.Dialogs.Routing; 17 | using System.Threading; 18 | using System.Diagnostics; 19 | 20 | namespace BlazmExtension; 21 | 22 | [Command(PackageIds.RunDotnetWatch)] 23 | internal sealed class RunDotnetWatchCommand : BaseCommand 24 | { 25 | protected override Task InitializeCompletedAsync() 26 | { 27 | 28 | 29 | return base.InitializeCompletedAsync(); 30 | } 31 | public static RunDotnetWatchCommand Instance 32 | { 33 | get; 34 | private set; 35 | } 36 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 37 | { 38 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 39 | 40 | try 41 | { 42 | var dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 43 | if (dte.SelectedItems.Count == 1) 44 | { 45 | var selectedItem = dte.SelectedItems.Item(1); 46 | var project = selectedItem.Project; 47 | if (project != null) 48 | { 49 | RunDotnetWatch(project.FullName); 50 | } 51 | } 52 | 53 | } 54 | catch (Exception ex ) 55 | { 56 | 57 | throw; 58 | } 59 | 60 | 61 | } 62 | 63 | private void RunDotnetWatch(string projectFilePath) 64 | { 65 | try 66 | { 67 | 68 | 69 | // Construct the PowerShell command 70 | string powershellCommand = $"-NoExit -Command \"Write-Host 'Starting up dotnet watch'; cd {Path.GetDirectoryName(projectFilePath)}; dotnet watch --non-interactive\""; 71 | 72 | ProcessStartInfo startInfo = new ProcessStartInfo() 73 | { 74 | FileName = "powershell.exe", 75 | Arguments =powershellCommand, 76 | UseShellExecute = true, 77 | CreateNoWindow = false 78 | }; 79 | 80 | System.Diagnostics.Process.Start(startInfo); 81 | } 82 | catch (Exception ex) 83 | { 84 | VsShellUtilities.ShowMessageBox( 85 | Package, 86 | $"Error running dotnet watch: {ex.Message}", 87 | "Run dotnet watch Error", 88 | OLEMSGICON.OLEMSGICON_CRITICAL, 89 | OLEMSGBUTTON.OLEMSGBUTTON_OK, 90 | OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); 91 | } 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Commands/SwitchToNestedFile.cs: -------------------------------------------------------------------------------- 1 | using EnvDTE; 2 | using EnvDTE80; 3 | using Microsoft.VisualStudio.Shell; 4 | using Microsoft.VisualStudio.Shell.Interop; 5 | using Microsoft.VisualStudio.Text.Editor; 6 | using Microsoft.VisualStudio.Text; 7 | using Microsoft.VisualStudio.TextManager.Interop; 8 | using System.Collections.Generic; 9 | using System.IO; 10 | using System.Linq; 11 | using System.Text.RegularExpressions; 12 | using System.Threading.Tasks; 13 | 14 | namespace BlazmExtension 15 | { 16 | [Command(PackageIds.SwitchToNestedFile)] 17 | internal sealed class SwitchToNestedFileCommand : BaseCommand 18 | { 19 | protected override Task InitializeCompletedAsync() 20 | { 21 | Command.Supported = false; 22 | return base.InitializeCompletedAsync(); 23 | } 24 | 25 | protected override async Task ExecuteAsync(OleMenuCmdEventArgs e) 26 | { 27 | try 28 | { 29 | await ThreadHelper.JoinableTaskFactory.SwitchToMainThreadAsync(); 30 | DTE2 dte = await Package.GetServiceAsync(typeof(DTE)) as DTE2; 31 | var document = dte.ActiveDocument; 32 | List files = new(); 33 | ProjectItem toplevel = null; 34 | if (document.ProjectItem.ProjectItems.Count == 0) 35 | { 36 | //There are no nested files, try an get the parent file 37 | toplevel = document.ProjectItem.Collection.Parent as ProjectItem; 38 | } 39 | else 40 | { 41 | toplevel = document.ProjectItem; 42 | } 43 | 44 | if (toplevel != null && toplevel.Document!=null) 45 | { 46 | files.Add(toplevel.Document.FullName); 47 | foreach (ProjectItem item in toplevel.Document.ProjectItem.ProjectItems) 48 | { 49 | files.Add(item.FileNames[1]); 50 | } 51 | } 52 | 53 | //If files contains a scss,less or sass file, skip the css and map files 54 | if (files.Any(f => f.EndsWith(".scss") || f.EndsWith(".less") || f.EndsWith(".sass"))) 55 | { 56 | files = files.Where(f => !f.EndsWith(".css") && !f.EndsWith(".css.map")).ToList(); 57 | } 58 | 59 | 60 | if (files.Count > 1) 61 | { 62 | var index = files.IndexOf(document.FullName); 63 | if (index < files.Count - 1) 64 | { 65 | dte.ItemOperations.OpenFile(files[index + 1]); 66 | } 67 | else 68 | { 69 | dte.ItemOperations.OpenFile(files[0]); 70 | } 71 | } 72 | } 73 | catch (System.Exception ex) 74 | { 75 | 76 | } 77 | } 78 | } 79 | } 80 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/Dialogs/ComponentReferences/ComponentReferencesControl.xaml: -------------------------------------------------------------------------------- 1 |  14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 29 | 30 | 31 | 49 | 50 | 51 | 56 | 57 | 58 | 63 | 64 | 68 | 69 | 78 | 79 | 80 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 | 112 | 113 | 120 | 127 | 128 | 48 | 49 | 55 | 56 | 62 | 63 | 70 | 71 | 72 | 73 | 82 | 83 | 91 | 92 | 101 | 102 | 103 | 112 | 113 | 114 | 122 | 123 | 131 | 132 | 141 | 150 | 151 | 160 | 161 | 169 | 170 | 171 | 172 | 173 | 174 | 175 | Blazm 176 | Blazm 177 | 178 | 179 | 180 | 181 | 182 | DynamicVisibility 183 | 184 | Generate bUnit test (to clipboard) 185 | Generate bUnit test (to clipboard) 186 | 187 | 188 | 189 | 190 | 191 | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 | 256 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/source.extension.cs: -------------------------------------------------------------------------------- 1 | // ------------------------------------------------------------------------------ 2 | // 3 | // This file was generated by VSIX Synchronizer 4 | // 5 | // ------------------------------------------------------------------------------ 6 | namespace BlazmExtension 7 | { 8 | internal sealed partial class Vsix 9 | { 10 | public const string Id = "BlazmExtension.a0f59921-9553-46c5-b0cf-4c4921326541"; 11 | public const string Name = "BlazmExtension"; 12 | public const string Description = @"Extension that helps you with common Blazor tasks like creating a Isolated CSS or JavaScript from a context menu item"; 13 | public const string Language = "en-US"; 14 | public const string Version = "1.7.8"; 15 | public const string Author = "EngstromJimmy"; 16 | public const string Tags = ""; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /BlazmExtension/BlazmExtension/source.extension.vsixmanifest: -------------------------------------------------------------------------------- 1 |  2 | 3 | 4 | 5 | BlazmExtension 6 | Extension that helps you with common Blazor tasks like creating a Isolated CSS or JavaScript from a context menu item 7 | Resources\Icon.png 8 | Resources\Icon.png 9 | true 10 | 11 | 12 | 13 | 14 | 15 | arm64 16 | 17 | 18 | arm64 19 | 20 | 21 | arm64 22 | 23 | 24 | 25 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | -------------------------------------------------------------------------------- /Images/ComponentUsagesExample.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/Images/ComponentUsagesExample.png -------------------------------------------------------------------------------- /Images/RazorMenuContext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/Images/RazorMenuContext.png -------------------------------------------------------------------------------- /Images/Routes.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/Images/Routes.png -------------------------------------------------------------------------------- /Images/SolutionRazorContext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/Images/SolutionRazorContext.png -------------------------------------------------------------------------------- /Images/SolutionRazorCsContext.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/Images/SolutionRazorCsContext.png -------------------------------------------------------------------------------- /Images/bUnit.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/Images/bUnit.png -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2023 Jimmy Engstrom 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | I've been running Blazor in production seven days after it was released. 2 | I use it for work all day and then for my hobby projects in the evening. 3 | I clock in a lot of Blazor development hours, and I'm always looking for ways to improve my workflow. 4 | There are a few things that I've been missing in Visual Studio, and I've been thinking about creating a Visual Studio extension for a while now. 5 | So I looked at some of my pain points and how I could solve them with an extension. 6 | 7 | ## Features when right-clicking a component in the solution explorer 8 | When you right-click on a component in the Solution Explorer, you will see a new context menu with the following items: 9 | 10 | 11 | 12 | ### Creating a new Isolated CSS file 13 | I wanted to be able to create a new Isolated CSS file directly from the Solution Explorer, and I didn't want to have to type the name of the file. 14 | So I created a new Visual Studio extension called BlazmExtension that adds a new context menu item to the Solution Explorer. 15 | Just right-click on the component and select "Create Isolated CSS . 16 | This will create a new CSS file with the appropriate name for that component. 17 | 18 | ### Creating a new Isolated JavaScript file 19 | I also wanted to be able to create a new Isolated JavaScript file directly from the Solution Explorer. 20 | Just right-click on the component and select "Create Isolated JavaScript". 21 | This will create a new JavaScript file with the same name as the component. 22 | 23 | ### Creating a new Codebehind file 24 | This feature will add a code-behind file directly from the Solution Explorer. 25 | Just right-click on the component and select "Create Codebehind". 26 | This will create a new code-behind file with the same name as the component. 27 | 28 | ### Find component usages (Solution Explorer) 29 | Clicking this will search your entire solution for usages of the selected component. 30 | 31 | See [Find component usages (Window)](#find-component-usages-window) 32 | 33 | ## Features when right-clicking when selecting code in a Razor file. 34 | When you select code and right-click in a component, you will see a new context menu with the following items: 35 | 36 | 37 | 38 | 39 | ### Move namespaces to _Imports 40 | A common task when creating a new component is to add the namespace to the _Imports.razor file. 41 | Simply select the namespaces you want to move and right-click and choose "Move namespaces to _Imports". 42 | 43 | ### Extract to Component 44 | Blazor is a very component-based framework, and you often find yourself extracting parts of your code to a new component. 45 | This task is very common, and I wanted to make it as easy as possible. 46 | Simply select the code you want to extract and right-click and select "Extract to Component". 47 | This will create a new component with the selected code and replace the selected code with the new component. 48 | 49 | ### Find component usages (Right click in razor file) 50 | The behaviour of this dependends on the cursor position when you right click. If you are anywhere 51 | within an opening, closing, or self-enclosing tag. It will open the component usages window and search for that component. 52 | (Note: Works for standard html elements as well) 53 | 54 | If you are not in an opening, closing, or self-enclosing tag - be it an empty line, csharp code space, or the body of a component - 55 | it will search for the razor component of the file you are in. For example, if you are in NavMenu.razor and right click in an 56 | `@code` block, it will search for `NavMenu` usages. 57 | 58 | See [Find component usages (Window)](#find-component-usages-window) 59 | 60 | ## Features when right-clicking a code-behind file of a Razor component. 61 | When you right-click on a component's codebehind file in the Solution Explorer you will see a new context menu with the following items: 62 | 63 | 64 | 65 | ### Move code-behind to razor 66 | This is my favorite feature of the extension. 67 | Visual Studio makes moving code from the razor file to the code-behind file easy. 68 | But it doesn't have a feature to move code from the code-behind file to the razor file. 69 | I prefer to have all my code in the razor file, and I often move code from the code-behind file to the razor file. 70 | Right-click on the component.razor.cs file and select "Move code-behind to razor". 71 | This feature is in beta. I hope I have managed to cover all the edge cases, but if you find any bugs, please let me know. 72 | 73 | ## Generic features 74 | ### Switching files 75 | Switching files between razor and code-behind is common, and I wanted to make it as easy as possible. 76 | By pressing CTRL + ALT + N (N for Next file), you can switch between the razor file and the code-behind file (or any nested files). 77 | 78 | ### Blazor Routes 79 | In a large project, it can be hard to keep track of all the routes. 80 | I wanted to be able to see all the routes in one place, so I created a new window called Blazor Routes. 81 | You can open the window by going to Extensions -> Blazm-> Show Blazor Routes. 82 | The window will show all the routes in your project, and you can double-click on a route to open the file. 83 | 84 | 85 | 86 | ### Quick save 87 | This is an experimental feature that I'm testing. 88 | I noticed that using Hot Reload from Notepad was alot faster that using it from Visual Studio. I am not sure if it is related but Visual Studio saves the file as a temporary file, deletes the original and renames the temp file. My theory is that this is why Hot Reload is slower in Visual Studio. 89 | So I created a new feature called Quick Save. This feature will save the file without creating a temp file. 90 | There is probably a very good reaon why Visual Studio saves the file as a temp file, so take into consideration that this feature is experimental. 91 | 92 | ### Run dotnet watch 93 | While creating my Blazor course on Dometrain (shameless plug), I noticed that Hot Reload running from PowerShell (dotnet watch) worked better than from Visual Studio, it is also quite nice to have it running in the background. I prefer not to have to write things in powershell or the console in general. So I added "Run dotnet watch" menu item for projects. 94 | So now we can just right-click on the project and select "Run dotnet watch" and it will start dotnet watch in a PowerShell window. 95 | 96 | ### bUnit test generation 97 | Think writing tests is tedious? Well, this new feature promises to eliminate much of that monotony, letting us zero in on the exciting parts! 98 | Currently, this feature is still undergoing refinement and is in its beta phase. Your feedback and suggestions would be invaluable as we refine this tool. 99 | 100 | This feature will automatically produce test code: 101 | 102 | ```csharp 103 | @inherits TestContext 104 | @using Bunit 105 | @using BlazorApp1.Pages; 106 | @code 107 | { 108 | [Fact] 109 | public void Test1() 110 | { 111 | //Arrange 112 | //Services.AddSingleton(); 113 | 114 | var cut = Render(@); 115 | 116 | //Act 117 | 118 | //Assert 119 | } 120 | } 121 | ``` 122 | For those who lean towards a pure C# syntax, the generator will provide: 123 | 124 | ```csharp 125 | 126 | public class FetchDataTests : TestContext 127 | { 128 | [Fact] 129 | public void Test1() 130 | { 131 | //Arrange 132 | //Services.AddSingleton(); 133 | var cut = RenderComponent(); 134 | 135 | //Act 136 | 137 | //Assert 138 | } 139 | } 140 | ``` 141 | This generator is designed to seamlessly incorporate dependency injected properties, render fragments, parameters, and much more. While I've tried to cover the most typical scenarios, there may be edge cases I've missed. Bear with me as I continue to tweak it. 142 | 143 | There's an ongoing challenge with line break placements, but I'm optimistic about finding a resolution. To leverage this feature, simply right-click on a component and choose the desired command. 144 | 145 | 146 | 147 | ### Find component usages (Window) 148 | The find component usages feature opens up a window that shows you the file name, file path, line number, and a preview, of all usages for a particular razor component in your solution. In 149 | this window there is also a search box to let you input a different component to find - this search box has auto complete but only for components in your solution. 150 | 151 | 152 | 153 | ## Conclusion 154 | I hope you find this extension useful. 155 | I will continue to add new features to the extension and I'm open to suggestions. 156 | You can find the extension on the Visual Studio Marketplace: 157 | [https://marketplace.visualstudio.com/items?itemName=EngstromJimmy.BlazmExtension](https://marketplace.visualstudio.com/items?itemName=EngstromJimmy.BlazmExtension) 158 | --------------------------------------------------------------------------------