-
Notifications
You must be signed in to change notification settings - Fork 229
Unskip cohosting diagnostics tests #11541
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
davidwengier
merged 6 commits into
dotnet:main
from
davidwengier:UnskipCohostDiagnosticsTests
Feb 25, 2025
Merged
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
8a80a1e
Unskip tests
davidwengier 45906d1
Don't use FilePathService in cohosting, it won't work
davidwengier c9354ef
Prevent tests from doing bad things in cohosting
davidwengier 9a75919
Clean up
davidwengier 59dd951
Fix logic
davidwengier 6f5c1e4
Unify logic
davidwengier File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...or/src/Microsoft.VisualStudio.LanguageServices.Razor/Extensions/TextDocumentExtensions.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // Copyright (c) .NET Foundation. All rights reserved. | ||
| // Licensed under the MIT license. See License.txt in the project root for license information. | ||
|
|
||
| using System.Diagnostics.CodeAnalysis; | ||
| using System.IO; | ||
| using Microsoft.CodeAnalysis; | ||
| using Microsoft.NET.Sdk.Razor.SourceGenerators; | ||
|
|
||
| namespace Microsoft.VisualStudio.Razor.Extensions; | ||
|
|
||
| internal static class TextDocumentExtensions | ||
| { | ||
| /// <summary> | ||
| /// This method tries to compute the source generated hint name for a Razor document using only string manipulation | ||
| /// </summary> | ||
| /// <remarks> | ||
| /// This should only be used in the devenv process. In OOP we can look at the actual generated run result to find this | ||
| /// information. | ||
| /// </remarks> | ||
| public static bool TryComputeHintNameFromRazorDocument(this TextDocument razorDocument, [NotNullWhen(true)] out string? hintName) | ||
| { | ||
| if (razorDocument.FilePath is null) | ||
| { | ||
| hintName = null; | ||
| return false; | ||
| } | ||
|
|
||
| var projectBasePath = Path.GetDirectoryName(razorDocument.Project.FilePath); | ||
| var relativeDocumentPath = razorDocument.FilePath[projectBasePath.Length..].TrimStart('/', '\\'); | ||
| hintName = RazorSourceGenerator.GetIdentifierFromPath(relativeDocumentPath); | ||
|
|
||
| return hintName is not null; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@chsienki Do you think this is reliable enough?
Alternative would be to see if we can expose a method through our EA that computes the path, including the generator Guid or whatever goo is put in there, except I'm not sure if thats possible in devenv anyway.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, so the code in roslyn that generates the full path to the generated file is pretty simple, but not public https://github.com/dotnet/roslyn/blob/e7f61a2c04c6964b0cb431a15c77dd58da7e453a/src/Compilers/Core/Portable/SourceGeneration/GeneratorDriver.cs#L440 and I don't think we're likely to want to depend on it.
Given that I think this approach seems safe enough?
I'm not sure the context in which is this is called. Presumably
TextDocumentis the actual.razordocument? I also assume at this point we don't have access to any of the razor-specific stuff, so it's just sort of an opaque file with some text in it?I'm just trying to wonder if we can centralize the hint name stuff somewhere so that it's a property of a razor document which the generator just uses as-is. Then we don't need to 'go to' the generator to get it. It probably doesn't make much difference though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, this case specifically is complicated by being in devenv, not OOP, so
razorDocumentis just an additional file in a Roslyn project.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also brings up TargetPath stuff we've talked about too. That is essentially what this is producing, and it matches what we do in tests for the generated
.editorconfig, but we've talked about moving that into the generator too. Would be nice if we had one method to call that did the computation in future.