Skip to content

Commit 2216747

Browse files
authored
Merge pull request #39 from badsyntax/refresh-subtree
Add ability to refresh projects & dbcontexts
2 parents 53c9b7f + 4a4305d commit 2216747

10 files changed

+158
-35
lines changed

package.json

Lines changed: 35 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,23 @@
7676
},
7777
{
7878
"command": "entityframework.refreshTree",
79-
"title": "Refresh Migrations",
79+
"title": "Refresh",
80+
"icon": {
81+
"light": "icons/refresh_light.svg",
82+
"dark": "icons/refresh_dark.svg"
83+
}
84+
},
85+
{
86+
"command": "entityframework.refreshDbContextTree",
87+
"title": "Refresh",
88+
"icon": {
89+
"light": "icons/refresh_light.svg",
90+
"dark": "icons/refresh_dark.svg"
91+
}
92+
},
93+
{
94+
"command": "entityframework.refreshProjectTree",
95+
"title": "Refresh",
8096
"icon": {
8197
"light": "icons/refresh_light.svg",
8298
"dark": "icons/refresh_dark.svg"
@@ -129,6 +145,14 @@
129145
"command": "entityframework.refreshTree",
130146
"when": "false"
131147
},
148+
{
149+
"command": "entityframework.refreshProjectTree",
150+
"when": "false"
151+
},
152+
{
153+
"command": "entityframework.refreshDbContextTree",
154+
"when": "false"
155+
},
132156
{
133157
"command": "entityframework.removeMigrations",
134158
"when": "false"
@@ -212,33 +236,19 @@
212236
},
213237
{
214238
"command": "entityframework.generateScript",
215-
"when": "viewItem == dbContext",
216-
"group": "inline@3"
217-
},
218-
{
219-
"command": "entityframework.generateScript",
220-
"when": "viewItem == dbContext",
221-
"group": "context@2"
239+
"when": "viewItem == dbContext"
222240
},
223241
{
224242
"command": "entityframework.generateERD",
225-
"when": "viewItem == dbContext",
226-
"group": "inline@2"
227-
},
228-
{
229-
"command": "entityframework.generateERD",
230-
"when": "viewItem == dbContext",
231-
"group": "context@3"
243+
"when": "viewItem == dbContext"
232244
},
233245
{
234246
"command": "entityframework.dbContextInfo",
235-
"when": "viewItem == dbContext",
236-
"group": "inline@1"
247+
"when": "viewItem == dbContext"
237248
},
238249
{
239-
"command": "entityframework.dbContextInfo",
240-
"when": "viewItem == dbContext",
241-
"group": "context@4"
250+
"command": "entityframework.refreshDbContextTree",
251+
"when": "viewItem == dbContext"
242252
},
243253
{
244254
"command": "entityframework.scaffold",
@@ -249,6 +259,11 @@
249259
"command": "entityframework.scaffold",
250260
"when": "viewItem == project",
251261
"group": "context@1"
262+
},
263+
{
264+
"command": "entityframework.refreshProjectTree",
265+
"when": "viewItem == project",
266+
"group": "context@2"
252267
}
253268
]
254269
},
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import * as vscode from 'vscode';
2+
import { CommandProvider } from '../commands/CommandProvider';
3+
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
4+
5+
import {
6+
dbContextsCache,
7+
DbContextTreeItem,
8+
} from '../treeView/DbContextTreeItem';
9+
import type { IAction } from './IAction';
10+
11+
export class RefreshDbContextTreeAction implements IAction {
12+
constructor(private readonly item: DbContextTreeItem) {}
13+
14+
public async run() {
15+
const cacheId = DbContextTreeItem.getCacheId(
16+
this.item.workspaceRoot,
17+
this.item.projectFile.name,
18+
this.item.label,
19+
);
20+
dbContextsCache.clear(cacheId);
21+
await vscode.commands.executeCommand(
22+
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
23+
false,
24+
);
25+
}
26+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
import * as vscode from 'vscode';
2+
import { CommandProvider } from '../commands/CommandProvider';
3+
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
4+
import { projectsCache, ProjectTreeItem } from '../treeView/ProjectTreeItem';
5+
import type { IAction } from './IAction';
6+
7+
export class RefreshProjectTreeAction implements IAction {
8+
constructor(private readonly item: ProjectTreeItem) {}
9+
10+
public async run() {
11+
const cacheId = ProjectTreeItem.getCacheId(
12+
this.item.workspaceRoot,
13+
this.item.label,
14+
);
15+
projectsCache.clear(cacheId);
16+
await vscode.commands.executeCommand(
17+
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
18+
false,
19+
);
20+
}
21+
}

src/actions/RefreshTreeAction.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
import { clearTreeCache } from '../treeView/treeCache';
2+
import type { TreeDataProvider } from '../treeView/TreeDataProvider';
3+
import type { IAction } from './IAction';
4+
5+
export class RefreshTreeAction implements IAction {
6+
constructor(
7+
private readonly treeDataProvider: TreeDataProvider,
8+
private readonly clearCache = true,
9+
) {}
10+
11+
public async run() {
12+
if (this.clearCache) {
13+
clearTreeCache();
14+
}
15+
this.treeDataProvider.refresh();
16+
}
17+
}

src/cli/EFOutputParser.ts

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,9 @@ export class EFOutputParser {
4848
}
4949

5050
public static parse(output: string) {
51-
let warnings = '';
52-
let data = '';
53-
let errors = '';
51+
let warnings: string[] = [];
52+
let data: string[] = [];
53+
let errors: string[] = [];
5454
let matchedWarning = false;
5555
let matchedError = false;
5656

@@ -72,18 +72,18 @@ export class EFOutputParser {
7272
const lineWithoutPrefix = line.replace(OUTPUT_PREFIX, '');
7373

7474
if (matchedWarning) {
75-
warnings += lineWithoutPrefix;
75+
warnings.push(lineWithoutPrefix);
7676
} else if (matchedError) {
77-
errors += lineWithoutPrefix;
77+
errors.push(lineWithoutPrefix);
7878
} else if (matchedData) {
79-
data += lineWithoutPrefix;
79+
data.push(lineWithoutPrefix);
8080
}
8181
});
8282

8383
return {
84-
warnings,
85-
errors,
86-
data,
84+
warnings: warnings.join('\n'),
85+
errors: errors.join('\n'),
86+
data: data.join('\n'),
8787
};
8888
}
8989
}

