From d495585133175abf3e35ffbedd905b82a20fc8b5 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Tue, 3 Jan 2023 18:13:24 +0000 Subject: [PATCH 1/3] Fix output parsing. Refs #35 --- src/cli/EFOutputParser.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/cli/EFOutputParser.ts b/src/cli/EFOutputParser.ts index ca53747..07fdf36 100644 --- a/src/cli/EFOutputParser.ts +++ b/src/cli/EFOutputParser.ts @@ -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; @@ -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'), }; } } From f4376f4d0c4f84cb1c33da903d151cc511042531 Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Tue, 3 Jan 2023 18:37:20 +0000 Subject: [PATCH 2/3] Add refresh project & dbcontext commands. Fixes #37 --- package.json | 55 +++++++++++++-------- src/actions/RefreshDbContextTreeAction.ts | 26 ++++++++++ src/actions/RefreshProjectTreeAction.ts | 21 ++++++++ src/actions/RefreshTreeAction.ts | 17 +++++++ src/commands/CommandProvider.ts | 11 +++++ src/commands/RefreshDbContextTreeCommand.ts | 18 +++++++ src/commands/RefreshProjectTreeCommand.ts | 18 +++++++ src/commands/RefreshTreeCommand.ts | 7 +-- 8 files changed, 148 insertions(+), 25 deletions(-) create mode 100644 src/actions/RefreshDbContextTreeAction.ts create mode 100644 src/actions/RefreshProjectTreeAction.ts create mode 100644 src/actions/RefreshTreeAction.ts create mode 100644 src/commands/RefreshDbContextTreeCommand.ts create mode 100644 src/commands/RefreshProjectTreeCommand.ts diff --git a/package.json b/package.json index 261cfc8..6de15aa 100644 --- a/package.json +++ b/package.json @@ -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" @@ -129,6 +145,14 @@ "command": "entityframework.refreshTree", "when": "false" }, + { + "command": "entityframework.refreshProjectTree", + "when": "false" + }, + { + "command": "entityframework.refreshDbContextTree", + "when": "false" + }, { "command": "entityframework.removeMigrations", "when": "false" @@ -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", @@ -249,6 +259,11 @@ "command": "entityframework.scaffold", "when": "viewItem == project", "group": "context@1" + }, + { + "command": "entityframework.refreshProjectTree", + "when": "viewItem == project", + "group": "context@2" } ] }, diff --git a/src/actions/RefreshDbContextTreeAction.ts b/src/actions/RefreshDbContextTreeAction.ts new file mode 100644 index 0000000..eb0ec10 --- /dev/null +++ b/src/actions/RefreshDbContextTreeAction.ts @@ -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, + ); + } +} diff --git a/src/actions/RefreshProjectTreeAction.ts b/src/actions/RefreshProjectTreeAction.ts new file mode 100644 index 0000000..ee35964 --- /dev/null +++ b/src/actions/RefreshProjectTreeAction.ts @@ -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, + ); + } +} diff --git a/src/actions/RefreshTreeAction.ts b/src/actions/RefreshTreeAction.ts new file mode 100644 index 0000000..cd773d3 --- /dev/null +++ b/src/actions/RefreshTreeAction.ts @@ -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(); + } +} diff --git a/src/commands/CommandProvider.ts b/src/commands/CommandProvider.ts index e2e357e..37b3875 100644 --- a/src/commands/CommandProvider.ts +++ b/src/commands/CommandProvider.ts @@ -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'; @@ -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'; @@ -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), diff --git a/src/commands/RefreshDbContextTreeCommand.ts b/src/commands/RefreshDbContextTreeCommand.ts new file mode 100644 index 0000000..7e15b09 --- /dev/null +++ b/src/commands/RefreshDbContextTreeCommand.ts @@ -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(); + } +} diff --git a/src/commands/RefreshProjectTreeCommand.ts b/src/commands/RefreshProjectTreeCommand.ts new file mode 100644 index 0000000..7813e10 --- /dev/null +++ b/src/commands/RefreshProjectTreeCommand.ts @@ -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(); + } +} diff --git a/src/commands/RefreshTreeCommand.ts b/src/commands/RefreshTreeCommand.ts index ccb8bda..e026f1c 100644 --- a/src/commands/RefreshTreeCommand.ts +++ b/src/commands/RefreshTreeCommand.ts @@ -1,4 +1,4 @@ -import { clearTreeCache } from '../treeView/treeCache'; +import { RefreshTreeAction } from '../actions/RefreshTreeAction'; import type { TreeDataProvider } from '../treeView/TreeDataProvider'; import { Command } from './Command'; @@ -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(); } } From 4a4305db81dceb843a5034f205278532d26fb2dc Mon Sep 17 00:00:00 2001 From: Richard Willis Date: Tue, 3 Jan 2023 18:45:10 +0000 Subject: [PATCH 3/3] Fix removing migrations --- src/commands/RemoveMigrationsCommand.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/commands/RemoveMigrationsCommand.ts b/src/commands/RemoveMigrationsCommand.ts index 12f7b89..7fa14b5 100644 --- a/src/commands/RemoveMigrationsCommand.ts +++ b/src/commands/RemoveMigrationsCommand.ts @@ -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; }