Skip to content

Commit 4492ce1

Browse files
committed
code review
1 parent 92adfb0 commit 4492ce1

File tree

2 files changed

+194
-168
lines changed

2 files changed

+194
-168
lines changed

package.json

Lines changed: 169 additions & 149 deletions
Original file line numberDiff line numberDiff line change
@@ -1,151 +1,171 @@
11
{
2-
"name": "vscode-dbt-power-user",
3-
"displayName": "dbt Power User",
4-
"description": "This extension makes vscode seamlessly work with dbt",
5-
"icon": "media/dbt.png",
6-
"publisher": "innoverio",
7-
"license": "MIT",
8-
"homepage": "https://github.com/innoverio/vscode-dbt-power-user",
9-
"repository": {
10-
"type": "git",
11-
"url": "https://github.com/innoverio/vscode-dbt-power-user.git"
12-
},
13-
"bugs": {
14-
"url": "https://github.com/innoverio/vscode-dbt-power-user/issues"
15-
},
16-
"version": "0.3.5",
17-
"engines": {
18-
"vscode": "^1.47.0"
19-
},
20-
"categories": [
21-
"Other"
22-
],
23-
"keywords": [
24-
"dbt",
25-
"sql",
26-
"jinja-sql"
27-
],
28-
"activationEvents": [
29-
"workspaceContains:**/dbt_project.yml"
30-
],
31-
"main": "./dist/extension",
32-
"contributes": {
33-
"viewsContainers": {
34-
"activitybar": [
35-
{
36-
"id": "dbt_view",
37-
"title": "DBT Power User",
38-
"icon": "./media/dbt_icon.svg",
39-
"contextualTitle": "DBT Power User"
40-
}
41-
]
42-
},
43-
"views": {
44-
"dbt_view": [
45-
{
46-
"id": "parent_model_treeview",
47-
"name": "Parent Models"
48-
},
49-
{
50-
"id": "children_model_treeview",
51-
"name": "Children Models"
52-
}
53-
]
54-
},
55-
"commands": [
56-
{
57-
"command": "run.dbt.currentModel",
58-
"title": "Run Current Model",
59-
"icon": {
60-
"light": "./media/run-light.svg",
61-
"dark": "./media/run-dark.svg"
62-
}
63-
},
64-
{
65-
"command": "run.dbt.childrenModels",
66-
"title": "Run Children Models",
67-
"icon": {
68-
"light": "./media/run-light.svg",
69-
"dark": "./media/run-dark.svg"
70-
}
71-
},
72-
{
73-
"command": "run.dbt.parentModels",
74-
"title": "Run Parent Models",
75-
"icon": {
76-
"light": "./media/run-light.svg",
77-
"dark": "./media/run-dark.svg"
78-
}
79-
}
80-
],
81-
"menus": {
82-
"editor/title": [
83-
{
84-
"command": "run.dbt.currentModel",
85-
"when": "resourceLangId == jinja-sql",
86-
"group": "1_run"
87-
}
88-
],
89-
"view/title": [
90-
{
91-
"command": "run.dbt.childrenModels",
92-
"when": "view == children_model_treeview",
93-
"group": "navigation"
94-
},
95-
{
96-
"command": "run.dbt.parentModels",
97-
"when": "view == parent_model_treeview",
98-
"group": "navigation"
99-
}
100-
],
101-
"view/item/context": [
102-
{
103-
"command": "run.dbt.childrenModels",
104-
"when": "view == children_model_treeview && viewItem != source",
105-
"group": "inline"
106-
},
107-
{
108-
"command": "run.dbt.parentModels",
109-
"when": "view == parent_model_treeview && viewItem != source",
110-
"group": "inline"
111-
}
112-
]
113-
}
114-
},
115-
"scripts": {
116-
"vscode:prepublish": "webpack --mode production",
117-
"webpack": "webpack --mode development",
118-
"webpack-dev": "webpack --mode development --watch",
119-
"test-compile": "tsc -p ./",
120-
"lint": "eslint src --ext ts",
121-
"lint:fix": "eslint src --ext ts --fix",
122-
"deploy": "vsce publish"
123-
},
124-
"devDependencies": {
125-
"@types/glob": "^7.1.1",
126-
"@types/js-yaml": "^3.12.5",
127-
"@types/mocha": "^7.0.2",
128-
"@types/node": "^13.13.15",
129-
"@types/vscode": "^1.47.0",
130-
"@typescript-eslint/eslint-plugin": "^2.30.0",
131-
"@typescript-eslint/parser": "^2.30.0",
132-
"eslint": "^6.8.0",
133-
"file-loader": "^6.1.0",
134-
"glob": "^7.1.6",
135-
"mocha": "^7.1.2",
136-
"ts-loader": "^8.0.3",
137-
"typescript": "^3.8.3",
138-
"vsce": "^1.77.0",
139-
"vscode-test": "^1.3.0",
140-
"webpack": "^4.44.1",
141-
"webpack-cli": "^3.3.12"
142-
},
143-
"extensionDependencies": [
144-
"samuelcolvin.jinjahtml",
145-
"bastienboutonnet.vscode-dbt"
146-
],
147-
"dependencies": {
148-
"dayjs": "^1.8.34",
149-
"js-yaml": "^3.14.0"
150-
}
2+
"name": "vscode-dbt-power-user",
3+
"displayName": "dbt Power User",
4+
"description": "This extension makes vscode seamlessly work with dbt",
5+
"icon": "media/dbt.png",
6+
"publisher": "innoverio",
7+
"license": "MIT",
8+
"homepage": "https://github.com/innoverio/vscode-dbt-power-user",
9+
"repository": {
10+
"type": "git",
11+
"url": "https://github.com/innoverio/vscode-dbt-power-user.git"
12+
},
13+
"bugs": {
14+
"url": "https://github.com/innoverio/vscode-dbt-power-user/issues"
15+
},
16+
"version": "0.3.5",
17+
"engines": {
18+
"vscode": "^1.47.0"
19+
},
20+
"categories": [
21+
"Other"
22+
],
23+
"keywords": [
24+
"dbt",
25+
"sql",
26+
"jinja-sql"
27+
],
28+
"activationEvents": [
29+
"workspaceContains:**/dbt_project.yml"
30+
],
31+
"main": "./dist/extension",
32+
"contributes": {
33+
"configuration": [
34+
{
35+
"title": "DBT Power User",
36+
"properties": {
37+
"vscodeDbtPowerUser.useCurrentTerminal": {
38+
"type": "boolean",
39+
"default": false,
40+
"description": "Use the current terminal to execute DBT commands."
41+
},
42+
"vscodeDbtPowerUser.dbtRunCommand": {
43+
"type": [
44+
"string",
45+
"null"
46+
],
47+
"default": "dbt run",
48+
"description": "Specifies the command for running dbt models."
49+
}
50+
}
51+
}
52+
],
53+
"viewsContainers": {
54+
"activitybar": [
55+
{
56+
"id": "dbt_view",
57+
"title": "DBT Power User",
58+
"icon": "./media/dbt_icon.svg",
59+
"contextualTitle": "DBT Power User"
60+
}
61+
]
62+
},
63+
"views": {
64+
"dbt_view": [
65+
{
66+
"id": "parent_model_treeview",
67+
"name": "Parent Models"
68+
},
69+
{
70+
"id": "children_model_treeview",
71+
"name": "Children Models"
72+
}
73+
]
74+
},
75+
"commands": [
76+
{
77+
"command": "run.dbt.currentModel",
78+
"title": "Run Current Model",
79+
"icon": {
80+
"light": "./media/run-light.svg",
81+
"dark": "./media/run-dark.svg"
82+
}
83+
},
84+
{
85+
"command": "run.dbt.childrenModels",
86+
"title": "Run Children Models",
87+
"icon": {
88+
"light": "./media/run-light.svg",
89+
"dark": "./media/run-dark.svg"
90+
}
91+
},
92+
{
93+
"command": "run.dbt.parentModels",
94+
"title": "Run Parent Models",
95+
"icon": {
96+
"light": "./media/run-light.svg",
97+
"dark": "./media/run-dark.svg"
98+
}
99+
}
100+
],
101+
"menus": {
102+
"editor/title": [
103+
{
104+
"command": "run.dbt.currentModel",
105+
"when": "resourceLangId == jinja-sql",
106+
"group": "1_run"
107+
}
108+
],
109+
"view/title": [
110+
{
111+
"command": "run.dbt.childrenModels",
112+
"when": "view == children_model_treeview",
113+
"group": "navigation"
114+
},
115+
{
116+
"command": "run.dbt.parentModels",
117+
"when": "view == parent_model_treeview",
118+
"group": "navigation"
119+
}
120+
],
121+
"view/item/context": [
122+
{
123+
"command": "run.dbt.childrenModels",
124+
"when": "view == children_model_treeview && viewItem != source",
125+
"group": "inline"
126+
},
127+
{
128+
"command": "run.dbt.parentModels",
129+
"when": "view == parent_model_treeview && viewItem != source",
130+
"group": "inline"
131+
}
132+
]
133+
}
134+
},
135+
"scripts": {
136+
"vscode:prepublish": "webpack --mode production",
137+
"webpack": "webpack --mode development",
138+
"webpack-dev": "webpack --mode development --watch",
139+
"test-compile": "tsc -p ./",
140+
"lint": "eslint src --ext ts",
141+
"lint:fix": "eslint src --ext ts --fix",
142+
"deploy": "vsce publish"
143+
},
144+
"devDependencies": {
145+
"@types/glob": "^7.1.1",
146+
"@types/js-yaml": "^3.12.5",
147+
"@types/mocha": "^7.0.2",
148+
"@types/node": "^13.13.15",
149+
"@types/vscode": "^1.47.0",
150+
"@typescript-eslint/eslint-plugin": "^2.30.0",
151+
"@typescript-eslint/parser": "^2.30.0",
152+
"eslint": "^6.8.0",
153+
"file-loader": "^6.1.0",
154+
"glob": "^7.1.6",
155+
"mocha": "^7.1.2",
156+
"ts-loader": "^8.0.3",
157+
"typescript": "^3.8.3",
158+
"vsce": "^1.77.0",
159+
"vscode-test": "^1.3.0",
160+
"webpack": "^4.44.1",
161+
"webpack-cli": "^3.3.12"
162+
},
163+
"extensionDependencies": [
164+
"samuelcolvin.jinjahtml",
165+
"bastienboutonnet.vscode-dbt"
166+
],
167+
"dependencies": {
168+
"dayjs": "^1.8.34",
169+
"js-yaml": "^3.14.0"
170+
}
151171
}

