├── .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("
"
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($"{property.Name}>");
100 | }
101 | sb.AppendLine($" {type.Name}>");
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 |
131 |
132 |
133 |
134 |
140 |
144 |
145 |
146 |
147 |
154 |
155 |
156 |
157 |
158 |
159 |
160 |
161 |
162 |
163 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Dialogs/ComponentReferences/ComponentReferencesControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using EnvDTE;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Collections.ObjectModel;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Windows;
8 | using System.Windows.Controls;
9 | using System.Windows.Input;
10 | using BlazmExtension.Extensions;
11 | using Path = System.IO.Path;
12 | using TextSelection = EnvDTE.TextSelection;
13 | using System.Text.RegularExpressions;
14 | using BlazmExtension.Singletons;
15 |
16 | namespace BlazmExtension.Dialogs.ComponentReferences
17 | {
18 | ///
19 | /// Interaction logic for ComponentReferencesControl.xaml
20 | ///
21 | public partial class ComponentReferencesControl : UserControl
22 | {
23 | public ObservableCollection ComponentReferenceDataList { get; set; } = new ();
24 | private readonly DTE _dte;
25 |
26 | public ComponentReferencesControl()
27 | {
28 | InitializeComponent();
29 | ThreadHelper.ThrowIfNotOnUIThread();
30 | if (ServiceProvider.GlobalProvider.GetService(typeof(DTE)) is DTE service)
31 | {
32 | _dte = service;
33 | }
34 | }
35 |
36 | public void Initialize(string componentName)
37 | {
38 | ThreadHelper.ThrowIfNotOnUIThread();
39 | try
40 | {
41 | ComponentReferenceDataList.Clear();
42 |
43 | ReferenceTextBlock.Text = $"Searching for <{componentName}> usages.";
44 |
45 | ComponentReferenceGrid.ItemsSource = ComponentReferenceDataList;
46 |
47 | foreach (var componentReference in FindComponentReferences(componentName))
48 | {
49 | ComponentReferenceDataList.Add(componentReference);
50 | }
51 |
52 | ReferenceTextBlock.Text = $"<{componentName}> {ComponentReferenceDataList.Count} usages found.";
53 | }
54 | catch (Exception ex) { }
55 | }
56 |
57 | private IEnumerable FindComponentReferences(string componentName)
58 | {
59 | ThreadHelper.ThrowIfNotOnUIThread();
60 | var razorFiles = _dte.Solution.GetAllRazorFiles();
61 |
62 |
63 | foreach (var razorFile in razorFiles)
64 | {
65 | var results = FindUsagesInFile(componentName, razorFile);
66 | foreach (var componentUsage in results)
67 | {
68 | if (componentUsage != null)
69 | {
70 | yield return componentUsage;
71 | }
72 | }
73 | }
74 | }
75 |
76 | private Dictionary _regexCache = new ();
77 | private List FindUsagesInFile(string componentName, string filePath)
78 | {
79 | var usages = new List();
80 |
81 | // Read the file line by line
82 | var lines = File.ReadLines(filePath);
83 |
84 | if (!_regexCache.TryGetValue(componentName, out var regex))
85 | {
86 | var pattern = $@"<{componentName}(?![a-zA-Z])";
87 | regex = new Regex(pattern, RegexOptions.Compiled);
88 | _regexCache[componentName] = regex;
89 | }
90 |
91 | int lineNumber = 0;
92 | foreach (var line in lines)
93 | {
94 | lineNumber++; // Keep track of the current line number
95 |
96 | // Check if the line contains the component's usage
97 | if (regex.IsMatch(line))
98 | {
99 | usages.Add(new ComponentReferenceItem()
100 | {
101 | ComponentName = componentName,
102 | FilePath = filePath,
103 | LineNumber = lineNumber,
104 | Preview = line.Trim() // Assuming the entire line is what you want as a preview
105 | });
106 | }
107 | }
108 |
109 | return usages;
110 | }
111 |
112 | private void ComponentReferenceGrid_MouseDoubleClick(object sender, MouseButtonEventArgs e)
113 | {
114 | if (!(ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) is DataGridRow row)) return;
115 |
116 | if (row.DataContext is ComponentReferenceItem item)
117 | {
118 | ThreadHelper.ThrowIfNotOnUIThread();
119 | var dte = (DTE)ServiceProvider.GlobalProvider.GetService(typeof(DTE));
120 | if (dte != null)
121 | {
122 | var window = dte.ItemOperations.OpenFile(item.FilePath);
123 | if (window != null)
124 | {
125 | TextSelection ts = (TextSelection)window.Document.Selection;
126 | ts?.GotoLine(item.LineNumber);
127 | }
128 | }
129 | }
130 | }
131 |
132 | private void OnSearchButtonClick(object sender, RoutedEventArgs e)
133 | {
134 | ThreadHelper.ThrowIfNotOnUIThread();
135 |
136 | string componentName = ComponentSearchTextBox.Text;
137 |
138 | if (string.IsNullOrWhiteSpace(componentName))
139 | {
140 | return;
141 | }
142 |
143 | Initialize(componentName);
144 | }
145 |
146 | private void ComponentSearchTextBox_GotFocus(object sender, RoutedEventArgs e)
147 | {
148 | PlaceholderTextBlock.Visibility = Visibility.Collapsed;
149 | }
150 |
151 | private void ComponentSearchTextBox_LostFocus(object sender, RoutedEventArgs e)
152 | {
153 | PlaceholderTextBlock.Visibility = string.IsNullOrEmpty(ComponentSearchTextBox.Text)
154 | ? Visibility.Visible
155 | : Visibility.Collapsed;
156 | }
157 |
158 | private bool handlingTextChange = false;
159 | private bool isDeletion = false;
160 |
161 | private void ComponentSearchTextBox_TextChanged(object sender, TextChangedEventArgs e)
162 | {
163 | if (!handlingTextChange && !isDeletion)
164 | {
165 | handlingTextChange = true; // Flag to indicate we're in the midst of handling
166 |
167 | // Your logic to find the closest matching component name
168 | string input = ComponentSearchTextBox.Text;
169 | if (!string.IsNullOrWhiteSpace(input))
170 | {
171 | ComponentSearchTextBox_GotFocus(null, null);
172 | }
173 | var matchingComponent = ComponentNameProvider.GetComponentNames().OrderBy(x => x.Length).FirstOrDefault(c => c.StartsWith(input, StringComparison.OrdinalIgnoreCase));
174 |
175 | if (matchingComponent != null)
176 | {
177 | // Unhook the TextChanged event
178 | ComponentSearchTextBox.TextChanged -= ComponentSearchTextBox_TextChanged;
179 |
180 | // Update the TextBox's text and selection
181 | ComponentSearchTextBox.Text = matchingComponent;
182 | ComponentSearchTextBox.Select(input.Length, matchingComponent.Length - input.Length);
183 |
184 | // Rehook the TextChanged event
185 | ComponentSearchTextBox.TextChanged += ComponentSearchTextBox_TextChanged;
186 | }
187 |
188 | handlingTextChange = false; // Reset the flag
189 | }
190 | else
191 | {
192 | isDeletion = false; // Reset the deletion flag
193 | }
194 | }
195 |
196 | private void ComponentSearchTextBox_PreviewKeyDown(object sender, KeyEventArgs e)
197 | {
198 | if (e.Key == Key.Tab && ComponentSearchTextBox.SelectedText.Length > 0)
199 | {
200 | // Move the caret to the end and clear the selection
201 | ComponentSearchTextBox.CaretIndex = ComponentSearchTextBox.Text.Length;
202 | ComponentSearchTextBox.SelectionLength = 0;
203 |
204 | // Important to set the event as handled
205 | e.Handled = true;
206 | }
207 | else if (e.Key is Key.Back or Key.Delete)
208 | {
209 | isDeletion = true; // Set the deletion flag
210 | }
211 | }
212 |
213 | private void UserControl_MouseDown(object sender, MouseButtonEventArgs e)
214 | {
215 | if (ComponentSearchTextBox.IsFocused)
216 | {
217 | Keyboard.ClearFocus();
218 | ComponentSearchTextBox_LostFocus(null, null);
219 | }
220 | }
221 |
222 | private void Grid_PreviewMouseDown(object sender, MouseButtonEventArgs e)
223 | {
224 | if (ComponentSearchTextBox.IsFocused)
225 | {
226 | Keyboard.ClearFocus();
227 | ComponentSearchTextBox_LostFocus(null, null);
228 | }
229 | }
230 | }
231 | public class ComponentReferenceItem
232 | {
233 | public string ComponentName { get; set; }
234 | public string FilePath { get; set; }
235 | public string FileName => Path.GetFileName(FilePath);
236 | public string Preview { get; set; }
237 | public int LineNumber { get; set; }
238 | }
239 | }
240 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Dialogs/ComponentReferences/ComponentReferencesWindow.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 |
3 | namespace BlazmExtension.Dialogs.ComponentReferences
4 | {
5 | [Guid("9d25178e-8686-452e-8491-7be334532c87")]
6 | public class ComponentReferencesWindow : ToolWindowPane
7 | {
8 | public ComponentReferencesWindow() : base(null)
9 | {
10 | this.Caption = "Component Usages";
11 | this.Content = new ComponentReferencesControl();
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Dialogs/FileNameDialog.xaml:
--------------------------------------------------------------------------------
1 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Dialogs/FileNameDialog.xaml.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using System.Windows;
4 | using System.Windows.Input;
5 | using System.Windows.Media.Imaging;
6 |
7 | namespace StageCoder
8 | {
9 | public partial class FileNameDialog : Window
10 | {
11 | private const string DEFAULT_TEXT = "Enter a name for the component";
12 |
13 |
14 | public FileNameDialog()
15 | {
16 | InitializeComponent();
17 |
18 | Loaded += (s, e) =>
19 | {
20 | //Icon = BitmapFrame.Create(new Uri("pack://application:,,,/AddAnyFile;component/Resources/icon.png", UriKind.RelativeOrAbsolute));
21 | Title = "Save selection as a new component";
22 |
23 | Name.Focus();
24 | Name.CaretIndex = 0;
25 | Name.Text = DEFAULT_TEXT;
26 | Name.Select(0, Name.Text.Length);
27 |
28 | Name.PreviewKeyDown += (a, b) =>
29 | {
30 | if (b.Key == Key.Escape)
31 | {
32 | if (string.IsNullOrWhiteSpace(Name.Text) || Name.Text == DEFAULT_TEXT)
33 | {
34 | Close();
35 | }
36 | else
37 | {
38 | Name.Text = string.Empty;
39 | }
40 | }
41 | else if (Name.Text == DEFAULT_TEXT)
42 | {
43 | Name.Text = string.Empty;
44 | btnCreate.IsEnabled = true;
45 | }
46 | };
47 |
48 | };
49 | }
50 |
51 | public string Input => Name.Text.Trim();
52 |
53 | private void Button_Click(object sender, RoutedEventArgs e)
54 | {
55 | DialogResult = true;
56 | Close();
57 | }
58 | }
59 | }
60 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Dialogs/Routing/ProvideToolboxControlAttribute.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using System;
3 | using System.Globalization;
4 | using System.Runtime.InteropServices;
5 |
6 | namespace BlazmExtension.Dialogs.Routing;
7 |
8 | [AttributeUsage(AttributeTargets.Class, AllowMultiple = false, Inherited = true)]
9 | [ComVisible(false)]
10 | public sealed class ProvideToolboxControlAttribute : RegistrationAttribute
11 | {
12 | private const string ToolboxControlsInstallerPath = "ToolboxControlsInstaller";
13 | private readonly string name;
14 | private readonly bool areWPFControls;
15 |
16 | ///
17 | /// Creates a new ProvideToolboxControl attribute to register the assembly for toolbox controls installer.
18 | ///
19 | /// The name of the toolbox controls.
20 | /// Indicates whether the toolbox controls are WPF controls.
21 | public ProvideToolboxControlAttribute(string name, bool areWPFControls)
22 | {
23 | this.name = name ?? throw new ArgumentNullException(nameof(name));
24 | this.areWPFControls = areWPFControls;
25 | }
26 |
27 | ///
28 | /// Called to register this attribute with the given context. The context
29 | /// contains the location where the registration information should be placed.
30 | /// It also contains other information such as the type being registered and path information.
31 | ///
32 | /// Given context to register in.
33 | public override void Register(RegistrationContext context)
34 | {
35 | if (context == null)
36 | {
37 | throw new ArgumentNullException(nameof(context));
38 | }
39 |
40 | using (Key key = context.CreateKey(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}",
41 | ToolboxControlsInstallerPath,
42 | context.ComponentType.Assembly.FullName)))
43 | {
44 | key.SetValue(string.Empty, this.name);
45 | key.SetValue("Codebase", context.CodeBase);
46 | if (this.areWPFControls)
47 | {
48 | key.SetValue("WPFControls", "1");
49 | }
50 | }
51 | }
52 |
53 | ///
54 | /// Called to unregister this attribute with the given context.
55 | ///
56 | /// A registration context provided by an external registration tool.
57 | /// The context can be used to remove registry keys, log registration activity, and obtain information
58 | /// about the component being registered.
59 | public override void Unregister(RegistrationContext context)
60 | {
61 | if (context != null)
62 | {
63 | context.RemoveKey(string.Format(CultureInfo.InvariantCulture, "{0}\\{1}",
64 | ToolboxControlsInstallerPath,
65 | context.ComponentType.Assembly.FullName));
66 | }
67 | }
68 | }
69 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Dialogs/Routing/RoutingItem.cs:
--------------------------------------------------------------------------------
1 | namespace BlazmExtension.Dialogs.Routing;
2 |
3 | public partial class RoutingWindowControl
4 | {
5 | public class RoutingItem
6 | {
7 | public string Name { get; set; }
8 | public string Content { get; set; }
9 | }
10 | }
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Dialogs/Routing/RoutingWindow.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.VisualStudio.Shell;
2 | using System;
3 | using System.Runtime.InteropServices;
4 |
5 | namespace BlazmExtension.Dialogs.Routing;
6 |
7 | ///
8 | /// This class implements the tool window exposed by this package and hosts a user control.
9 | ///
10 | ///
11 | /// In Visual Studio tool windows are composed of a frame (implemented by the shell) and a pane,
12 | /// usually implemented by the package implementer.
13 | ///
14 | /// This class derives from the ToolWindowPane class provided from the MPF in order to use its
15 | /// implementation of the IVsUIElementPane interface.
16 | ///
17 | ///
18 | [Guid("eb70ef4f-9898-4e9d-91c3-419ef679d727")]
19 | public class RoutingWindow : ToolWindowPane
20 | {
21 | ///
22 | /// Initializes a new instance of the class.
23 | ///
24 | public RoutingWindow() : base(null)
25 | {
26 | this.Caption = "Blazor Routes";
27 |
28 | // This is the user control hosted by the tool window; Note that, even if this class implements IDisposable,
29 | // we are not calling Dispose on this object. This is because ToolWindowPane calls Dispose on
30 | // the object returned by the Content property.
31 | this.Content = new RoutingWindowControl();
32 | }
33 | }
34 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Dialogs/Routing/RoutingWindowControl.xaml:
--------------------------------------------------------------------------------
1 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
26 |
27 |
28 |
31 |
32 |
33 |
37 |
38 |
39 |
43 |
44 |
48 |
49 |
50 |
51 |
52 |
53 |
54 |
55 |
56 |
57 |
58 |
59 |
60 |
61 |
62 |
63 |
64 |
72 |
73 |
74 |
75 |
76 |
84 |
85 |
86 |
87 |
91 |
92 |
93 |
94 |
95 |
96 |
97 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Dialogs/Routing/RoutingWindowControl.xaml.cs:
--------------------------------------------------------------------------------
1 | using Community.VisualStudio.Toolkit;
2 | using EnvDTE;
3 | using Microsoft.VisualStudio.Package;
4 | using Microsoft.VisualStudio.Shell;
5 | using Microsoft.VisualStudio.Shell.Interop;
6 | using Mono.Cecil;
7 | using System;
8 | using System.Collections.Generic;
9 | using System.Collections.ObjectModel;
10 | using System.Configuration.Assemblies;
11 | using System.Diagnostics.CodeAnalysis;
12 | using System.IO;
13 | using System.Linq;
14 | using System.Reflection;
15 | using System.Reflection.Emit;
16 | using System.Runtime.InteropServices;
17 | using System.Windows;
18 | using System.Windows.Controls;
19 | using BlazmExtension.Extensions;
20 |
21 | namespace BlazmExtension.Dialogs.Routing;
22 |
23 | public partial class RoutingWindowControl : UserControl
24 | {
25 | public RoutingWindowControl()
26 | {
27 | InitializeComponent();
28 | ThreadHelper.ThrowIfNotOnUIThread();
29 | if (ServiceProvider.GlobalProvider.GetService(typeof(DTE)) is DTE service)
30 | {
31 | dte = service;
32 | Load();
33 | }
34 | }
35 |
36 | private readonly DTE dte;
37 |
38 | private void Load()
39 | {
40 | try
41 | {
42 | ThreadHelper.ThrowIfNotOnUIThread();
43 | Array _projects = dte.ActiveSolutionProjects as Array;
44 | RoutingDataList.Clear();
45 | if (_projects.Length != 0 && _projects != null)
46 | {
47 | string rowText;
48 | IEnumerable razorFiles = dte.Solution.GetAllRazorFiles();
49 |
50 | foreach (string file in razorFiles)
51 | {
52 | if (!RoutingDataList.Any(_ => _.Name == file))
53 | {
54 | using (StreamReader sr = new StreamReader(file))
55 | {
56 | int row = 0;
57 | while (sr.Peek() >= 0)
58 | {
59 | rowText = sr.ReadLine();
60 |
61 | if (rowText.Contains("@page") && !rowText.StartsWith("@*"))
62 | {
63 | string content = rowText.Replace("@page", "").Replace("\"", "").Trim();
64 | RoutingDataList.Add(new RoutingItem() { Name = file, Content = content });
65 | }
66 | else if (row > 5)
67 | {
68 | break;
69 | }
70 |
71 | row++;
72 | }
73 | }
74 | }
75 | }
76 | }
77 | else
78 | {
79 | //RoutingDataList.Add(new RoutingItem() { Name = "No Project in solution or selected" });
80 | }
81 |
82 | }
83 | catch (Exception ex)
84 | {
85 |
86 | }
87 | RoutingGrid.ItemsSource = RoutingDataList.OrderBy(i => i.Content);
88 | }
89 |
90 |
91 |
92 | public ObservableCollection RoutingDataList { get; set; } = new ObservableCollection();
93 |
94 | private void RefreshButton_Click(object sender, RoutedEventArgs e)
95 | {
96 | Load();
97 | }
98 |
99 | private void RoutingGrid_MouseDoubleClick(object sender, System.Windows.Input.MouseButtonEventArgs e)
100 | {
101 | if (!(ItemsControl.ContainerFromElement((DataGrid)sender, e.OriginalSource as DependencyObject) is DataGridRow row))
102 | {
103 | return;
104 | }
105 |
106 | RoutingItem item = (RoutingItem)row.DataContext;
107 | ThreadHelper.ThrowIfNotOnUIThread();
108 | if (!string.IsNullOrEmpty(item.Name))
109 | {
110 | _ = dte.ItemOperations.OpenFile(item.Name);
111 | }
112 | }
113 |
114 | private void TextBox_TextChanged(object sender, TextChangedEventArgs e)
115 | {
116 | var textbox = sender as TextBox;
117 | var searchtext = textbox.Text;
118 | if (searchtext != null)
119 | {
120 | RoutingGrid.ItemsSource = RoutingDataList.Where(i => i.Content.Contains(searchtext)).OrderBy(i => i.Name);
121 | }
122 | }
123 |
124 |
125 | public static List GetAllRoutesFromAssembly(EnvDTE.Solution solution)
126 | {
127 | ThreadHelper.ThrowIfNotOnUIThread();
128 | List items = new List();
129 | Projects projects = solution.Projects;
130 | foreach (EnvDTE.Project project in projects)
131 | {
132 |
133 | var activeProject = project;
134 | string outputDir = activeProject?.ConfigurationManager?.ActiveConfiguration?.Properties?.Item("OutputPath")?.Value?.ToString()??"";
135 | string outputFileName = activeProject?.Properties?.Item("OutputFileName")?.Value?.ToString()??"";
136 | string projectDir = activeProject?.Properties?.Item("FullPath")?.Value?.ToString()??"";
137 |
138 | string fullPath = Path.Combine(projectDir, outputDir, outputFileName);
139 |
140 | if (File.Exists(fullPath))
141 | {
142 | var readerParameters = new ReaderParameters { ReadSymbols = true };
143 | var types = Mono.Cecil.AssemblyDefinition
144 | .ReadAssembly(fullPath, readerParameters)
145 | .MainModule
146 | .Types
147 | .Where(_ => _.IsPublic && _.CustomAttributes.Any(ca => ca.AttributeType.Name == "RouteAttribute"));
148 |
149 | foreach (var t in types)
150 | {
151 | var m = t.Methods.FirstOrDefault(_ => _.DebugInformation.HasSequencePoints);
152 | var a = t.CustomAttributes.Where(_ => _.AttributeType.Name == "RouteAttribute");
153 |
154 | string sourceFile = "";
155 | //Find the line source file and line number
156 | if (m != null)
157 | {
158 | var line = m.DebugInformation.SequencePoints.FirstOrDefault();
159 | if (line != null)
160 | {
161 | //If the source file is a cs file, see if there is a .razor file.
162 | //If so, use that instead
163 | if (line.Document.Url.EndsWith(".razor.cs"))
164 | {
165 | var razorFile = line.Document.Url.TrimEnd(".cs".ToCharArray());
166 | if (File.Exists(razorFile))
167 | {
168 | sourceFile = razorFile;
169 | }
170 | else
171 | {
172 | sourceFile = line.Document.Url;
173 | }
174 | }
175 | else
176 | {
177 | sourceFile = line.Document.Url;
178 | }
179 | }
180 | }
181 | if (!string.IsNullOrEmpty(sourceFile))
182 | {
183 | foreach (var item in a)
184 | {
185 | var routingitem = new RoutingItem();
186 | var route = item.ConstructorArguments[0].Value.ToString();
187 | routingitem.Name = sourceFile;
188 | routingitem.Content = route;
189 | items.Add(routingitem);
190 | }
191 | }
192 | }
193 | }
194 | }
195 | return items;
196 | }
197 |
198 | private static string GetRouteFromComponent(Type component)
199 | {
200 | var attributes = component.GetCustomAttributes(inherit: true);
201 |
202 | var routeAttribute = attributes.Where(a => a.GetType().Name == "RouteAttribute").FirstOrDefault();
203 |
204 | if (routeAttribute is null)
205 | {
206 | // Only map routable components
207 | return null;
208 | }
209 |
210 | var route = routeAttribute.GetType().GetProperty("Template").GetValue(routeAttribute, null).ToString();
211 |
212 | //if (string.IsNullOrEmpty(route))
213 | //{
214 | // throw new Exception($"RouteAttribute in component '{component}' has empty route template");
215 | //}
216 |
217 |
218 | return route;
219 | }
220 |
221 | }
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Extensions/EnvDteExtensionMethods.cs:
--------------------------------------------------------------------------------
1 | using EnvDTE;
2 | using System.Collections.Generic;
3 | using System.IO;
4 | using BlazmExtension.Singletons;
5 | using Project = EnvDTE.Project;
6 |
7 | namespace BlazmExtension.Extensions
8 | {
9 | public static class EnvDteExtensionMethods
10 | {
11 |
12 |
13 |
14 |
15 | public static IEnumerable GetAllRazorFiles(this EnvDTE.Solution solution)
16 | {
17 | if (solution == null)
18 | {
19 | yield break;
20 | }
21 |
22 | ThreadHelper.ThrowIfNotOnUIThread();
23 |
24 | var componentNames = new List();
25 | Projects projects = solution.Projects;
26 | foreach (Project project in projects)
27 | {
28 | foreach (string fileName in ProcessProjectForRazorFiles(project))
29 | {
30 | var componentName = Path.GetFileNameWithoutExtension(fileName);
31 | componentNames.Add(componentName);
32 | yield return fileName;
33 | }
34 | }
35 | ComponentNameProvider.SetComponentNames(componentNames);
36 | }
37 |
38 | private static IEnumerable ProcessProjectForRazorFiles(Project project)
39 | {
40 | ThreadHelper.ThrowIfNotOnUIThread();
41 |
42 | if (project.ProjectItems != null) // Solution folder
43 | {
44 | foreach (ProjectItem subProjectItem in project.ProjectItems)
45 | {
46 | foreach (var razorFile in ProcessProjectItemForRazorFiles(subProjectItem))
47 | {
48 | yield return razorFile;
49 | }
50 | }
51 | }
52 | }
53 |
54 | private static IEnumerable ProcessProjectItemForRazorFiles(ProjectItem projectItem)
55 | {
56 | ThreadHelper.ThrowIfNotOnUIThread();
57 |
58 | if (projectItem == null)
59 | {
60 | yield break;
61 | }
62 |
63 | if (projectItem.Kind == Constants.vsProjectItemKindPhysicalFile)
64 | {
65 | if (projectItem.Name.EndsWith(".razor", StringComparison.OrdinalIgnoreCase))
66 | {
67 | yield return projectItem.FileNames[0];
68 | }
69 | }
70 | else if (projectItem.Kind == Constants.vsProjectItemKindPhysicalFolder ||
71 | projectItem.Kind == Constants.vsProjectItemKindVirtualFolder ||
72 | projectItem.Kind == Constants.vsProjectItemKindSolutionItems)
73 | {
74 | if (projectItem.ProjectItems != null)
75 | {
76 | foreach (ProjectItem subItem in projectItem.ProjectItems)
77 | {
78 | foreach (string file in ProcessProjectItemForRazorFiles(subItem))
79 | {
80 | yield return file;
81 | }
82 | }
83 | }
84 |
85 | if (projectItem.SubProject != null)
86 | {
87 | foreach (string file in ProcessProjectForRazorFiles(projectItem.SubProject))
88 | {
89 | yield return file;
90 | }
91 | }
92 | }
93 | }
94 | }
95 | }
96 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Extensions/ProjectHelpers.cs:
--------------------------------------------------------------------------------
1 | using EnvDTE;
2 | using Mono.Cecil;
3 | using System;
4 | using System.Collections.Generic;
5 | using System.IO;
6 | using System.Linq;
7 | using System.Text;
8 | using System.Threading.Tasks;
9 |
10 | namespace BlazmExtension.Extensions
11 | {
12 | public class ProjectHelpers
13 | {
14 | static List GetAllProjects(Projects projects)
15 | {
16 | List allProjects = new List();
17 | foreach (EnvDTE.Project project in projects)
18 | {
19 | if (project.Kind == EnvDTE80.ProjectKinds.vsProjectKindSolutionFolder)
20 | {
21 | // This is a solution folder, need to look inside it
22 | foreach (EnvDTE.ProjectItem projectItem in project.ProjectItems)
23 | {
24 | EnvDTE.Project subProject = projectItem.Object as EnvDTE.Project;
25 | if (subProject != null)
26 | {
27 | allProjects.AddRange(GetAllProjects(new List { subProject }));
28 | }
29 | }
30 | }
31 | else
32 | {
33 | // This is a real project, add it to the list
34 | allProjects.Add(project);
35 | }
36 | }
37 | return allProjects;
38 | }
39 |
40 | static List GetAllProjects(List projects)
41 | {
42 | List allProjects = new List();
43 | foreach (EnvDTE.Project project in projects)
44 | {
45 | if (project.Kind == EnvDTE80.ProjectKinds.vsProjectKindSolutionFolder)
46 | {
47 | // This is a solution folder, need to look inside it
48 | foreach (EnvDTE.ProjectItem projectItem in project.ProjectItems)
49 | {
50 | EnvDTE.Project subProject = projectItem.Object as EnvDTE.Project;
51 | if (subProject != null)
52 | {
53 | allProjects.AddRange(GetAllProjects(new List { subProject }));
54 | }
55 | }
56 | }
57 | else
58 | {
59 | // This is a real project, add it to the list
60 | allProjects.Add(project);
61 | }
62 | }
63 | return allProjects;
64 | }
65 |
66 |
67 | public static List GetAllRazorComponentsFromAssembly(EnvDTE.Solution solution)
68 | {
69 | List items = new List();
70 | try
71 | {
72 | ThreadHelper.ThrowIfNotOnUIThread();
73 | Projects projects = solution.Projects;
74 | foreach (EnvDTE.Project project in GetAllProjects(projects))
75 | {
76 |
77 | var activeProject = project;
78 | var name = activeProject;
79 | string outputDir = activeProject?.ConfigurationManager?.ActiveConfiguration?.Properties?.Item("OutputPath")?.Value?.ToString() ?? "";
80 | string outputFileName = activeProject?.Properties?.Item("OutputFileName")?.Value?.ToString() ?? "";
81 | string projectDir = activeProject?.Properties?.Item("FullPath")?.Value?.ToString() ?? "";
82 |
83 | string fullPath = Path.Combine(projectDir, outputDir, outputFileName);
84 |
85 | if (File.Exists(fullPath))
86 | {
87 | var readerParameters = new ReaderParameters { ReadSymbols = true };
88 | using (var ass = Mono.Cecil.AssemblyDefinition.ReadAssembly(fullPath, readerParameters))
89 | {
90 | try
91 | {
92 | var types = ass.MainModule
93 | .Types
94 | .Where(_ => _.BaseType != null && _.BaseType.FullName == "Microsoft.AspNetCore.Components.ComponentBase");
95 |
96 | foreach (var t in types)
97 | {
98 | var m = t.Methods.FirstOrDefault(_ => _.DebugInformation.HasSequencePoints);
99 | var a = t.CustomAttributes.Where(_ => _.AttributeType.Name == "RouteAttribute");
100 |
101 | string sourceFile = "";
102 | //Find the line source file and line number
103 | if (m != null)
104 | {
105 | var line = m.DebugInformation.SequencePoints.FirstOrDefault();
106 | if (line != null)
107 | {
108 | //If the source file is a cs file, see if there is a .razor file.
109 | //If so, use that instead
110 | if (line.Document.Url.EndsWith(".razor.cs"))
111 | {
112 | var razorFile = line.Document.Url.TrimEnd(".cs".ToCharArray());
113 | if (File.Exists(razorFile))
114 | {
115 | sourceFile = razorFile;
116 | }
117 | else
118 | {
119 | sourceFile = line.Document.Url;
120 | }
121 | }
122 | else
123 | {
124 | sourceFile = line.Document.Url;
125 | }
126 | }
127 | }
128 |
129 | var item = new ComponentItem();
130 |
131 | item.Name = t.Name;
132 | item.TypeDefinition = t;
133 | item.FullName = t.FullName;
134 | item.Path = sourceFile;
135 | items.Add(item);
136 | }
137 | }
138 | catch (Exception ex)
139 | {
140 | }
141 | }
142 | }
143 | }
144 | }
145 | catch (Exception ex)
146 | {
147 | }
148 | return items;
149 | }
150 |
151 | }
152 | public class ComponentItem
153 | {
154 | public string Name { get; set; }
155 | public string FullName { get; set; }
156 | public string Path { get; set; }
157 | public TypeDefinition TypeDefinition { get; set; }
158 | }
159 | }
160 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Extensions/StringExtensions.cs:
--------------------------------------------------------------------------------
1 | using System.Text;
2 |
3 | namespace BlazmExtension.Extensions
4 | {
5 | public static class StringExtensions
6 | {
7 | public static string GetComponentNameOnCursor(this string lineText, int cursorPosition)
8 | {
9 | if (string.IsNullOrWhiteSpace(lineText))
10 | {
11 | return null;
12 | }
13 |
14 | int initialCursorPos = cursorPosition;
15 |
16 | string componentName = null;
17 |
18 | // 1. Start from the cursor position and move to the right until we find a closing tag
19 | while (cursorPosition < lineText.Length && lineText[cursorPosition] != '<' && lineText[cursorPosition] != '>')
20 | {
21 | cursorPosition++;
22 | }
23 |
24 | if (cursorPosition < lineText.Length && lineText[cursorPosition] == '>')
25 | {
26 | // 2. Ok, the input has a closing tag to the right, lets go back to the original cursor position
27 | // and move to the left to see if we can find an opening tag
28 | cursorPosition = initialCursorPos;
29 | while (cursorPosition >= 0 && lineText[cursorPosition] != '<' && (lineText[cursorPosition] != '>' || cursorPosition == initialCursorPos))
30 | {
31 | cursorPosition--;
32 | }
33 |
34 | if (cursorPosition >= 0 && lineText[cursorPosition] == '<')
35 | {
36 | // Ok, we found an opening tag, lets move to the right and capture the component name
37 | // NOTE: This could be an opening, closing or self-closing tag. It works the same
38 | var sb = new StringBuilder();
39 | while (cursorPosition < lineText.Length && lineText[cursorPosition] != ' ' && lineText[cursorPosition] != '>' && lineText[cursorPosition] != '\n')
40 | {
41 | if (lineText[cursorPosition] != '<' && lineText[cursorPosition] != '/')
42 | {
43 | sb.Append(lineText[cursorPosition]);
44 | }
45 | cursorPosition++;
46 | }
47 | componentName = sb.ToString();
48 | }
49 | }
50 |
51 | return componentName;
52 | }
53 | }
54 | }
55 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Extensions/TypeDefinitionExtensions.cs:
--------------------------------------------------------------------------------
1 | using Mono.Cecil;
2 | using System;
3 | using System.Collections.Generic;
4 | using System.Linq;
5 | using System.Text;
6 | using System.Threading.Tasks;
7 |
8 | namespace BlazmExtension.Extensions
9 | {
10 |
11 | internal static class TypeDefinitionExtensions
12 | {
13 | static string[] bunitIncludedTestDoubles = new[]
14 | {
15 | "Microsoft.AspNetCore.Components.WebAssembly.Hosting.IWebAssemblyHostEnvironment",
16 | "Microsoft.AspNetCore.Components.Routing.INavigationInterception",
17 | "Microsoft.AspNetCore.Components.NavigationManager",
18 | "Microsoft.JSInterop.IJSRuntime",
19 | "Microsoft.Extensions.Localization.IStringLocalizer",
20 | "Microsoft.AspNetCore.Authorization.IAuthorizationService"
21 | };
22 |
23 | //Get properties that has the attribute parameter of a type
24 | public static IEnumerable GetParameters(this TypeDefinition typeDefinition)
25 | {
26 | return typeDefinition.Properties.Where(x => x.CustomAttributes.Any(c => c.AttributeType.Name == "ParameterAttribute"));
27 | }
28 | public static IEnumerable GetCascadingParameters(this TypeDefinition typeDefinition)
29 | {
30 | return typeDefinition.Properties.Where(x => x.CustomAttributes.Any(c => c.AttributeType.Name == "CascadingParameterAttribute"));
31 | }
32 |
33 | public static IEnumerable GetParametersWithoutRenderFragments(this TypeDefinition typeDefinition)
34 | {
35 | return typeDefinition.Properties.Where(x => x.CustomAttributes.Any(c => c.AttributeType.Name == "ParameterAttribute") && !x.PropertyType.FullName.StartsWith( "Microsoft.AspNetCore.Components.RenderFragment"));
36 | }
37 |
38 | public static IEnumerable GetParametersRenderFragments(this TypeDefinition typeDefinition)
39 | {
40 | return typeDefinition.Properties.Where(x => x.CustomAttributes.Any(c => c.AttributeType.Name == "ParameterAttribute") && x.PropertyType.FullName.StartsWith("Microsoft.AspNetCore.Components.RenderFragment"));
41 | }
42 |
43 | public static string GetParameterDeclarations(this TypeDefinition typeDefinition,bool razorSyntax=true)
44 | {
45 | StringBuilder sb = new StringBuilder();
46 | if (!razorSyntax)
47 | {
48 | foreach (var property in typeDefinition.GetParametersRenderFragments())
49 | {
50 | sb.AppendLine(GetPropertyDeclaration(property, razorSyntax));
51 | }
52 | }
53 |
54 | foreach (var property in typeDefinition.GetParametersWithoutRenderFragments())
55 | {
56 | sb.AppendLine(GetPropertyDeclaration(property,razorSyntax));
57 | }
58 | foreach (var property in typeDefinition.GetCascadingParameters())
59 | {
60 | sb.AppendLine(GetPropertyDeclaration(property,razorSyntax));
61 | }
62 | return sb.ToString();
63 | }
64 |
65 | public static string GetPropertyDeclaration(PropertyDefinition property, bool razorSyntax=true)
66 | {
67 |
68 | var friendlyName = GetFriendlyTypeName(property.PropertyType);
69 | if (!razorSyntax && property.PropertyType.FullName == "Microsoft.AspNetCore.Components.RenderFragment")
70 | {
71 | friendlyName = "string";
72 | }
73 |
74 | string result = $" {friendlyName} {FirstCharToLowerCase(property.Name)}";
75 | var declaration = "default!;";
76 | if (property.PropertyType.FullName=="Microsoft.AspNetCore.Components.RenderFragment")
77 | {
78 | if (razorSyntax)
79 | {
80 | declaration = "@render me;";
81 | }
82 | else
83 | {
84 | declaration = "\"render me\";";
85 | }
86 | }
87 | else if (friendlyName == "Action")
88 | {
89 | declaration = "() => { };";
90 | }
91 | else if (friendlyName.StartsWith("Action<"))
92 | {
93 | declaration = "_ => { };";
94 | }
95 |
96 | result += $" = {declaration}";
97 | return result;
98 | }
99 |
100 | public static string GetInjectDeclarations(this TypeDefinition typeDefinition)
101 | {
102 | StringBuilder sb = new StringBuilder();
103 | //Add injects
104 | foreach (var property in typeDefinition.Properties)
105 | {
106 | if (property.CustomAttributes.Any(c => c.AttributeType.Name == "InjectAttribute"))
107 | {
108 | if (property.PropertyType.FullName == "System.Net.Http.HttpClient")
109 | {
110 | sb.AppendLine($" //Services.AddMockHttpClient(); //See this link for more information.");
111 | }
112 | else if (bunitIncludedTestDoubles.Contains(property.PropertyType.FullName))
113 | {
114 | //Skip this bUnit has a built in mock for this
115 | }
116 | else if (property.PropertyType.FullName == "Microsoft.AspNetCore.Components.Authorization.AuthenticationStateProvider")
117 | {
118 | sb.AppendLine($" var authContext = this.AddTestAuthorization();");
119 | sb.AppendLine($" //authContext.SetAuthorized(\"TEST USER\", AuthorizationState.Unauthorized);");
120 | }
121 | else
122 | {
123 | sb.AppendLine($" //Services.AddSingleton<{property.PropertyType.Name},/*Add implementation for {property.PropertyType.Name}*/>();");
124 | }
125 | }
126 | }
127 | return sb.ToString();
128 | }
129 |
130 | public static string GetFriendlyTypeName(TypeReference type)
131 | {
132 | if (type.IsGenericInstance)
133 | {
134 | var genericType = type as GenericInstanceType;
135 | if (genericType != null && genericType.ElementType.FullName == "System.Nullable`1")
136 | {
137 | return GetFriendlyTypeName(genericType.GenericArguments[0]) + "?";
138 | }
139 | }
140 |
141 | switch (type.FullName)
142 | {
143 | case "System.Int32": return "int";
144 | case "System.String": return "string";
145 | case "System.Single": return "float";
146 | case "System.Double": return "double";
147 | case "System.Byte": return "byte";
148 | case "System.Boolean": return "bool";
149 | case "System.Int16": return "short";
150 | case "System.Int64": return "long";
151 | case "System.UInt16": return "ushort";
152 | case "System.UInt32": return "uint";
153 | case "System.UInt64": return "ulong";
154 | case "System.Char": return "char";
155 | case "System.Object": return "object";
156 | case "System.Void": return "void";
157 | case "System.DateOnly": return "DateOnly";
158 | case "System.TimeOnly": return "TimeOnly";
159 | case "System.DateTime": return "DateTime";
160 | case "System.DateTimeOffset": return "DateTimeOffset";
161 | case "System.Decimal": return "decimal";
162 | case "System.Guid": return "Guid";
163 | case "System.Uri": return "Uri";
164 | case "Microsoft.AspNetCore.Components.RenderFragment": return "RenderFragment";
165 | case "Microsoft.AspNetCore.Components.EventCallback":return "Action";
166 |
167 | // ... Add more as needed
168 | default:
169 | //These could probably be handled better
170 | if (type.FullName.StartsWith("Microsoft.AspNetCore.Components.EventCallback`1"))
171 | {
172 | return type.FullName.Replace("Microsoft.AspNetCore.Components.EventCallback`1","Action");
173 | }
174 | if (type.FullName.StartsWith("Microsoft.AspNetCore.Components.RenderFragment`1"))
175 | {
176 | return type.FullName.Replace("Microsoft.AspNetCore.Components.RenderFragment`1", "RenderFragment");
177 | }
178 | return type.FullName;
179 | }
180 | }
181 |
182 |
183 | public static string FirstCharToLowerCase(string input)
184 | {
185 | if (string.IsNullOrEmpty(input))
186 | return input;
187 |
188 | return char.ToLower(input[0]) + input.Substring(1);
189 | }
190 |
191 | }
192 |
193 | }
194 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Properties/AssemblyInfo.cs:
--------------------------------------------------------------------------------
1 | using BlazmExtension;
2 | using System.Reflection;
3 | using System.Runtime.InteropServices;
4 |
5 | [assembly: AssemblyTitle(Vsix.Name)]
6 | [assembly: AssemblyDescription(Vsix.Description)]
7 | [assembly: AssemblyConfiguration("")]
8 | [assembly: AssemblyCompany(Vsix.Author)]
9 | [assembly: AssemblyProduct(Vsix.Name)]
10 | [assembly: AssemblyCopyright(Vsix.Author)]
11 | [assembly: AssemblyTrademark("")]
12 | [assembly: AssemblyCulture("")]
13 |
14 | [assembly: ComVisible(false)]
15 |
16 | [assembly: AssemblyVersion(Vsix.Version)]
17 | [assembly: AssemblyFileVersion(Vsix.Version)]
18 |
19 | namespace System.Runtime.CompilerServices
20 | {
21 | public class IsExternalInit { }
22 | }
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Resources/CSFileNode.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/BlazmExtension/BlazmExtension/Resources/CSFileNode.png
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Resources/CSRazorFile.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/BlazmExtension/BlazmExtension/Resources/CSRazorFile.png
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Resources/Icon.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/BlazmExtension/BlazmExtension/Resources/Icon.png
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Resources/Images.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/BlazmExtension/BlazmExtension/Resources/Images.png
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Resources/JSScript.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/BlazmExtension/BlazmExtension/Resources/JSScript.png
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Resources/StyleSheet.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/BlazmExtension/BlazmExtension/Resources/StyleSheet.png
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Resources/bunit.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/EngstromJimmy/Blazm.Extension/d8a951975c12de7997dbb7305af51ed9a1a05f68/BlazmExtension/BlazmExtension/Resources/bunit.png
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/Singletons/ComponentNameProvider.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 |
4 | namespace BlazmExtension.Singletons
5 | {
6 | public static class ComponentNameProvider
7 | {
8 | private static List ComponentNames { get; set; } = new List();
9 |
10 | public static void SetComponentNames(IEnumerable componentNames)
11 | {
12 | if (componentNames != null)
13 | {
14 | ComponentNames = componentNames.ToList();
15 | }
16 | }
17 | public static IEnumerable GetComponentNames()
18 | {
19 | return ComponentNames;
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/VSCommandTable.cs:
--------------------------------------------------------------------------------
1 | // ------------------------------------------------------------------------------
2 | //
3 | // This file was generated by VSIX Synchronizer
4 | //
5 | // ------------------------------------------------------------------------------
6 | namespace BlazmExtension
7 | {
8 | using System;
9 |
10 | ///
11 | /// Helper class that exposes all GUIDs used across VS Package.
12 | ///
13 | internal sealed partial class PackageGuids
14 | {
15 | public const string BlazmExtensionString = "e12b1962-2ac4-416a-af19-2c6b8731922d";
16 | public static Guid BlazmExtension = new Guid(BlazmExtensionString);
17 |
18 | public const string RazorContextGuidString = "ba1aa6e4-68f5-4a4f-97c0-cbf91710430e";
19 | public static Guid RazorContextGuid = new Guid(RazorContextGuidString);
20 |
21 | public const string RazorCsContextGuidString = "8f08cd3a-1f0b-4114-8a32-b148e8505468";
22 | public static Guid RazorCsContextGuid = new Guid(RazorCsContextGuidString);
23 |
24 | public const string CssIconsString = "7d860ae9-adfa-4fda-b13b-083a6dd309b1";
25 | public static Guid CssIcons = new Guid(CssIconsString);
26 |
27 | public const string JsIconsString = "7d860ae9-adfa-4fda-b13b-083a6dd309b0";
28 | public static Guid JsIcons = new Guid(JsIconsString);
29 |
30 | public const string RazorIconsString = "7d860ae9-adfa-4fda-b13b-083a6dd309b2";
31 | public static Guid RazorIcons = new Guid(RazorIconsString);
32 |
33 | public const string CsIconsString = "7d860ae9-adfa-4fda-b13b-083a6dd309b3";
34 | public static Guid CsIcons = new Guid(CsIconsString);
35 |
36 | public const string bunitIconsString = "7d860ae9-adfa-4fda-b13b-083a6dd309b4";
37 | public static Guid bunitIcons = new Guid(bunitIconsString);
38 | }
39 | ///
40 | /// Helper class that encapsulates all CommandIDs uses across VS Package.
41 | ///
42 | internal sealed partial class PackageIds
43 | {
44 | public const int MyMenuGroup = 0x0001;
45 | public const int RazorFileMenu = 0x0002;
46 | public const int CreatebUnitTestRazor = 0x0097;
47 | public const int CreatebUnitTestCs = 0x0098;
48 | public const int CreatebUnitTestSubMenu = 0x0099;
49 | public const int CreateIsolatedCss = 0x0100;
50 | public const int CreateIsolatedJavaScript = 0x0200;
51 | public const int CreateCodebehind = 0x0250;
52 | public const int MoveNamespace = 0x0300;
53 | public const int MoveCodebehind = 0x0400;
54 | public const int ExtractToComponent = 0x0500;
55 | public const int RoutingWindow = 0x0600;
56 | public const int SwitchToNestedFile = 0x0700;
57 | public const int CreatebUnitTestGroup = 0x0800;
58 | public const int BlazmExtensionMenuGroup = 0x1020;
59 | public const int BlazmExtensionMenu = 0x1021;
60 | public const int CreatebUnitTestSubMenuGroup = 0x1022;
61 | public const int cssIcon = 0x0001;
62 | public const int jsIcon = 0x0001;
63 | public const int razorIcon = 0x0001;
64 | public const int csIcon = 0x0001;
65 | public const int FindComponentUsages = 0x0800;
66 | public const int FindComponentUsagesSE = 0x0900;
67 | public const int QuickSave = 0x1023;
68 | public const int RunDotnetWatch = 0x1024;
69 | }
70 | }
--------------------------------------------------------------------------------
/BlazmExtension/BlazmExtension/VSCommandTable.vsct:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
15 |
18 |
19 |
22 |
23 |
26 |
27 |
30 |
31 |
32 |
33 |
34 |
35 |
36 |
37 |
38 |
40 |
41 |
42 |
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 |
179 |
180 |
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 |
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 |
--------------------------------------------------------------------------------