Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: query bookmarks feedback changes #1295

Merged
merged 6 commits into from
Jul 12, 2024
Merged
Show file tree
Hide file tree
Changes from 5 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
5 changes: 4 additions & 1 deletion src/code_lens_provider/virtualSqlCodeLensProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,10 @@ export class VirtualSqlCodeLensProvider implements CodeLensProvider {
token: CancellationToken,
): CodeLens[] | Thenable<CodeLens[]> {
// Enable this code lens only for adhoc query files created using command: dbtPowerUser.createSqlFile
if (document.uri.scheme !== "untitled" && document.languageId !== "sql") {
if (
document.uri.scheme !== "untitled" &&
document.languageId !== "jinja-sql"
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

converted the new query sql file from sql language to jinja-sql so we can use jinja autocompletes

) {
return [];
}

Expand Down
124 changes: 64 additions & 60 deletions src/commands/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -539,77 +539,81 @@ export class VSCodeCommands implements Disposable {
this.dbtTerminal.logLine(`Error=${e}`);
}
}),
commands.registerCommand("dbtPowerUser.createSqlFile", async () => {
try {
const project =
await this.queryManifestService.getOrPickProjectFromWorkspace();
if (!project) {
window.showErrorMessage("No dbt project selected.");
return;
}
commands.registerCommand(
"dbtPowerUser.createSqlFile",
async ({ code, fileName }: { code?: string; fileName?: string }) => {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

added these 2 arguments to display selected code from bookmark or history details and with filename

try {
const project =
await this.queryManifestService.getOrPickProjectFromWorkspace();
if (!project) {
window.showErrorMessage("No dbt project selected.");
return;
}

const uri = Uri.parse(
`${project.projectRoot}/poweruser-${getFormattedDateTime()}.sql`,
).with({ scheme: "untitled" });
const annotationDecoration: TextEditorDecorationType =
window.createTextEditorDecorationType({
rangeBehavior: DecorationRangeBehavior.OpenOpen,
});
const fileNamePrefix = fileName || "poweruser";
const uri = Uri.parse(
`${project.projectRoot}/${fileNamePrefix}-${getFormattedDateTime()}.sql`,
).with({ scheme: "untitled" });
const annotationDecoration: TextEditorDecorationType =
window.createTextEditorDecorationType({
rangeBehavior: DecorationRangeBehavior.OpenOpen,
});

const contentText =
"Enter your query here and execute it just like any dbt model file. This file is unsaved, you can either save it to your project or save it as a bookmark for later usage or share it with your team members.";
const contentText =
"Enter your query here and execute it just like any dbt model file. This file is unsaved, you can either save it to your project or save it as a bookmark for later usage or share it with your team members.";

const decorations = [
{
renderOptions: {
before: {
color: "#666666",
contentText,
// hacking to add more css properties
width: "90%;display: block;white-space: pre-line;",
const decorations = [
{
renderOptions: {
before: {
color: "#666666",
contentText,
// hacking to add more css properties
width: "90%;display: block;white-space: pre-line;",
},
},
range: new Range(2, 0, 2, 0),
},
range: new Range(2, 0, 2, 0),
},
];
];

workspace.openTextDocument(uri).then((doc) => {
// set this to sql language so we can bind codelens and other features
languages.setTextDocumentLanguage(doc, "sql");
window.showTextDocument(doc).then((editor) => {
editor.edit((editBuilder) => {
const entireDocumentRange = new Range(
doc.positionAt(0),
doc.positionAt(doc.getText().length),
);
editBuilder.replace(entireDocumentRange, "\n");
workspace.openTextDocument(uri).then((doc) => {
// set this to sql language so we can bind codelens and other features
languages.setTextDocumentLanguage(doc, "jinja-sql");
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use jinja-sql language

window.showTextDocument(doc).then((editor) => {
editor.edit((editBuilder) => {
const entireDocumentRange = new Range(
doc.positionAt(0),
doc.positionAt(doc.getText().length),
);
editBuilder.replace(entireDocumentRange, code || "\n");

editor.setDecorations(annotationDecoration, decorations);
setTimeout(() => {
commands.executeCommand("cursorMove", {
to: "up",
by: "line",
value: 1,
});
}, 0);
const disposable = workspace.onDidChangeTextDocument((e) => {
const activeEditor = window.activeTextEditor;
if (activeEditor && e.document === editor.document) {
if (activeEditor.document.getText().trim()) {
activeEditor.setDecorations(annotationDecoration, []);
disposable.dispose();
editor.setDecorations(annotationDecoration, decorations);
setTimeout(() => {
commands.executeCommand("cursorMove", {
to: "up",
by: "line",
value: 1,
});
}, 0);
const disposable = workspace.onDidChangeTextDocument((e) => {
const activeEditor = window.activeTextEditor;
if (activeEditor && e.document === editor.document) {
if (activeEditor.document.getText().trim()) {
activeEditor.setDecorations(annotationDecoration, []);
disposable.dispose();
}
}
}
});
});
});
});
});
} catch (e) {
const message = (e as Error).message;
this.dbtTerminal.error("createSqlFile", message, e, true);
window.showErrorMessage(message);
}
}),
} catch (e) {
const message = (e as Error).message;
this.dbtTerminal.error("createSqlFile", message, e, true);
window.showErrorMessage(message);
}
},
),
commands.registerCommand("dbtPowerUser.sqlLineage", async () => {
window.withProgress(
{
Expand Down
2 changes: 1 addition & 1 deletion src/dbtPowerUserExtension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export class DBTPowerUserExtension implements Disposable {
static DBT_SQL_SELECTOR = [
{ language: "jinja-sql", scheme: "file" },
{ language: "sql", scheme: "file" },
{ language: "sql", scheme: "untitled" },
{ language: "jinja-sql", scheme: "untitled" },
];
static DBT_YAML_SELECTOR = [
{ language: "yaml", scheme: "file" },
Expand Down
2 changes: 1 addition & 1 deletion src/webview_provider/docsEditPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -339,7 +339,7 @@ export class DocsEditViewPanel implements WebviewViewProvider {
const testFullName: string = namespace ? `${namespace}.${name}` : name;

const columnTestConfigFromYml = getColumnTestConfigFromYml(
existingColumn.tests,
existingColumn?.tests,
kwargs,
testFullName,
);
Expand Down
14 changes: 14 additions & 0 deletions src/webview_provider/queryResultPanel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ enum InboundCommand {
GetQueryTabData = "getQueryTabData",
RunAdhocQuery = "runAdhocQuery",
ViewResultSet = "viewResultSet",
OpenCodeInEditor = "openCodeInEditor",
}

interface RecInfo {
Expand Down Expand Up @@ -323,11 +324,24 @@ export class QueryResultPanel extends AltimateWebviewProvider {
}
}

private async handleOpenCodeInEditor(message: {
code: string;
name: string;
}) {
commands.executeCommand("dbtPowerUser.createSqlFile", {
code: message.code,
name: message.name,
});
}

/** Primary interface for WebviewView inbound communication */
private setupWebviewHooks() {
this._panel!.webview.onDidReceiveMessage(
async (message) => {
switch (message.command) {
case InboundCommand.OpenCodeInEditor:
this.handleOpenCodeInEditor(message);
break;
case InboundCommand.ViewResultSet:
const queryHistoryData = message.queryHistory;
this._queryTabData = {
Expand Down
4 changes: 4 additions & 0 deletions webview_panels/src/assets/icons/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -155,3 +155,7 @@ export const SearchIcon = (props: HTMLAttributes<HTMLElement>): JSX.Element => (
export const FileCodeIcon = (
props: HTMLAttributes<HTMLElement>,
): JSX.Element => <Icon icon="file-code" {...props} />;

export const OpenNewIcon = (
props: HTMLAttributes<HTMLElement>,
): JSX.Element => <Icon icon="link-external" {...props} />;
5 changes: 3 additions & 2 deletions webview_panels/src/lib/altimate/altimate-components.d.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
/// <reference types="react" />

import { JSX as JSX_2 } from "react/jsx-runtime";
import { ReactNode } from "react";

export declare const ApiHelper: {
get: <T>(
Expand All @@ -21,6 +20,7 @@ export declare const CodeBlock: ({
fileName,
theme,
showLineNumbers,
titleActions,
}: Props_4) => JSX.Element;

export declare interface Conversation {
Expand Down Expand Up @@ -131,6 +131,7 @@ declare interface Props_4 {
fileName?: string;
showLineNumbers?: boolean;
theme?: "vs" | "vsc-dark-plus" | "solarizedLight";
titleActions?: ReactNode;
}

declare interface User {
Expand Down
Loading
Loading