src/commands/CommandProvider.ts

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import { EXTENSION_NAMESPACE } from '../constants/constants';
44
import type { TerminalProvider } from '../terminal/TerminalProvider';
55
import type { DbContextTreeItem } from '../treeView/DbContextTreeItem';
66
import type { MigrationTreeItem } from '../treeView/MigrationTreeItem';
7+
import type { ProjectTreeItem } from '../treeView/ProjectTreeItem';
78
import type { TreeDataProvider } from '../treeView/TreeDataProvider';
89
import { Disposable } from '../util/Disposable';
910
import type { Logger } from '../util/Logger';
@@ -13,6 +14,8 @@ import { DBContextInfoCommand } from './DBContextInfoCommand';
1314
import { GenerateERDCommand } from './GenerateERDCommand';
1415
import { GenerateScriptCommand } from './GenerateScriptCommand';
1516
import { OpenMigrationFileCommand } from './OpenMigrationFileCommand';
17+
import { RefreshDbContextTreeCommand } from './RefreshDbContextTreeCommand';
18+
import { RefreshProjectTreeCommand } from './RefreshProjectTreeCommand';
1619
import { RefreshTreeCommand } from './RefreshTreeCommand';
1720
import { RemoveMigrationsCommand } from './RemoveMigrationsCommand';
1821
import { RunMigrationCommand } from './RunMigrationCommand';
@@ -70,6 +73,14 @@ export class CommandProvider extends Disposable {
7073
(clearCache: boolean) =>
7174
new RefreshTreeCommand(treeDataProvider, clearCache),
7275
);
76+
this.registerCommand(
77+
RefreshDbContextTreeCommand.commandName,
78+
(item?: DbContextTreeItem) => new RefreshDbContextTreeCommand(item),
79+
);
80+
this.registerCommand(
81+
RefreshProjectTreeCommand.commandName,
82+
(item?: ProjectTreeItem) => new RefreshProjectTreeCommand(item),
83+
);
7384
this.registerCommand(
7485
OpenMigrationFileCommand.commandName,
7586
(item?: MigrationTreeItem) => new OpenMigrationFileCommand(item),
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { RefreshDbContextTreeAction } from '../actions/RefreshDbContextTreeAction';
2+
import type { DbContextTreeItem } from '../treeView/DbContextTreeItem';
3+
import { Command } from './Command';
4+
5+
export class RefreshDbContextTreeCommand extends Command {
6+
public static commandName = 'refreshDbContextTree';
7+
8+
constructor(private readonly item?: DbContextTreeItem) {
9+
super();
10+
}
11+
12+
public async run() {
13+
if (!this.item) {
14+
return;
15+
}
16+
await new RefreshDbContextTreeAction(this.item).run();
17+
}
18+
}
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import { RefreshProjectTreeAction } from '../actions/RefreshProjectTreeAction';
2+
import type { ProjectTreeItem } from '../treeView/ProjectTreeItem';
3+
import { Command } from './Command';
4+
5+
export class RefreshProjectTreeCommand extends Command {
6+
public static commandName = 'refreshProjectTree';
7+
8+
constructor(private readonly item?: ProjectTreeItem) {
9+
super();
10+
}
11+
12+
public async run() {
13+
if (!this.item) {
14+
return;
15+
}
16+
await new RefreshProjectTreeAction(this.item).run();
17+
}
18+
}

src/commands/RefreshTreeCommand.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { clearTreeCache } from '../treeView/treeCache';
1+
import { RefreshTreeAction } from '../actions/RefreshTreeAction';
22
import type { TreeDataProvider } from '../treeView/TreeDataProvider';
33
import { Command } from './Command';
44

@@ -13,9 +13,6 @@ export class RefreshTreeCommand extends Command {
1313
}
1414

1515
public async run() {
16-
if (this.clearCache) {
17-
clearTreeCache();
18-
}
19-
this.treeDataProvider.refresh();
16+
await new RefreshTreeAction(this.treeDataProvider, this.clearCache).run();
2017
}
2118
}

src/commands/RemoveMigrationsCommand.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ export class RemoveMigrationsCommand extends Command {
2828
this.item.dbContext,
2929
),
3030
);
31-
const index = migrations?.indexOf(this.item) || -1;
31+
const index = (migrations || []).indexOf(this.item);
3232
if (index === -1) {
3333
return;
3434
}

0 commit comments

Comments
 (0)