Skip to content

Fix #26358: AbstractDocumentationCommentCommandHandler has hardcoded Windows line ending#27626

Merged
jasonmalinowski merged 2 commits intodotnet:masterfrom
DavidKarlas:fixDocumentationComments
Jun 11, 2018
Merged

Fix #26358: AbstractDocumentationCommentCommandHandler has hardcoded Windows line ending#27626
jasonmalinowski merged 2 commits intodotnet:masterfrom
DavidKarlas:fixDocumentationComments

Conversation

@DavidKarlas
Copy link
Copy Markdown
Contributor

I used \n and \r\n in string instead @"" because as far as I understand on Windows/CI code is checked out with git config core.autocrlf which means it modifies line endings...

Customer scenario

If customer uses \n for line endings and has appropriate formatting setting set, every time documentation after /// is inserted it inserted \r\n wrongly.

Bugs this fixes

#26358

Workarounds, if any

None.

Risk

Fix is pretty small, so I would say it's unlikely to cause regressions.

Performance impact

I don't expect changes

Is this a regression from a previous update?

No.

Root cause analysis

There was commented code that would support thiis, so I would assume reason was just not caring about \n scenario. Unit test is added.

How was the bug found?

While integrating this command with VSfM.

Test documentation updated?

Unit tests should be sufficient.

@DavidKarlas DavidKarlas requested a review from a team as a code owner June 8, 2018 12:50
…coded Windows line ending

I used `\n` and `\r\n` in string instead `@""` because as far as I understand on Windows/CI code is checked out with `git config core.autocrlf` which means it modifies line endings...
@DavidKarlas DavidKarlas force-pushed the fixDocumentationComments branch from a63d7a4 to 5508d1c Compare June 8, 2018 13:23
@jinujoseph jinujoseph added this to the 15.8 milestone Jun 8, 2018
@DavidKarlas
Copy link
Copy Markdown
Contributor Author

Hmm, looks like unit tests infrastructure just replace \n with \r\n, not sure how to unit test this, should I disable my new unit test until infrastructure is updated to handle working with \n, problem is at https://github.com/dotnet/roslyn/blob/master/src/EditorFeatures/TestUtilities/Extensions/XElementExtensions.cs#L12 ...

