Skip to content

Add ability to refresh projects & dbcontexts #39

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

Merged
merged 3 commits into from
Jan 3, 2023
Merged
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
55 changes: 35 additions & 20 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,23 @@
},
{
"command": "entityframework.refreshTree",
"title": "Refresh Migrations",
"title": "Refresh",
"icon": {
"light": "icons/refresh_light.svg",
"dark": "icons/refresh_dark.svg"
}
},
{
"command": "entityframework.refreshDbContextTree",
"title": "Refresh",
"icon": {
"light": "icons/refresh_light.svg",
"dark": "icons/refresh_dark.svg"
}
},
{
"command": "entityframework.refreshProjectTree",
"title": "Refresh",
"icon": {
"light": "icons/refresh_light.svg",
"dark": "icons/refresh_dark.svg"
Expand Down Expand Up @@ -129,6 +145,14 @@
"command": "entityframework.refreshTree",
"when": "false"
},
{
"command": "entityframework.refreshProjectTree",
"when": "false"
},
{
"command": "entityframework.refreshDbContextTree",
"when": "false"
},
{
"command": "entityframework.removeMigrations",
"when": "false"
Expand Down Expand Up @@ -212,33 +236,19 @@
},
{
"command": "entityframework.generateScript",
"when": "viewItem == dbContext",
"group": "inline@3"
},
{
"command": "entityframework.generateScript",
"when": "viewItem == dbContext",
"group": "context@2"
"when": "viewItem == dbContext"
},
{
"command": "entityframework.generateERD",
"when": "viewItem == dbContext",
"group": "inline@2"
},
{
"command": "entityframework.generateERD",
"when": "viewItem == dbContext",
"group": "context@3"
"when": "viewItem == dbContext"
},
{
"command": "entityframework.dbContextInfo",
"when": "viewItem == dbContext",
"group": "inline@1"
"when": "viewItem == dbContext"
},
{
"command": "entityframework.dbContextInfo",
"when": "viewItem == dbContext",
"group": "context@4"
"command": "entityframework.refreshDbContextTree",
"when": "viewItem == dbContext"
},
{
"command": "entityframework.scaffold",
Expand All @@ -249,6 +259,11 @@
"command": "entityframework.scaffold",
"when": "viewItem == project",
"group": "context@1"
},
{
"command": "entityframework.refreshProjectTree",
"when": "viewItem == project",
"group": "context@2"
}
]
},
Expand Down
26 changes: 26 additions & 0 deletions src/actions/RefreshDbContextTreeAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
import * as vscode from 'vscode';
import { CommandProvider } from '../commands/CommandProvider';
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';

import {
dbContextsCache,
DbContextTreeItem,
} from '../treeView/DbContextTreeItem';
import type { IAction } from './IAction';

export class RefreshDbContextTreeAction implements IAction {
constructor(private readonly item: DbContextTreeItem) {}

public async run() {
const cacheId = DbContextTreeItem.getCacheId(
this.item.workspaceRoot,
this.item.projectFile.name,
this.item.label,
);
dbContextsCache.clear(cacheId);
await vscode.commands.executeCommand(
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
false,
);
}
}
21 changes: 21 additions & 0 deletions src/actions/RefreshProjectTreeAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import * as vscode from 'vscode';
import { CommandProvider } from '../commands/CommandProvider';
import { RefreshTreeCommand } from '../commands/RefreshTreeCommand';
import { projectsCache, ProjectTreeItem } from '../treeView/ProjectTreeItem';
import type { IAction } from './IAction';

export class RefreshProjectTreeAction implements IAction {
constructor(private readonly item: ProjectTreeItem) {}

public async run() {
const cacheId = ProjectTreeItem.getCacheId(
this.item.workspaceRoot,
this.item.label,
);
projectsCache.clear(cacheId);
await vscode.commands.executeCommand(
CommandProvider.getCommandName(RefreshTreeCommand.commandName),
false,
);
}
}
17 changes: 17 additions & 0 deletions src/actions/RefreshTreeAction.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import { clearTreeCache } from '../treeView/treeCache';
import type { TreeDataProvider } from '../treeView/TreeDataProvider';
import type { IAction } from './IAction';

export class RefreshTreeAction implements IAction {
constructor(
private readonly treeDataProvider: TreeDataProvider,
private readonly clearCache = true,
) {}

public async run() {
if (this.clearCache) {
clearTreeCache();
}
this.treeDataProvider.refresh();
}
}
18 changes: 9 additions & 9 deletions src/cli/EFOutputParser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,9 @@ export class EFOutputParser {
}

