-
Notifications
You must be signed in to change notification settings - Fork 1
allow options to be overriden #2262
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
Changes from all commits
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 | ||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -643,7 +643,7 @@ public GeneratorTestContextBuilder AddMarkup(string name, CodeMarkup source) | |||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| return this with | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| _markedLocations = _markedLocations.Add(name, new(source.Location, source.Trigger)), | ||||||||||||||||||||||||||||||||||||
| _markedLocations = _markedLocations.SetItem(name, new(source.Location, source.Trigger)), | ||||||||||||||||||||||||||||||||||||
| _sources = _sources.Add(new(SourceText.From(source.Code, Encoding.UTF8)) { Name = name, }), | ||||||||||||||||||||||||||||||||||||
| }; | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
@@ -726,14 +726,14 @@ public GeneratorTestContextBuilder AddAdditionalTexts(params IEnumerable<Additio | |||||||||||||||||||||||||||||||||||
| public GeneratorTestContextBuilder AddOption(string path, string key, string value) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| var rootOptions = _options; | ||||||||||||||||||||||||||||||||||||
| if (rootOptions.TryGetValue(path, out var fileOptions)) | ||||||||||||||||||||||||||||||||||||
| if (_options.TryGetValue(path, out var fileOptions)) | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| fileOptions = fileOptions.Add(key, value); | ||||||||||||||||||||||||||||||||||||
| fileOptions = fileOptions.SetItem(key, value); | ||||||||||||||||||||||||||||||||||||
| rootOptions = rootOptions.SetItem(path, fileOptions); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
| else | ||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||
| rootOptions = rootOptions.SetItem(path, ImmutableDictionary<string, string>.Empty.Add(key, value)); | ||||||||||||||||||||||||||||||||||||
| rootOptions = rootOptions.SetItem(path, ImmutableDictionary<string, string>.Empty.SetItem(key, value)); | ||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| return this with { _options = rootOptions, }; | ||||||||||||||||||||||||||||||||||||
|
Comment on lines
728
to
739
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. ⚪ LOW RISK Suggestion: This logic can be simplified to a single expression using
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
|
@@ -745,7 +745,7 @@ public GeneratorTestContextBuilder AddOption(string path, string key, string val | |||||||||||||||||||||||||||||||||||
| /// <param name="key"></param> | ||||||||||||||||||||||||||||||||||||
| /// <param name="value"></param> | ||||||||||||||||||||||||||||||||||||
| /// <returns></returns> | ||||||||||||||||||||||||||||||||||||
| public GeneratorTestContextBuilder AddGlobalOption(string key, string value) => this with { _globalOptions = _globalOptions.Add(key, value), }; | ||||||||||||||||||||||||||||||||||||
| public GeneratorTestContextBuilder AddGlobalOption(string key, string value) => this with { _globalOptions = _globalOptions.SetItem(key, value), }; | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| /// <summary> | ||||||||||||||||||||||||||||||||||||
| /// Create the <see cref="GeneratorTestContext" /> from the builder | ||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,4 +1,4 @@ | ||||||||||||||||||||||
| using System.Collections.Immutable; | ||||||||||||||||||||||
| using System.Collections.Immutable; | ||||||||||||||||||||||
| using Microsoft.CodeAnalysis; | ||||||||||||||||||||||
| using Microsoft.CodeAnalysis.Diagnostics; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
|
|
@@ -17,7 +17,7 @@ | |||||||||||||||||||||
| if (!options.TryGetValue(tree.FilePath, out var value)) return GlobalOptions; | ||||||||||||||||||||||
| foreach (var v in globalOptions.Where(v => !value.ContainsKey(v.Key))) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| value = value.Add(v.Key, v.Value); | ||||||||||||||||||||||
| value = value.SetItem(v.Key, v.Value); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return new OptionsObject(value); | ||||||||||||||||||||||
|
Comment on lines
17
to
23
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. ⚪ LOW RISK Suggestion: This merge logic can be simplified and made more efficient by using
Suggested change
|
||||||||||||||||||||||
|
|
@@ -28,24 +28,16 @@ | |||||||||||||||||||||
| if (!options.TryGetValue(textFile.Path, out var value)) return GlobalOptions; | ||||||||||||||||||||||
| foreach (var v in globalOptions.Where(v => !value.ContainsKey(v.Key))) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| value = value.Add(v.Key, v.Value); | ||||||||||||||||||||||
| value = value.SetItem(v.Key, v.Value); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| return new OptionsObject(value); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| private sealed class OptionsObject : AnalyzerConfigOptions | ||||||||||||||||||||||
| private sealed class OptionsObject(ImmutableDictionary<string, string> properties) : AnalyzerConfigOptions | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| private readonly ImmutableDictionary<string, string> _properties; | ||||||||||||||||||||||
| private readonly ImmutableDictionary<string, string> _properties = properties; | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public OptionsObject(ImmutableDictionary<string, string> properties) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| _properties = properties; | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
|
|
||||||||||||||||||||||
| public override bool TryGetValue(string key, [NotNullWhen(true)] out string? value) | ||||||||||||||||||||||
| { | ||||||||||||||||||||||
| return _properties.TryGetValue(key, out value); | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| public override bool TryGetValue(string key, [NotNullWhen(true)] out string? value) => _properties.TryGetValue(key, out value); | ||||||||||||||||||||||
|
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. 🔴 HIGH RISK The |
||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
| } | ||||||||||||||||||||||
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.
🟡 MEDIUM RISK
While
_markedLocationswas updated toSetItemto allow overriding,_sourcesremains additive. To fully support overriding markup, the existing source with the same name must be replaced in the_sourcescollection; otherwise, the compilation will contain multiple files with the same name, leading to 'Duplicate type defined' compiler errors (e.g., CS0101).