-
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
write out codestyle options to include their diagnostic ids #52916
write out codestyle options to include their diagnostic ids #52916
Conversation
src/Analyzers/Core/Analyzers/IDEDiagnosticIdToOptionMappingHelper.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/EditorConfigSettings/Updater/SettingsUpdaterTests.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/EditorConfigSettings/Updater/SettingsUpdaterTests.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/EditorConfigSettings/Updater/SettingsUpdaterTests.cs
Outdated
Show resolved
Hide resolved
} | ||
|
||
var optionName = storageLocation.KeyName; | ||
var optionValue = storageLocation.GetEditorConfigStringValue(value, optionSet); | ||
var language = option.IsPerLanguage ? Language.CSharp | Language.VisualBasic : Language.CSharp; |
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 don't really get thsi. if it's not per langauge, then i would expect it to be C#/VB (As that's waht a normal option affects). if it is per-language, then i woudl expect it to pick the language based on what language the otion is intended for.
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.
@CyrusNajmabadi This is tracked by #52696.
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 is the reverse of the normal case our options operate under. Normally you get an option and you want to know what it applies to in the context of a project. For editorconfig we have the reverse problem. How should a per-language option be persisted? Do users want their single file to have duplicate language for each language type in their project? Or do they want a unified header?
I've chosen to, where possible, write out options that can apply to both languages together.
if (value is ICodeStyleOption codeStyleOption && !optionValue.Contains(':')) | ||
{ | ||
var diagnosticIds = IDEDiagnosticIdToOptionMappingHelper.GetDiagnosticIdsForOption(option, LanguageNames.CSharp); // TODO handle VB |
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.
seems important :)
src/EditorFeatures/Core/EditorConfigSettings/Updater/SettingsUpdateHelper.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/Core/EditorConfigSettings/Updater/SettingsUpdateHelper.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/Core/EditorConfigSettings/Updater/SettingsUpdateHelper.cs
Outdated
Show resolved
Hide resolved
// Verify the option name matches | ||
if (string.Equals(key, optionName, StringComparison.OrdinalIgnoreCase)) | ||
{ | ||
var sb = new StringBuilder($"{optionName}={optionValue}\r\n"); |
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.
should we be hardcoding \r\n in these guys? my preference woudl at least be that that's a constant defined somewhere in this file, so we can tweak this at will, or use an env variable, or allow this to be passed in.
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.
yep I have it in a todo to actually try and get the users newline preferences for this file type if possible. In the meantime the codefix for editorconfig has been writing out \r\n
since mid 2019.
src/EditorFeatures/Core/EditorConfigSettings/Updater/SettingsUpdateHelper.cs
Show resolved
Hide resolved
src/EditorFeatures/CSharpTest/EditorConfigSettings/Updater/SettingsUpdaterTests.cs
Outdated
Show resolved
Hide resolved
src/EditorFeatures/Core/EditorConfigSettings/Updater/SettingsUpdateHelper.cs
Outdated
Show resolved
Hide resolved
{ | ||
lastValidSpecificHeaderSpanEnd = curLine; | ||
} | ||
} | ||
} |
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 admit my eyes glazed over with all the string processing. i really don't have any idea if this is right or not. Note: we have a generalized pattern matching system in Roslyn for matching over sequences of elements. it might be worthwhile seeing if we could use that. but it might also be overkill.
my primary concern here is that there seems to be a bunch of complexity here that would likely be good to extrac tout into small types that are responsibel for just one thing. i.e. this is the type that just finds the relevant portions of a chunk of hte editorconfig file.
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.
yep, I hope to do a big refactor as part of #52735 and clean all this up
// Replacing characters in the header with the regex equivalent. | ||
fileName = fileName.Replace(".", @"\."); | ||
fileName = fileName.Replace("*", ".*"); | ||
fileName = fileName.Replace("/", @"\/"); |
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 feels unsafe. lots of other filename characters would violate regex semantics.
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.
every editorconfig parsers I am aware of also use regex for this including the one in the compiler. The correct thing to do is to unify all this parser logic with the compilers implementation.
fixes #52720