public static parse(output: string) {
let warnings = '';
let data = '';
let errors = '';
let warnings: string[] = [];
let data: string[] = [];
let errors: string[] = [];
let matchedWarning = false;
let matchedError = false;

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

if (matchedWarning) {
warnings += lineWithoutPrefix;
warnings.push(lineWithoutPrefix);
} else if (matchedError) {
errors += lineWithoutPrefix;
errors.push(lineWithoutPrefix);
} else if (matchedData) {
data += lineWithoutPrefix;
data.push(lineWithoutPrefix);
}
});

return {
warnings,
errors,
data,
warnings: warnings.join('\n'),
errors: errors.join('\n'),
data: data.join('\n'),
};
}
}
11 changes: 11 additions & 0 deletions src/commands/CommandProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { EXTENSION_NAMESPACE } from '../constants/constants';
import type { TerminalProvider } from '../terminal/TerminalProvider';
import type { DbContextTreeItem } from '../treeView/DbContextTreeItem';
import type { MigrationTreeItem } from '../treeView/MigrationTreeItem';
import type { ProjectTreeItem } from '../treeView/ProjectTreeItem';
import type { TreeDataProvider } from '../treeView/TreeDataProvider';
import { Disposable } from '../util/Disposable';
import type { Logger } from '../util/Logger';
Expand All @@ -13,6 +14,8 @@ import { DBContextInfoCommand } from './DBContextInfoCommand';
import { GenerateERDCommand } from './GenerateERDCommand';
import { GenerateScriptCommand } from './GenerateScriptCommand';
import { OpenMigrationFileCommand } from './OpenMigrationFileCommand';
import { RefreshDbContextTreeCommand } from './RefreshDbContextTreeCommand';
import { RefreshProjectTreeCommand } from './RefreshProjectTreeCommand';
import { RefreshTreeCommand } from './RefreshTreeCommand';
import { RemoveMigrationsCommand } from './RemoveMigrationsCommand';
import { RunMigrationCommand } from './RunMigrationCommand';
Expand Down Expand Up @@ -70,6 +73,14 @@ export class CommandProvider extends Disposable {
(clearCache: boolean) =>
new RefreshTreeCommand(treeDataProvider, clearCache),
);
this.registerCommand(
RefreshDbContextTreeCommand.commandName,
(item?: DbContextTreeItem) => new RefreshDbContextTreeCommand(item),
);
this.registerCommand(
RefreshProjectTreeCommand.commandName,
(item?: ProjectTreeItem) => new RefreshProjectTreeCommand(item),
);
this.registerCommand(
OpenMigrationFileCommand.commandName,
(item?: MigrationTreeItem) => new OpenMigrationFileCommand(item),
Expand Down
18 changes: 18 additions & 0 deletions src/commands/RefreshDbContextTreeCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RefreshDbContextTreeAction } from '../actions/RefreshDbContextTreeAction';
import type { DbContextTreeItem } from '../treeView/DbContextTreeItem';
import { Command } from './Command';

export class RefreshDbContextTreeCommand extends Command {
public static commandName = 'refreshDbContextTree';

constructor(private readonly item?: DbContextTreeItem) {
super();
}

public async run() {
if (!this.item) {
return;
}
await new RefreshDbContextTreeAction(this.item).run();
}
}
18 changes: 18 additions & 0 deletions src/commands/RefreshProjectTreeCommand.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { RefreshProjectTreeAction } from '../actions/RefreshProjectTreeAction';
import type { ProjectTreeItem } from '../treeView/ProjectTreeItem';
import { Command } from './Command';

export class RefreshProjectTreeCommand extends Command {
public static commandName = 'refreshProjectTree';

constructor(private readonly item?: ProjectTreeItem) {
super();
}

public async run() {
if (!this.item) {
return;
}
await new RefreshProjectTreeAction(this.item).run();
}
}
7 changes: 2 additions & 5 deletions src/commands/RefreshTreeCommand.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { clearTreeCache } from '../treeView/treeCache';
import { RefreshTreeAction } from '../actions/RefreshTreeAction';
import type { TreeDataProvider } from '../treeView/TreeDataProvider';
import { Command } from './Command';

Expand All @@ -13,9 +13,6 @@ export class RefreshTreeCommand extends Command {
}

public async run() {
if (this.clearCache) {
clearTreeCache();
}
this.treeDataProvider.refresh();
await new RefreshTreeAction(this.treeDataProvider, this.clearCache).run();
}
}
2 changes: 1 addition & 1 deletion src/commands/RemoveMigrationsCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class RemoveMigrationsCommand extends Command {
this.item.dbContext,
),
);
const index = migrations?.indexOf(this.item) || -1;
const index = (migrations || []).indexOf(this.item);
if (index === -1) {
return;
}
Expand Down