Skip to content

Commit 7350362

Browse files
aasimkhan30Aasim Khan
andauthored
Adding a copy fallback if xsel is missing. (#2550)
* Adding workaround for new copy api. * remove content when copy is successful --------- Co-authored-by: Aasim Khan <aasimkhan@gmail.com>
1 parent e1e41ae commit 7350362

File tree

2 files changed

+15
-2
lines changed

2 files changed

+15
-2
lines changed

src/Microsoft.SqlTools.ServiceLayer/QueryExecution/Contracts/CopyResults2Request.cs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,11 @@ public class CopyResults2RequestParams : SubsetParams
6464
/// </summary>
6565
public class CopyResults2RequestResult
6666
{
67+
/// <summary>
68+
/// The content to be copied to the clipboard.
69+
/// If this is populated, the client is responsible for copying it to the clipboard.
70+
/// </summary>
71+
public string Content { get; set; }
6772
}
6873

6974
/// <summary>

src/Microsoft.SqlTools.ServiceLayer/QueryExecution/QueryExecutionService.cs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1004,8 +1004,16 @@ internal async Task HandleCopyResults2Request(CopyResults2RequestParams requestP
10041004

10051005
cts.Token.ThrowIfCancellationRequested();
10061006

1007-
await ClipboardService.SetTextAsync(content);
1008-
await requestContext.SendResult(new CopyResults2RequestResult());
1007+
try
1008+
{
1009+
await ClipboardService.SetTextAsync(content);
1010+
await requestContext.SendResult(new CopyResults2RequestResult());
1011+
}
1012+
catch (Exception)
1013+
{
1014+
// If clipboard copy fails (e.g. missing xsel on Linux), send content back to client
1015+
await requestContext.SendResult(new CopyResults2RequestResult { Content = content });
1016+
}
10091017
}
10101018
catch (OperationCanceledException)
10111019
{

0 commit comments

Comments
 (0)