Skip to content

Commit b05937a

Browse files
committed
Merge branch 'master' of github.com:badsyntax/vscode-entity-framework
2 parents 2aa21b7 + 859565d commit b05937a

22 files changed

+292
-177
lines changed

package.json

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@
4343
"contributes": {
4444
"commands": [
4545
{
46-
"command": "entityframework.removeMigration",
46+
"command": "entityframework.removeMigrations",
4747
"title": "Remove Migration",
4848
"icon": {
4949
"light": "icons/trash_light.svg",
@@ -119,7 +119,7 @@
119119
"explorer": [
120120
{
121121
"id": "entityframeworkTree",
122-
"name": "EF Migrations"
122+
"name": "Entity Framework"
123123
}
124124
]
125125
},
@@ -130,7 +130,7 @@
130130
"when": "false"
131131
},
132132
{
133-
"command": "entityframework.removeMigration",
133+
"command": "entityframework.removeMigrations",
134134
"when": "false"
135135
},
136136
{
@@ -171,12 +171,12 @@
171171
],
172172
"view/item/context": [
173173
{
174-
"command": "entityframework.removeMigration",
174+
"command": "entityframework.removeMigrations",
175175
"when": "viewItem =~ /^migration-.*\\|?can-remove\\|?.*$/",
176176
"group": "inline@1"
177177
},
178178
{
179-
"command": "entityframework.removeMigration",
179+
"command": "entityframework.removeMigrations",
180180
"when": "viewItem =~ /^migration-.*\\|?can-remove\\|?.*$/",
181181
"group": "context@2"
182182
},
@@ -203,22 +203,22 @@
203203
{
204204
"command": "entityframework.addMigration",
205205
"when": "viewItem == dbContext",
206-
"group": "context@4"
206+
"group": "inline@4"
207207
},
208208
{
209209
"command": "entityframework.addMigration",
210210
"when": "viewItem == dbContext",
211-
"group": "inline@4"
211+
"group": "context@1"
212212
},
213213
{
214214
"command": "entityframework.generateScript",
215215
"when": "viewItem == dbContext",
216-
"group": "context@3"
216+
"group": "inline@3"
217217
},
218218
{
219219
"command": "entityframework.generateScript",
220220
"when": "viewItem == dbContext",
221-
"group": "inline@3"
221+
"group": "context@2"
222222
},
223223
{
224224
"command": "entityframework.generateERD",
@@ -228,7 +228,7 @@
228228
{
229229
"command": "entityframework.generateERD",
230230
"when": "viewItem == dbContext",
231-
"group": "context@2"
231+
"group": "context@3"
232232
},
233233
{
234234
"command": "entityframework.dbContextInfo",
@@ -238,7 +238,7 @@
238238
{
239239
"command": "entityframework.dbContextInfo",
240240
"when": "viewItem == dbContext",
241-
"group": "context@1"
241+
"group": "context@4"
242242
},
243243
{
244244
"command": "entityframework.scaffold",

src/actions/AddMigrationAction.ts

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
22
import { CommandProvider } from '../commands/CommandProvider';
33
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
44
import { getCommandsConfig } from '../config/config';
5+
import { TREE_VIEW_ID } from '../constants/constants';
56

67
import type { TerminalProvider } from '../terminal/TerminalProvider';
78
import {
@@ -40,13 +41,20 @@ export class AddMigrationAction extends TerminalAction {
4041
return vscode.window.withProgress(
4142
{
4243
title: 'Adding Migration...',
43-
location: vscode.ProgressLocation.Window,
44+
location: { viewId: TREE_VIEW_ID },
45+
cancellable: true,
4446
},
45-
async () => {
46-
const output = await super.run({
47+
async (_progress, cancellationToken) => {
48+
cancellationToken.onCancellationRequested(() => {
49+
this.cancel();
50+
});
51+
52+
await this.start({
4753
...this.params,
4854
migrationName,
4955
});
56+
57+
const output = await this.getOutput();
5058
const cacheId = DbContextTreeItem.getCacheId(
5159
this.workspaceRoot,
5260
this.project,

src/actions/DBContextInfoCommandAction.ts

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
22

33
import { CLI } from '../cli/CLI';
44
import { getCommandsConfig } from '../config/config';
5+
import { TREE_VIEW_ID } from '../constants/constants';
56

67
import type { TerminalProvider } from '../terminal/TerminalProvider';
78
import { TextDocumentProvider } from '../util/TextDocumentProvider';
@@ -29,15 +30,19 @@ export class DBContextInfoCommandAction extends TerminalAction {
2930
return vscode.window.withProgress(
3031
{
3132
title: 'Getting DbContext Info...',
32-
location: vscode.ProgressLocation.Window,
33+
location: { viewId: TREE_VIEW_ID },
34+
cancellable: true,
3335
},
34-
async () => {
35-
const output = CLI.getDataFromStdOut(
36-
await super.run(undefined, {
37-
removeDataFromOutput: true,
38-
asJson: true,
39-
}),
40-
);
36+
async (_progress, cancellationToken) => {
37+
cancellationToken.onCancellationRequested(() => {
38+
this.cancel();
39+
});
40+
41+
await this.start(undefined, {
42+
removeDataFromOutput: true,
43+
asJson: true,
44+
});
45+
const output = CLI.getDataFromStdOut(await this.getOutput());
4146
const uri = vscode.Uri.parse(
4247
`${TextDocumentProvider.scheme}:${output}`,
4348
);

src/actions/GenerateERDAction.ts

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ import util from 'util';
77
import { CLI } from '../cli/CLI';
88
import { getCommandsConfig, getERDConfig } from '../config/config';
99
import { TerminalAction } from './TerminalAction';
10-
import { DEFAULT_EFCORE_PROVIDERS } from '../constants/constants';
10+
import { DEFAULT_EFCORE_PROVIDERS, TREE_VIEW_ID } from '../constants/constants';
1111
import { InputWizard } from '../util/InputWizard';
1212
import { ERDiagramWebViewProvider } from '../util/ERDiagramWebViewProvider';
1313
import { ProjectFilesProvider } from '../solution/ProjectFilesProvider';
@@ -130,9 +130,13 @@ export class GenerateERDAction extends TerminalAction {
130130
return vscode.window.withProgress(
131131
{
132132
title: 'Generating diagram...',
133-
location: vscode.ProgressLocation.Window,
133+
location: { viewId: TREE_VIEW_ID },
134+
cancellable: true,
134135
},
135-
async () => {
136+
async (_progress, cancellationToken) => {
137+
cancellationToken.onCancellationRequested(() => {
138+
this.cancel();
139+
});
136140
try {
137141
// Backup any existing DbContext template
138142
const finalTemplatePathExists = fs.existsSync(finalTemplatePath);
@@ -145,23 +149,21 @@ export class GenerateERDAction extends TerminalAction {
145149
finalConfigPath,
146150
JSON.stringify(erDiagramConfig, null, 2),
147151
);
148-
149-
const output = CLI.getDataFromStdOut(
150-
await super.run(
151-
{
152-
...this.params,
153-
connectionString,
154-
provider,
155-
outputDir: this.outputDir,
156-
},
157-
{
158-
asJson: true,
159-
removeDataFromOutput: true,
160-
},
161-
),
152+
await this.start(
153+
{
154+
...this.params,
155+
connectionString,
156+
provider,
157+
outputDir: this.outputDir,
158+
},
159+
{
160+
asJson: true,
161+
removeDataFromOutput: true,
162+
},
162163
);
163-
164-
const result = JSON.parse(output) as ScaffoldResult;
164+
const output = await this.getOutput();
165+
const data = CLI.getDataFromStdOut(await this.getOutput());
166+
const result = JSON.parse(data) as ScaffoldResult;
165167

166168
const fileContents = fs.readFileSync(result.contextFile, 'utf-8');
167169

src/actions/GenerateScriptAction.ts

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
22

33
import { CLI } from '../cli/CLI';
44
import { getCommandsConfig } from '../config/config';
5+
import { TREE_VIEW_ID } from '../constants/constants';
56
import type { TerminalProvider } from '../terminal/TerminalProvider';
67
import { TextDocumentProvider } from '../util/TextDocumentProvider';
78
import { TerminalAction } from './TerminalAction';
@@ -28,21 +29,23 @@ export class GenerateScriptAction extends TerminalAction {
2829
return vscode.window.withProgress(
2930
{
3031
title: 'Generating script...',
31-
location: vscode.ProgressLocation.Window,
32+
location: { viewId: TREE_VIEW_ID },
33+
cancellable: true,
3234
},
33-
async () => {
34-
const output = CLI.getDataFromStdOut(
35-
await super.run(undefined, {
36-
removeDataFromOutput: true,
37-
}),
38-
);
39-
const uri = vscode.Uri.parse(
40-
`${TextDocumentProvider.scheme}:${output}`,
41-
);
35+
async (_progress, cancellationToken) => {
36+
cancellationToken.onCancellationRequested(() => {
37+
this.cancel();
38+
});
39+
await this.start(undefined, {
40+
removeDataFromOutput: true,
41+
});
42+
const output = await this.getOutput();
43+
const data = CLI.getDataFromStdOut(output);
44+
const uri = vscode.Uri.parse(`${TextDocumentProvider.scheme}:${data}`);
4245
const doc = await vscode.workspace.openTextDocument(uri);
4346
await vscode.languages.setTextDocumentLanguage(doc, 'sql');
4447
await vscode.window.showTextDocument(doc, { preview: false });
45-
return output;
48+
return data;
4649
},
4750
);
4851
}

src/actions/RemoveMigrationAction.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
22
import { CommandProvider } from '../commands/CommandProvider';
33
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
44
import { getCommandsConfig } from '../config/config';
5+
import { TREE_VIEW_ID } from '../constants/constants';
56
import type { TerminalProvider } from '../terminal/TerminalProvider';
67
import {
78
dbContextsCache,
@@ -15,6 +16,7 @@ export class RemoveMigrationAction extends TerminalAction {
1516
private readonly workspaceRoot: string,
1617
private readonly dbContext: string,
1718
private readonly project: string,
19+
private readonly refresh?: boolean,
1820
) {
1921
super(
2022
terminalProvider,
@@ -31,20 +33,28 @@ export class RemoveMigrationAction extends TerminalAction {
3133
return vscode.window.withProgress(
3234
{
3335
title: 'Removing Migration...',
34-
location: vscode.ProgressLocation.Window,
36+
location: { viewId: TREE_VIEW_ID },
37+
cancellable: true,
3538
},
36-
async () => {
37-
const output = await super.run();
39+
async (_progress, cancellationToken) => {
40+
cancellationToken.onCancellationRequested(() => {
41+
this.cancel();
42+
});
43+
await this.start();
44+
const output = await this.getOutput();
3845
const cacheId = DbContextTreeItem.getCacheId(
3946
this.workspaceRoot,
4047
this.project,
4148
this.dbContext,
4249
);
4350
dbContextsCache.clear(cacheId);
44-
await vscode.commands.executeCommand(
45-
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
46-
false,
47-
);
51+
const refresh = this.refresh || this.refresh === undefined;
52+
if (refresh) {
53+
await vscode.commands.executeCommand(
54+
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
55+
false,
56+
);
57+
}
4858
return output;
4959
},
5060
);

src/actions/RemoveMigrationsAction.ts

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import * as vscode from 'vscode';
2+
import { CommandProvider } from '../commands/CommandProvider';
3+
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
4+
import type { TerminalProvider } from '../terminal/TerminalProvider';
5+
import type { MigrationTreeItem } from '../treeView/MigrationTreeItem';
6+
import type { IAction } from './IAction';
7+
import { RemoveMigrationAction } from './RemoveMigrationAction';
8+
9+
export class RemoveMigrationsAction implements IAction {
10+
constructor(
11+
private readonly terminalProvider: TerminalProvider,
12+
private readonly workspaceRoot: string,
13+
private readonly dbContext: string,
14+
private readonly project: string,
15+
private readonly migrationsToRemove: MigrationTreeItem[],
16+
) {}
17+
18+
public async run() {
19+
for (let i = 0; i < this.migrationsToRemove.length; i++) {
20+
await new RemoveMigrationAction(
21+
this.terminalProvider,
22+
this.workspaceRoot,
23+
this.dbContext,
24+
this.project,
25+
false,
26+
).run();
27+
}
28+
if (this.migrationsToRemove.length > 0) {
29+
await vscode.commands.executeCommand(
30+
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
31+
false,
32+
);
33+
}
34+
}
35+
}

src/actions/RunMigrationAction.ts

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import * as vscode from 'vscode';
22
import { CommandProvider } from '../commands/CommandProvider';
33
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
44
import { getCommandsConfig } from '../config/config';
5+
import { TREE_VIEW_ID } from '../constants/constants';
56
import type { TerminalProvider } from '../terminal/TerminalProvider';
67
import {
78
dbContextsCache,
@@ -33,10 +34,15 @@ export class RunMigrationAction extends TerminalAction {
3334
return vscode.window.withProgress(
3435
{
3536
title: 'Running Migration...',
36-
location: vscode.ProgressLocation.Window,
37+
location: { viewId: TREE_VIEW_ID },
38+
cancellable: true,
3739
},
38-
async () => {
39-
const output = await super.run();
40+
async (_progress, cancellationToken) => {
41+
cancellationToken.onCancellationRequested(() => {
42+
this.cancel();
43+
});
44+
await this.start();
45+
const output = await this.getOutput();
4046

4147
const cacheId = DbContextTreeItem.getCacheId(
4248
this.workspaceRoot,

0 commit comments

Comments
 (0)