提交 6aad4d42 编写于 作者: C Cyrus Najmabadi

Support wrap and align, and wrap without align

上级 5ae0f39d
......@@ -21,6 +21,11 @@ private class BinaryExpressionCodeActionComputer :
private readonly ImmutableArray<SyntaxNodeOrToken> _exprsAndOperators;
private readonly OperatorPlacementWhenWrappingPreference _preference;
/// <summary>
/// trivia to place at the end of a node prior to a chunk that is wrapped.
/// For C# this will just be a newline. For VB this will include a line-
/// continuation character.
/// </summary>
private readonly SyntaxTriviaList _newlineBeforeOperatorTrivia;
/// <summary>
......
......@@ -43,11 +43,6 @@ private class CallExpressionCodeActionComputer :
/// </summary>
private readonly ImmutableArray<ImmutableArray<SyntaxNodeOrToken>> _chunks;
/// <summary>
/// Trivia to place before a chunk when it is wrapped.
/// </summary>
private readonly SyntaxTriviaList _indentationTrivia;
/// <summary>
/// trivia to place at the end of a node prior to a chunk that is wrapped.
/// For C# this will just be a newline. For VB this will include a line-
......@@ -55,6 +50,18 @@ private class CallExpressionCodeActionComputer :
/// </summary>
private readonly SyntaxTriviaList _newlineBeforeOperatorTrivia;
/// <summary>
/// The indent trivia to insert if we are trying to align wrapped chunks with the
/// start of the original chunk.
/// </summary>
private readonly SyntaxTriviaList _indentAndAlignTrivia;
/// <summary>
/// The indent trivia to insert if we are trying to simply smart-indent all wrapped
/// chunks.
/// </summary>
private readonly SyntaxTriviaList _smartIndentTrivia;
public CallExpressionCodeActionComputer(
AbstractChainedExpressionWrapper<TNameSyntax, TBaseArgumentListSyntax> service,
Document document,
......@@ -71,39 +78,59 @@ private class CallExpressionCodeActionComputer :
// Both [0][0] indices are safe here. We can only get here if we had more than
// two chunks to wrap. And each chunk is required to have at least three elements
// (i.e. `. name (arglist)`).
var indentationString = OriginalSourceText.GetOffset(chunks[0][0].SpanStart)
.CreateIndentationString(UseTabs, TabSize);
var firstPeriod = chunks[0][0];
_indentAndAlignTrivia = new SyntaxTriviaList(generator.Whitespace(
OriginalSourceText.GetOffset(firstPeriod.SpanStart).CreateIndentationString(UseTabs, TabSize)));
_smartIndentTrivia = new SyntaxTriviaList(generator.Whitespace(
this.GetSmartIndentationAfter(firstPeriod)));
_indentationTrivia = new SyntaxTriviaList(generator.Whitespace(indentationString));
_newlineBeforeOperatorTrivia = service.GetNewLineBeforeOperatorTrivia(NewLineTrivia);
}
protected override async Task<ImmutableArray<WrappingGroup>> ComputeWrappingGroupsAsync()
=> ImmutableArray.Create(new WrappingGroup(
isInlinable: true, ImmutableArray.Create(
await GetWrapCodeActionAsync().ConfigureAwait(false),
await GetUnwrapCodeActionAsync().ConfigureAwait(false),
await GetWrapLongCodeActionAsync().ConfigureAwait(false))));
{
var actions = ArrayBuilder<WrapItemsAction>.GetInstance();
await AddWrapCodeActionAsync(actions).ConfigureAwait(false);
await AddUnwrapCodeActionAsync(actions).ConfigureAwait(false);
await AddWrapLongCodeActionAsync(actions).ConfigureAwait(false);
return ImmutableArray.Create(new WrappingGroup(
isInlinable: true, actions.ToImmutableAndFree()));
}
// Pass 0 as the wrapping column as we effectively always want to wrap each chunk
// Not just when the chunk would go past the wrapping column.
private Task<WrapItemsAction> GetWrapCodeActionAsync()
=> TryCreateCodeActionAsync(GetWrapEdits(wrappingColumn: 0), FeaturesResources.Wrapping, FeaturesResources.Wrap_call_chain);
private async Task AddWrapCodeActionAsync(ArrayBuilder<WrapItemsAction> actions)
{
actions.Add(await TryCreateCodeActionAsync(GetWrapEdits(wrappingColumn: 0, align: false), FeaturesResources.Wrapping, FeaturesResources.Wrap_call_chain).ConfigureAwait(false));
actions.Add(await TryCreateCodeActionAsync(GetWrapEdits(wrappingColumn: 0, align: true), FeaturesResources.Wrapping, FeaturesResources.Wrap_and_align_call_chain).ConfigureAwait(false));
}
private Task<WrapItemsAction> GetUnwrapCodeActionAsync()
=> TryCreateCodeActionAsync(GetUnwrapEdits(), FeaturesResources.Wrapping, FeaturesResources.Unwrap_call_chain);
private async Task AddUnwrapCodeActionAsync(ArrayBuilder<WrapItemsAction> actions)
{
actions.Add(await TryCreateCodeActionAsync(GetUnwrapEdits(), FeaturesResources.Wrapping, FeaturesResources.Unwrap_call_chain).ConfigureAwait(false));
}
private Task<WrapItemsAction> GetWrapLongCodeActionAsync()
=> TryCreateCodeActionAsync(GetWrapEdits(WrappingColumn), FeaturesResources.Wrapping, FeaturesResources.Wrap_long_call_chain);
private async Task AddWrapLongCodeActionAsync(ArrayBuilder<WrapItemsAction> actions)
{
actions.Add(await TryCreateCodeActionAsync(GetWrapEdits(WrappingColumn, align: false), FeaturesResources.Wrapping, FeaturesResources.Wrap_long_call_chain).ConfigureAwait(false));
actions.Add(await TryCreateCodeActionAsync(GetWrapEdits(WrappingColumn, align: true), FeaturesResources.Wrapping, FeaturesResources.Wrap_and_align_long_call_chain).ConfigureAwait(false));
}
private ImmutableArray<Edit> GetWrapEdits(int wrappingColumn)
private ImmutableArray<Edit> GetWrapEdits(int wrappingColumn, bool align)
{
var result = ArrayBuilder<Edit>.GetInstance();
// First, normalize the first chunk.
var firstChunk = _chunks[0];
DeleteAllSpacesInChunk(result, firstChunk);
var position = _indentationTrivia.FullSpan.Length + NormalizedWidth(firstChunk);
var indentationTrivia = align ? _indentAndAlignTrivia : _smartIndentTrivia;
var position = indentationTrivia.FullSpan.Length;// _indentationTrivia.FullSpan.Length + NormalizedWidth(firstChunk);
// Now, go to each subsequent chunk. If keeping it on the current line would
// cause us to go past the requested wrapping column, then wrap it and proceed.
......@@ -116,13 +143,13 @@ private ImmutableArray<Edit> GetWrapEdits(int wrappingColumn)
{
// we're wrapping. So our position is reset to the indentation
// on the next line.
position = _indentationTrivia.FullSpan.Length;
position = indentationTrivia.FullSpan.Length;
// First, add a newline at the end of the previous arglist, and then
// indent the very first member chunk appropriately.
result.Add(Edit.UpdateBetween(
_chunks[i - 1].Last(), _newlineBeforeOperatorTrivia,
_indentationTrivia, chunk[0]));
indentationTrivia, chunk[0]));
}
// Now, delete all the remaining spaces in this call chunk.
......
......@@ -110,7 +110,7 @@ private async Task AddWrappingGroups(ArrayBuilder<WrappingGroup> result)
result.Add(await GetWrapLongGroupAsync().ConfigureAwait(false));
}
#region unwrap all
#region unwrap group
private async Task<WrappingGroup> GetUnwrapGroupAsync()
{
......
......@@ -4661,16 +4661,14 @@ internal class FeaturesResources {
}
/// <summary>
/// Looks up a localized string similar to Wrap call chain.
/// Looks up a localized string similar to Wrap and align call chain.
/// </summary>
internal static string Wrap_call_chain
{
get
{
return ResourceManager.GetString("Wrap_call_chain", resourceCulture);
internal static string Wrap_and_align_call_chain {
get {
return ResourceManager.GetString("Wrap_and_align_call_chain", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Wrap and align expression.
/// </summary>
......@@ -4680,6 +4678,24 @@ internal static string Wrap_call_chain
}
}
/// <summary>
/// Looks up a localized string similar to Wrap and align long call chain.
/// </summary>
internal static string Wrap_and_align_long_call_chain {
get {
return ResourceManager.GetString("Wrap_and_align_long_call_chain", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Wrap call chain.
/// </summary>
internal static string Wrap_call_chain {
get {
return ResourceManager.GetString("Wrap_call_chain", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Wrap every argument.
/// </summary>
......
......@@ -1678,4 +1678,10 @@ This version used in: {2}</value>
<data name="DisposableFieldsShouldBeDisposedDescription" xml:space="preserve">
<value>A type that implements System.IDisposable declares fields that are of types that also implement IDisposable. The Dispose method of the field is not called by the Dispose method of the declaring type. To fix a violation of this rule, call Dispose on fields that are of types that implement IDisposable if you are responsible for allocating and releasing the unmanaged resources held by the field.</value>
</data>
<data name="Wrap_and_align_call_chain" xml:space="preserve">
<value>Wrap and align call chain</value>
</data>
<data name="Wrap_and_align_long_call_chain" xml:space="preserve">
<value>Wrap and align long call chain</value>
</data>
</root>
\ No newline at end of file
......@@ -537,11 +537,21 @@
<target state="translated">Upozornění: Změna oboru názvů může vést k vytvoření neplatného kódu a změnit význam kódu.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">Warnung: Durch die Änderung des Namespaces kann der Code ungültig werden oder seine Bedeutung verändern.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">Advertencia: si cambia Cambiar el espacio de nombres puede producir código inválido y cambiar el significado del código.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">Avertissement : Le changement d’espace de noms peut produire du code non valide et changer la signification du code.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">Avviso: la modifica dello spazio dei nomi può comportare la creazione di codice non valido e modificare il significato del codice.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">警告: 名前空間を変更すると無効なコードが生成され、コードの意味が変更される可能性があります。</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">경고: 네임스페이스를 변경하면 잘못된 코드가 발생하고 코드 의미가 변경될 수 있습니다.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">Ostrzeżenie: Zmiana przestrzeni nazw może skutkować nieprawidłowym kodem i zmianą jego znaczenia.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">Aviso: a alteração do namespace pode produzir código inválido e mudar o significado do código.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">Предупреждение: изменение пространства имен может привести к появлению недопустимого кода и к изменению значения кода.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">Uyarı: Ad alanının değiştirilmesi geçersiz kod oluşturabilir ve kodun anlamını değiştirebilir.</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">警告: 更改命名空间可能会产生无效的代码并更改代码的含义。</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
......@@ -537,11 +537,21 @@
<target state="translated">警告: 變更命名空間可能會產生無效的程式碼及變更程式碼意義。</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_call_chain">
<source>Wrap and align call chain</source>
<target state="new">Wrap and align call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_expression">
<source>Wrap and align expression</source>
<target state="new">Wrap and align expression</target>
<note />
</trans-unit>
<trans-unit id="Wrap_and_align_long_call_chain">
<source>Wrap and align long call chain</source>
<target state="new">Wrap and align long call chain</target>
<note />
</trans-unit>
<trans-unit id="Wrap_call_chain">
<source>Wrap call chain</source>
<target state="new">Wrap call chain</target>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册