>	Roslyn.Services.Test.Utilities.dll!Microsoft.CodeAnalysis.Editor.UnitTests.Extensions.XElementExtensions.NormalizedValue(System.Xml.Linq.XElement element) Line 12	C#
 	Roslyn.Services.Test.Utilities.dll!Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.CreateDocument(Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace workspace, System.Xml.Linq.XElement workspaceElement, System.Xml.Linq.XElement documentElement, string language, Microsoft.VisualStudio.Composition.ExportProvider exportProvider, Microsoft.CodeAnalysis.Host.HostLanguageServices languageServiceProvider, System.Collections.Generic.Dictionary<string, Microsoft.VisualStudio.Text.ITextBuffer> filePathToTextBufferMap, ref int documentId) Line 648	C#
 	Roslyn.Services.Test.Utilities.dll!Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.CreateProject(System.Xml.Linq.XElement workspaceElement, System.Xml.Linq.XElement projectElement, Microsoft.VisualStudio.Composition.ExportProvider exportProvider, Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace workspace, System.Collections.Generic.Dictionary<System.Xml.Linq.XElement, string> documentElementToFilePath, System.Collections.Generic.Dictionary<string, Microsoft.VisualStudio.Text.ITextBuffer> filePathToTextBufferMap, ref int projectId, ref int documentId) Line 298	C#
 	Roslyn.Services.Test.Utilities.dll!Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.Create(System.Xml.Linq.XElement workspaceElement, bool completed, bool openDocuments, Microsoft.VisualStudio.Composition.ExportProvider exportProvider, string workspaceKind) Line 99	C#
 	Roslyn.Services.Test.Utilities.dll!Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.Create(string language, Microsoft.CodeAnalysis.CompilationOptions compilationOptions, Microsoft.CodeAnalysis.ParseOptions parseOptions, string[] files, Microsoft.VisualStudio.Composition.ExportProvider exportProvider, string[] metadataReferences, string workspaceKind, string extension, bool commonReferences, bool openDocuments) Line 166	C#
 	Roslyn.Services.Test.Utilities.dll!Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.CreateCSharp(string[] files, Microsoft.CodeAnalysis.ParseOptions parseOptions, Microsoft.CodeAnalysis.CompilationOptions compilationOptions, Microsoft.VisualStudio.Composition.ExportProvider exportProvider, string[] metadataReferences, bool openDocuments) Line 231	C#
 	Roslyn.Services.Test.Utilities.dll!Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace.CreateCSharp(string file, Microsoft.CodeAnalysis.ParseOptions parseOptions, Microsoft.CodeAnalysis.CompilationOptions compilationOptions, Microsoft.VisualStudio.Composition.ExportProvider exportProvider, string[] metadataReferences, bool openDocuments) Line 220	C#
 	Roslyn.Services.Editor.CSharp.UnitTests.dll!Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.DocumentationComments.DocumentationCommentTests.CreateTestWorkspace(string code) Line 1947	C#
 	Roslyn.Services.Test.Utilities.dll!Microsoft.CodeAnalysis.Editor.UnitTests.DocumentationComments.AbstractDocumentationCommentTests.Verify(string initialMarkup, string expectedMarkup, bool useTabs, bool autoGenerateXmlDocComments, System.Action<Microsoft.VisualStudio.Text.Editor.IWpfTextView, Microsoft.VisualStudio.Text.Operations.ITextUndoHistoryRegistry, Microsoft.VisualStudio.Text.Operations.IEditorOperationsFactoryService, Microsoft.CodeAnalysis.Editor.IAsyncCompletionService> execute, System.Action<Microsoft.CodeAnalysis.Editor.UnitTests.Workspaces.TestWorkspace> setOptionsOpt, string newLine) Line 125	C#
 	Roslyn.Services.Test.Utilities.dll!Microsoft.CodeAnalysis.Editor.UnitTests.DocumentationComments.AbstractDocumentationCommentTests.VerifyTypingCharacter(string initialMarkup, string expectedMarkup, bool useTabs, bool autoGenerateXmlDocComments, string newLine) Line 34	C#
 	Roslyn.Services.Editor.CSharp.UnitTests.dll!Microsoft.CodeAnalysis.Editor.CSharp.UnitTests.DocumentationComments.DocumentationCommentTests.TypingCharacter_Class_NewLine() Line 45	C#

…t infrastructure assumption that all code is `\r\n`
@DavidKarlas
Copy link
Copy Markdown
Contributor Author

@dotnet-bot retest windows_debug_vs-integration_prtest please
and don't fail, thank you

@DavidKarlas
Copy link
Copy Markdown
Contributor Author

@dotnet-bot retest windows_debug_vs-integration_prtest please

private string GetNewLine(SourceText text)
{
// return editorOptionsFactoryService.GetEditorOptions(text).GetNewLineCharacter();
return "\r\n";
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

🤦‍♂️

@jasonmalinowski jasonmalinowski requested a review from a team June 8, 2018 19:55
@jinujoseph
Copy link
Copy Markdown
Contributor

Approved to merge for 15.8.Preview4

@jasonmalinowski jasonmalinowski merged commit d6a304f into dotnet:master Jun 11, 2018
@jasonmalinowski
Copy link
Copy Markdown
Member

Thanks @DavidKarlas for the fix! I worry there are plenty more of these hiding...

@DavidKarlas
Copy link
Copy Markdown
Contributor Author

@jasonmalinowski first step in finding them would be removing hacks like https://github.com/dotnet/roslyn/blob/master/src/EditorFeatures/TestUtilities/Extensions/XElementExtensions.cs#L12 and not using git config core.autocrlf and work with source code as is, and not manipulate it differently on every machine o.O

@DavidKarlas DavidKarlas deleted the fixDocumentationComments branch June 11, 2018 16:55
@jasonmalinowski
Copy link
Copy Markdown
Member

Well, at the time NormalizedValue wasn't a hack: VB XML literals follow the XML spec which state that they're linefeed only even on Windows machines -- hence that converts to what we expected at the time.

That said, I'd be 100% for using the platform's line endings in tests, and then just enabling our tests on Linux/Mac runs. Thoughts?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants