Use config instead of parameter for query editor result copy and fix some wording (#2124)

* Fix typo and update wording

* use config instead of parameter for copying result
This commit is contained in:
Hai Cao
2023-06-27 16:44:23 -07:00
committed by GitHub
parent 4334d79d76
commit 33b5cb98cd
5 changed files with 78 additions and 18 deletions

View File

@@ -22,21 +22,6 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution.Contracts
/// </summary> /// </summary>
public class CopyResultsRequestParams : SubsetParams public class CopyResultsRequestParams : SubsetParams
{ {
/// <summary>
/// Whether to remove the line break from cell values.
/// </summary>
public bool RemoveNewLines { get; set; }
/// <summary>
/// Whether to avoid adding a line break between rows during row concatenation for copying result when the previous row already has a trailing line break.
/// </summary>
public bool AvoidNewLineAfterTailingLineBreak { get; set; }
/// <summary>
/// Whether to include the column headers.
/// </summary>
public bool IncludeHeaders { get; set; }
/// <summary> /// <summary>
/// The selections. /// The selections.
/// </summary> /// </summary>

View File

@@ -729,7 +729,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
var lastRowIndex = rowRanges.Last().End; var lastRowIndex = rowRanges.Last().End;
var builder = new StringBuilder(); var builder = new StringBuilder();
var pageSize = 200; var pageSize = 200;
if (requestParams.IncludeHeaders) if (Settings.QueryEditorSettings.Results.CopyIncludeHeaders)
{ {
Validate.IsNotNullOrEmptyString(nameof(requestParams.OwnerUri), requestParams.OwnerUri); Validate.IsNotNullOrEmptyString(nameof(requestParams.OwnerUri), requestParams.OwnerUri);
Query query; Query query;
@@ -780,7 +780,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
selection.FromColumn <= columnIndex && selection.FromColumn <= columnIndex &&
selection.ToColumn >= columnIndex)) selection.ToColumn >= columnIndex))
{ {
builder.Append(requestParams.RemoveNewLines ? row[columnIndex].DisplayValue.ReplaceLineEndings(" ") : row[columnIndex].DisplayValue); builder.Append(Settings.QueryEditorSettings.Results.CopyRemoveNewLine ? row[columnIndex].DisplayValue.ReplaceLineEndings(" ") : row[columnIndex].DisplayValue);
} }
if (columnIndex != lastColumnIndex) if (columnIndex != lastColumnIndex)
{ {
@@ -789,7 +789,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
} }
} }
// Add line break if this is not the last row in all selections. // Add line break if this is not the last row in all selections.
if (rowIndex + pageStartRowIndex != lastRowIndex && (!builder.ToString().EndsWith(Environment.NewLine) || !requestParams.AvoidNewLineAfterTailingLineBreak)) if (rowIndex + pageStartRowIndex != lastRowIndex && (!builder.ToString().EndsWith(Environment.NewLine) || !Settings.QueryEditorSettings.Results.SkipNewLineAfterTrailingLineBreak))
{ {
builder.Append(Environment.NewLine); builder.Append(Environment.NewLine);
} }
@@ -1141,6 +1141,7 @@ namespace Microsoft.SqlTools.ServiceLayer.QueryExecution
internal Task UpdateSettings(SqlToolsSettings newSettings, SqlToolsSettings oldSettings, EventContext eventContext) internal Task UpdateSettings(SqlToolsSettings newSettings, SqlToolsSettings oldSettings, EventContext eventContext)
{ {
Settings.QueryExecutionSettings.Update(newSettings.QueryExecutionSettings); Settings.QueryExecutionSettings.Update(newSettings.QueryExecutionSettings);
Settings.QueryEditorSettings.Update(newSettings.QueryEditorSettings);
return Task.FromResult(0); return Task.FromResult(0);
} }

View File

@@ -0,0 +1,26 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
namespace Microsoft.SqlTools.ServiceLayer.SqlContext
{
public class QueryEditorResultSettingsValues
{
/// <summary>
/// Whether to remove the line break from cell values when copying results.
/// </summary>
public bool CopyRemoveNewLine { get; set; } = true;
/// <summary>
/// Whether to skip adding a line break between rows when copying results when the previous row already has a trailing line break.
/// </summary>
public bool SkipNewLineAfterTrailingLineBreak { get; set; } = false;
/// <summary>
/// Whether to include the column headers when copying results.
/// </summary>
public bool CopyIncludeHeaders { get; set; } = false;
}
}

View File

@@ -0,0 +1,30 @@
//
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
//
using Newtonsoft.Json;
namespace Microsoft.SqlTools.ServiceLayer.SqlContext
{
public class QueryEditorSettingsValues
{
/// <summary>
/// Gets or sets the results setting
/// </summary>
[JsonProperty("results")]
public QueryEditorResultSettingsValues? Results { get; set; }
/// <summary>
/// Update the current settings with the new settings
/// </summary>
/// <param name="newSettings">The new settings</param>
public void Update(QueryEditorSettingsValues newSettings)
{
if (newSettings != null)
{
Results = newSettings.Results ?? Results;
}
}
}
}

View File

@@ -18,6 +18,7 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext
private SqlToolsSettingsValues mssqlTools = null; private SqlToolsSettingsValues mssqlTools = null;
private SqlToolsSettingsValues allSqlTools = null; private SqlToolsSettingsValues allSqlTools = null;
private TelemetrySettingsValues telemetrySettings = null; private TelemetrySettingsValues telemetrySettings = null;
private QueryEditorSettingsValues queryEditorSettings = null;
public ISqlToolsSettingsValues SqlTools public ISqlToolsSettingsValues SqlTools
{ {
@@ -83,6 +84,23 @@ namespace Microsoft.SqlTools.ServiceLayer.SqlContext
} }
} }
/// <summary>
/// Gets or sets the underlying query editor settings value object
/// </summary>
[JsonProperty("queryEditor")]
public QueryEditorSettingsValues QueryEditorSettings
{
get
{
this.queryEditorSettings ??= new QueryEditorSettingsValues();
return this.queryEditorSettings;
}
set
{
this.queryEditorSettings = value;
}
}
/// <summary> /// <summary>
/// Query execution settings forwarding property /// Query execution settings forwarding property
/// </summary> /// </summary>