src/commands/runModel.ts

Lines changed: 25 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -6,28 +6,30 @@ import { NodeTreeItem } from "../treeview_provider/ModelParentTreeviewProvider";
66

77
export enum RunModelType {
88
PARENTS,
9-
CHILDREN
9+
CHILDREN,
1010
}
1111

1212
export const runModelOnActiveWindow = async (type?: RunModelType) => {
1313
const fullPath = window.activeTextEditor?.document.fileName;
1414
if (fullPath !== undefined) {
15-
const fileName = path.basename(fullPath, '.sql');
15+
const fileName = path.basename(fullPath, ".sql");
1616
runTerminal(fileName, type);
1717
}
1818
};
1919

20-
export const runModelOnNodeTreeItem = (type: RunModelType) => async (model?: NodeTreeItem) => {
20+
export const runModelOnNodeTreeItem = (type: RunModelType) => async (
21+
model?: NodeTreeItem
22+
) => {
2123
if (model === undefined) {
2224
runModelOnActiveWindow(type);
2325
return;
2426
}
25-
const fileName = path.basename(model.url, '.sql');
27+
const fileName = path.basename(model.url, ".sql");
2628
runTerminal(fileName, type);
2729
};
2830

2931
const sleep: (timeout: number) => Promise<void> = async (timeout: number) => {
30-
return new Promise<void>(resolve => {
32+
return new Promise<void>((resolve) => {
3133
setTimeout(resolve, timeout);
3234
});
3335
};
@@ -38,22 +40,26 @@ const runTerminal = async (modelName: string, type?: RunModelType) => {
3840
}
3941
const currentFilePath = window.activeTextEditor.document.uri;
4042
const projectRootpath = manifestContainer.getProjectRootpath(currentFilePath);
41-
43+
4244
if (modelName !== undefined && projectRootpath !== undefined) {
43-
const terminal = workspace.getConfiguration('innoverio-vscode-dbt-power-user.setting').get('current_terminal') && window.activeTerminal
44-
? window.activeTerminal
45-
: window.createTerminal({
46-
name: 'DBT',
47-
cwd: projectRootpath,
48-
});
45+
const terminal =
46+
workspace
47+
.getConfiguration("vscodeDbtPowerUser")
48+
.get<boolean>("useCurrentTerminal") && window.activeTerminal
49+
? window.activeTerminal
50+
: window.createTerminal({
51+
name: "DBT",
52+
cwd: projectRootpath,
53+
});
4954
// should sleep after the terminal cration in order for the venv to be activated
5055
await sleep(500);
51-
const plusOperatorLeft = type === RunModelType.PARENTS ? '+' : '';
52-
const plusOperatorRight = type === RunModelType.CHILDREN ? '+' : '';
53-
const dbt_command = workspace.getConfiguration('innoverio-vscode-dbt-power-user.setting').get('dbt_command')
54-
? workspace.getConfiguration('innoverio-vscode-dbt-power-user.setting').get('dbt_command')
55-
: `dbt run`
56-
terminal.sendText(dbt_command + ` --model ${plusOperatorLeft}${modelName}${plusOperatorRight}`);
56+
const plusOperatorLeft = type === RunModelType.PARENTS ? "+" : "";
57+
const plusOperatorRight = type === RunModelType.CHILDREN ? "+" : "";
58+
const dbt_command = workspace
59+
.getConfiguration("vscodeDbtPowerUser")
60+
.get("dbtRunCommand", "dbt run");
61+
62+
terminal.sendText(`${dbt_command} --model ${plusOperatorLeft}${modelName}${plusOperatorRight}`);
5763
terminal.show(true);
5864
}
59-
};
65+
};

0 commit comments

Comments
 (0)