Respect tabs vs spaces when generating code#1606
Conversation
|
|
||
| // Internal for testing. | ||
| internal CodeWriter Indent(int size) | ||
| public CodeWriter Indent(int size) |
There was a problem hiding this comment.
I made this public. Otherwise things in Extensions.1_X projects etc were complaining because we share CodeWriterExtensions.cs as a shared source and it uses this method.
| return base.Create(configuration, remoteFileSystem, configure); | ||
| return base.Create(configuration, remoteFileSystem, Configure); | ||
|
|
||
| void Configure(RazorProjectEngineBuilder builder) |
There was a problem hiding this comment.
I'm not completely sure if this is the right place to wire this up.
| #line default | ||
| #line hidden | ||
| #nullable disable | ||
There was a problem hiding this comment.
I'm not sure why this happened. Haven't investigated it further yet. @NTaylorMullen any ideas off the top of your head?
|
|
||
| var context = new DefaultCodeRenderingContext( | ||
| new CodeWriter(), | ||
| new CodeWriter(Environment.NewLine, _options.IndentSize, _options.IndentWithTabs), |
There was a problem hiding this comment.
The Environment.NewLine should also eventually come from options.
| } | ||
| } | ||
|
|
||
| public int TabSize { get; set; } |
| return base.Create(configuration, remoteFileSystem, configure); | ||
| return base.Create(configuration, remoteFileSystem, Configure); | ||
|
|
||
| void Configure(RazorProjectEngineBuilder builder) |
| #line default | ||
| #line hidden | ||
| #nullable disable | ||
| private int _currentLineCharacterIndex; | ||
|
|
||
| public CodeWriter() | ||
| public CodeWriter() : this(Environment.NewLine, 4, false) |
There was a problem hiding this comment.
| public CodeWriter() : this(Environment.NewLine, 4, false) | |
| public CodeWriter() : this(Environment.NewLine, 4, indentWithTabs: false) |
|
|
||
| var result = await _server.Client.SendRequest<ConfigurationParams, object[]>("workspace/configuration", request); | ||
| if (result == null || result.Length < 1 || result[0] == null) | ||
| if (result == null || result.Length < 2 || result[0] == null) |
There was a problem hiding this comment.
What makes 2 the expected length, and as a corollary, why was it one before?
There was a problem hiding this comment.
The spec says the result should be the same length as the number of ConfigurationItems we pass in. I'll leave a comment for future us.
|
|
||
| return new RazorLSPOptions(trace, enableFormatting); | ||
| var tabSize = instance.TabSize; | ||
| if (int.TryParse(config["tabSize"], out var parsedTabSize)) |
There was a problem hiding this comment.
Is there a guarantee that config will always have a tabSize?
There was a problem hiding this comment.
Guarantee is a strong word but we can expect vscode to do the right thing. Moreover, if it is not there it still won't throw. The default implementation of IConfiguration will just return null.
| } | ||
|
|
||
| var insertSpaces = instance.InsertSpaces; | ||
| if (bool.TryParse(config["insertSpaces"], out var parsedInsertSpaces)) |
|
FYI some of this PR will need to be opened against aspnetcore. Some of the projects have migrated there. |
|
Closing as we're not ready to tackle this yet. |
Fixes https://github.com/dotnet/aspnetcore/issues/18996
CodeWriterand actually use them when indenting.