Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -646,6 +646,12 @@
"icon": "$(output)",
"category": "Confluent"
},
{
"command": "confluent.statements.copyAndEdit",
"title": "Copy & Edit",
"icon": "$(copy)",
"category": "Confluent: Flink Statements"
},
{
"command": "confluent.statements.create",
"icon": "$(cloud-upload)",
Expand Down Expand Up @@ -1540,6 +1546,10 @@
"command": "confluent.showSidecarOutputChannel",
"when": "true"
},
{
"command": "confluent.statements.copyAndEdit",
"when": "false"
},
{
"command": "confluent.statements.create",
"when": "false"
Expand Down
12 changes: 12 additions & 0 deletions src/codelens/flinkSqlProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
Range,
TextDocument,
} from "vscode";
import { FLINKSTATEMENT_URI_SCHEME } from "../documentProviders/flinkStatement";
import { ccloudConnected, uriMetadataSet } from "../emitters";
import { FLINK_CONFIG_COMPUTE_POOL, FLINK_CONFIG_DATABASE } from "../extensionSettings/constants";
import { CCloudResourceLoader } from "../loaders";
Expand Down Expand Up @@ -130,6 +131,17 @@ export class FlinkSqlCodelensProvider extends DisposableCollection implements Co
};
const resetLens = new CodeLens(range, resetCommand);

if (document.uri.scheme === FLINKSTATEMENT_URI_SCHEME) {
const copyEditCommand: Command = {
title: "Copy & Edit",
command: "confluent.statements.copyAndEdit",
tooltip: "Copy the current statement to a new document and edit it",
arguments: [document.uri],
};
const copyEditLens = new CodeLens(range, copyEditCommand);
codeLenses.push(copyEditLens);
}

if (computePool && database) {
const submitCommand: Command = {
title: "▶️ Submit Statement",
Expand Down
30 changes: 30 additions & 0 deletions src/commands/flinkStatements.ts
Original file line number Diff line number Diff line change
Expand Up @@ -376,6 +376,32 @@ export async function stopFlinkStatementCommand(statement: FlinkStatement): Prom
void vscode.window.showInformationMessage(`Stopped statement ${statement.name}`);
}

export async function copyAndEditFlinkStatementCommand(uri: vscode.Uri): Promise<void> {
if (!(uri instanceof vscode.Uri) || uri.scheme !== FLINKSTATEMENT_URI_SCHEME) {
return;
}

const rm = ResourceManager.getInstance();
const uriMetadata: UriMetadata | undefined = await rm.getUriMetadata(uri);
if (!uriMetadata) {
// should never happen since this command is only available from existing statements,
// which always have resource-related metadata
return;
}

// grab the content of the read-only flinksql document
const document: vscode.TextDocument = await vscode.workspace.openTextDocument(uri);
const sqlStatement: string = document.getText();

// open a new editable document with the same content and relevant metadata
const editableDoc = await vscode.workspace.openTextDocument({
language: FLINK_SQL_LANGUAGE_ID,
content: sqlStatement,
});
await rm.setUriMetadata(editableDoc.uri, uriMetadata);
await vscode.window.showTextDocument(editableDoc, { preview: false });
}

export function registerFlinkStatementCommands(): vscode.Disposable[] {
return [
registerCommandWithLogging("confluent.statements.viewstatementsql", viewStatementSqlCommand),
Expand All @@ -384,5 +410,9 @@ export function registerFlinkStatementCommands(): vscode.Disposable[] {
registerCommandWithLogging("confluent.flinkStatementResults", openFlinkStatementResultsView),
registerCommandWithLogging("confluent.statements.delete", deleteFlinkStatementCommand),
registerCommandWithLogging("confluent.statements.stop", stopFlinkStatementCommand),
registerCommandWithLogging(
"confluent.statements.copyAndEdit",
copyAndEditFlinkStatementCommand,
),
];
}