Commit 262b31a
authored
Use the full file path as the target path when it's missing (#12355)
This allows projects that don't use the Razor SDK (eg,
#12332 or #12331) to have some kind of
tooling experience. They won't have a perfect one, because there is no
guarantee that the code the generator produces will compile (and in the
first linked issue, it doesn't), but it will produce something and will have
unique hint paths etc.
Projects can essentially "enable tooling" by putting this in their
project file:
```xml
<ItemGroup Condition="'$(DesignTimeBuild)' == 'true'">
<!--
The cohosting editor uses the Razor source generator for VS functionality, so we have to make sure
it can see the .cshtml files.
-->
<AdditionalFiles Include="**\*.cshtml" />
<!--
Now we have to make sure the generator is actually referenced. Luckily the Razor tooling will automatically
redirect any reference to it, to the right location of the file that ships with VS, so we don't have to care
where it actually is.
-->
<Analyzer Include="Microsoft.CodeAnalysis.Razor.Compiler.dll" />
<!--
Make sure the source generator knows where the project is, for computing target paths.
-->
<CompilerVisibleProperty Include="MSBuildProjectDirectory" />
</ItemGroup>
```
Source generator changes:
* If there is a target path supplied, use it
* If there is no target path supplied, but we know the project path,
compute a target path
* If there is no target path supplied, use the whole file path
Tooling changes:
* Instead of trying to have an algorithm perform similar logic and guess
what the source generator would have done, we just look through the
source generated documents and find a match. Full path matches always
win, otherwise project relative, being careful to watch out for
duplicates.
The "use the whole file path" change is arguably separate, and it is TBD
if it is the way we want to go. If we don't do that, it just makes the
compiler visible property part of the above required.File tree
15 files changed
+464
-272
lines changed- src
- Compiler/Microsoft.CodeAnalysis.Razor.Compiler/src
- SourceGenerators
- Razor
- src
- Microsoft.CodeAnalysis.Razor.Workspaces/Extensions
- test
- Microsoft.AspNetCore.Razor.Test.Common.Cohosting
- Microsoft.VisualStudio.LanguageServices.Razor.Test/Cohost
- Microsoft.VisualStudioCode.RazorExtension.Test
15 files changed
+464
-272
lines changedLines changed: 1 addition & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
68 | 68 | | |
69 | 69 | | |
70 | 70 | | |
| 71 | + | |
71 | 72 | | |
72 | 73 | | |
73 | 74 | | |
Lines changed: 27 additions & 15 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
77 | 77 | | |
78 | 78 | | |
79 | 79 | | |
80 | | - | |
81 | | - | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
82 | 83 | | |
83 | | - | |
84 | | - | |
85 | | - | |
86 | | - | |
87 | | - | |
88 | | - | |
89 | | - | |
90 | | - | |
91 | | - | |
92 | | - | |
93 | 84 | | |
94 | 85 | | |
95 | | - | |
| 86 | + | |
| 87 | + | |
| 88 | + | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
96 | 96 | | |
97 | | - | |
98 | | - | |
| 97 | + | |
| 98 | + | |
| 99 | + | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
| 106 | + | |
| 107 | + | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
99 | 111 | | |
100 | 112 | | |
101 | 113 | | |
| |||
Lines changed: 1 addition & 6 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
101 | 101 | | |
102 | 102 | | |
103 | 103 | | |
104 | | - | |
105 | | - | |
106 | | - | |
107 | | - | |
108 | | - | |
109 | | - | |
| 104 | + | |
110 | 105 | | |
111 | 106 | | |
112 | 107 | | |
| |||
Lines changed: 72 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
8 | 8 | | |
9 | 9 | | |
10 | 10 | | |
| 11 | + | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
15 | 16 | | |
16 | 17 | | |
| 18 | + | |
17 | 19 | | |
18 | 20 | | |
19 | 21 | | |
| |||
103 | 105 | | |
104 | 106 | | |
105 | 107 | | |
| 108 | + | |
| 109 | + | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
| 114 | + | |
| 115 | + | |
| 116 | + | |
| 117 | + | |
| 118 | + | |
| 119 | + | |
| 120 | + | |
| 121 | + | |
| 122 | + | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
| 143 | + | |
| 144 | + | |
| 145 | + | |
| 146 | + | |
| 147 | + | |
| 148 | + | |
| 149 | + | |
| 150 | + | |
| 151 | + | |
| 152 | + | |
| 153 | + | |
| 154 | + | |
| 155 | + | |
| 156 | + | |
| 157 | + | |
| 158 | + | |
| 159 | + | |
| 160 | + | |
| 161 | + | |
| 162 | + | |
| 163 | + | |
| 164 | + | |
| 165 | + | |
| 166 | + | |
| 167 | + | |
| 168 | + | |
| 169 | + | |
| 170 | + | |
| 171 | + | |
| 172 | + | |
| 173 | + | |
| 174 | + | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
106 | 178 | | |
107 | 179 | | |
108 | 180 | | |
| |||
Lines changed: 0 additions & 51 deletions
This file was deleted.
0 commit comments