Skip to content
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

Conversation

jmarolf
Copy link
Contributor

@jmarolf jmarolf commented Apr 26, 2021

fixes #52720

@jmarolf jmarolf requested a review from a team as a code owner April 26, 2021 17:15
}

var optionName = storageLocation.KeyName;
var optionValue = storageLocation.GetEditorConfigStringValue(value, optionSet);
var language = option.IsPerLanguage ? Language.CSharp | Language.VisualBasic : Language.CSharp;
Copy link
Member

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.

Copy link
Member

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.

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 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
Copy link
Member

Choose a reason for hiding this comment

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

seems important :)

// Verify the option name matches
if (string.Equals(key, optionName, StringComparison.OrdinalIgnoreCase))
{
var sb = new StringBuilder($"{optionName}={optionValue}\r\n");
Copy link
Member

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.

Copy link
Contributor Author

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.

{
lastValidSpecificHeaderSpanEnd = curLine;
}
}
}
Copy link
Member

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.

Copy link
Contributor Author

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("/", @"\/");
Copy link
Member

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.

Copy link
Contributor Author

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.

@jmarolf jmarolf changed the base branch from main to release/dev16.10 April 27, 2021 23:49
@jmarolf jmarolf closed this May 18, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New Editorconfig UX does not use the correct syntax for updating severity of IDE code style
4 participants