-
Notifications
You must be signed in to change notification settings - Fork 4k
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
Treat decompiled sources separately from metadata sources #27940
Changes from 4 commits
022581c
5a4b1ac
4a04fae
f1ed8a7
547bac8
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,7 @@ | |
using System.Collections.Immutable; | ||
using System.IO; | ||
using System.Text; | ||
using Microsoft.CodeAnalysis.Host; | ||
using Microsoft.CodeAnalysis.Text; | ||
|
||
namespace Microsoft.CodeAnalysis.Editor.Implementation.MetadataAsSource | ||
|
@@ -21,16 +22,24 @@ internal sealed class MetadataAsSourceGeneratedFileInfo | |
|
||
private readonly ParseOptions _parseOptions; | ||
|
||
public MetadataAsSourceGeneratedFileInfo(string rootPath, Project sourceProject, INamedTypeSymbol topLevelNamedType) | ||
public MetadataAsSourceGeneratedFileInfo(string rootPath, Project sourceProject, INamedTypeSymbol topLevelNamedType, bool allowDecompilation) | ||
{ | ||
this.SourceProjectId = sourceProject.Id; | ||
_parseOptions = sourceProject.ParseOptions; | ||
this.Workspace = sourceProject.Solution.Workspace; | ||
this.LanguageName = sourceProject.Language; | ||
this.LanguageName = allowDecompilation ? LanguageNames.CSharp : sourceProject.Language; | ||
if (sourceProject.Language == LanguageName) | ||
{ | ||
_parseOptions = sourceProject.ParseOptions; | ||
} | ||
else | ||
{ | ||
_parseOptions = Workspace.Services.GetLanguageServices(LanguageName).GetRequiredService<ISyntaxTreeFactoryService>().GetDefaultParseOptionsWithLatestLanguageVersion(); | ||
} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: consider ?: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Opted against it here. The two branches seem different enough that I like to keep it obvious. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why still having the branches at all? When would the source project's parse options be different than the default parse options for the language in an observable way? I'm not saying there's not a reason for this....I just can't tell what it is. I can't read your mind (not sure if good thing or bad thing?) but do we need a comment here? |
||
|
||
this.References = sourceProject.MetadataReferences.ToImmutableArray(); | ||
this.AssemblyIdentity = topLevelNamedType.ContainingAssembly.Identity; | ||
|
||
var extension = sourceProject.Language == LanguageNames.CSharp ? ".cs" : ".vb"; | ||
var extension = LanguageName == LanguageNames.CSharp ? ".cs" : ".vb"; | ||
|
||
var directoryName = Guid.NewGuid().ToString("N"); | ||
this.TemporaryFilePath = Path.Combine(rootPath, directoryName, topLevelNamedType.Name + extension); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Doesn't this still need to have some differentiation for the decompiled vs. not? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It does. Two levels of directory names are used when the keys don't match; this one will still get one unique GUID in the path where before it was getting two. |
||
|
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.
i personally hate this :) but i guess i will have to grow to live with these sorts of patterns :)
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, I admire your desire to play with new things, but if we just went back to a single mutex/folder and generated the paths differently, it's just two lines with no fancy tricks whatsoever.
"If you write your code as cleverly as possible..."