Skip to content

Conversation

@sharwell
Copy link
Contributor

@sharwell sharwell commented Jun 6, 2023

Fixes #68440

@sharwell sharwell requested a review from a team as a code owner June 6, 2023 18:17
@ghost ghost added Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead labels Jun 6, 2023
#if CODE_STYLE
var info = new CSharpCodeGenerationContextInfo(
CodeGenerationContext.Default, CSharpCodeGenerationOptions.Default, new CSharpCodeGenerationService(document.Project.Services), root.SyntaxTree.Options.LanguageVersion());
CodeGenerationContext.Default, CSharpCodeGenerationOptions.Default, new CSharpCodeGenerationService(document.Project.GetExtendedLanguageServices().LanguageServices), root.SyntaxTree.Options.LanguageVersion());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 This fixes the root cause of the bug


internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
=> (new CSharpUseLocalFunctionDiagnosticAnalyzer(), GetCSharpUseLocalFunctionCodeFixProvider());
=> (new CSharpUseLocalFunctionDiagnosticAnalyzer(), new CSharpUseLocalFunctionCodeFixProvider());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 This fixes the failure to identify the bug in testing

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@sharwell I'm very surprised. The deleted GetCSharpUseLocalFunctionCodeFixProvider method exactly does new CSharpUseLocalFunctionCodeFixProvider(), how that would matter in identifying the bug in testing?

Copy link
Contributor Author

@sharwell sharwell Jun 7, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ There are two instances of this type: one in the code style layer, and one in the features layer. Previously, when tests compiled in the code style layer they were still using the fixer from the features layer. The relocated instantiation binds to the other type, so tests in the code style layer use the fix from the code style layer.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Makes sense! Thanks @sharwell


internal override (DiagnosticAnalyzer, CodeFixProvider) CreateDiagnosticProviderAndFixer(Workspace workspace)
=> (new MakeLocalFunctionStaticDiagnosticAnalyzer(), GetMakeLocalFunctionStaticCodeFixProvider());
=> (new MakeLocalFunctionStaticDiagnosticAnalyzer(), new MakeLocalFunctionStaticCodeFixProvider());
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

📝 This is another code fixer which was not properly tested, but there were no test failures when it was corrected

var info = new CSharpCodeGenerationContextInfo(
CodeGenerationContext.Default, CSharpCodeGenerationOptions.Default, new CSharpCodeGenerationService(document.Project.Services), root.SyntaxTree.Options.LanguageVersion());
CodeGenerationContext.Default, CSharpCodeGenerationOptions.Default, new CSharpCodeGenerationService(document.Project.GetExtendedLanguageServices().LanguageServices), root.SyntaxTree.Options.LanguageVersion());
#else
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so, this seems like something we likely need an analyzer for, right? Like it's farrrrrr too easy to screw this up.

Another option seems to be (CSharpCodeGenarationService)document.GetRequiredLanguageService<ICodeGenerationService>() (or just make CSharpCodeGenerationContextInfo take an ICodeGenService, i dont' think it needs the subtype.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

➡️ Updated BannedSymbols.txt to account for the new Services property, which was not present at the time LanguageServices property was excluded.

Copy link
Member

@CyrusNajmabadi CyrusNajmabadi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm. i think we could make this slightly nicer though by avoidign the direct casll to GetExtendedLanguageServices here.

@sharwell sharwell merged commit ce5a320 into dotnet:main Jun 8, 2023
@ghost ghost added this to the Next milestone Jun 8, 2023
@sharwell sharwell deleted the fix-service branch June 8, 2023 14:41
@RikkiGibson RikkiGibson modified the milestones: Next, 17.7 P3 Jun 28, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area-IDE untriaged Issues and PRs which have not yet been triaged by a lead

Projects

None yet

Development

Successfully merging this pull request may close these issues.

CodeFixProvider throws InvalidOperationException: 'ISymbolDeclarationService' is required to accomplish the task but is not available from the workspace

4 participants