Skip to content

Commit

Permalink
Merge pull request #113 from badsyntax/feature/configure
Browse files Browse the repository at this point in the history
Improve tree refresh
  • Loading branch information
badsyntax authored Sep 21, 2024
2 parents 37a9ccb + 2a05e1d commit 29bdb7c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 27 deletions.
13 changes: 2 additions & 11 deletions src/commands/CommandProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
import type { Project } from 'nuget-deps-tree';
import * as vscode from 'vscode';
import { EXTENSION_NAMESPACE } from '../constants/constants';
import type { TerminalProvider } from '../terminal/TerminalProvider';
Expand Down Expand Up @@ -30,7 +29,6 @@ export class CommandProvider extends Disposable {
treeDataProvider: TreeDataProvider,
terminalProvider: TerminalProvider,
extensionUri: vscode.Uri,
solutionProjects?: Project[],
) {
super();
this.registerCommand(
Expand Down Expand Up @@ -68,13 +66,7 @@ export class CommandProvider extends Disposable {
this.registerCommand(
GenerateERDCommand.commandName,
(item?: DbContextTreeItem) =>
new GenerateERDCommand(
logger,
terminalProvider,
extensionUri,
item,
solutionProjects,
),
new GenerateERDCommand(logger, terminalProvider, extensionUri, item),
);
this.registerCommand(
RefreshTreeCommand.commandName,
Expand All @@ -100,8 +92,7 @@ export class CommandProvider extends Disposable {
);
this.registerCommand(
ScaffoldCommand.commandName,
(item?: DbContextTreeItem) =>
new ScaffoldCommand(terminalProvider, item, solutionProjects),
(item?: DbContextTreeItem) => new ScaffoldCommand(terminalProvider, item),
);
this.registerCommand(
ConfigureCommand.commandName,
Expand Down
6 changes: 3 additions & 3 deletions src/commands/GenerateERDCommand.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import type { TerminalProvider } from '../terminal/TerminalProvider';
import { type DbContextTreeItem } from '../treeView/DbContextTreeItem';
import { Command } from './Command';
import type { Logger } from '../util/Logger';
import type { Project } from 'nuget-deps-tree';
import { ProjectFilesProvider } from '../solution/ProjectFilesProvider';

export class GenerateERDCommand extends Command {
public static commandName = 'generateERD';
Expand All @@ -17,7 +17,6 @@ export class GenerateERDCommand extends Command {
private readonly terminalProvider: TerminalProvider,
private readonly extensionUri: vscode.Uri,
private readonly item?: DbContextTreeItem,
private readonly solutionProjects?: Project[],
) {
super();
}
Expand All @@ -27,14 +26,15 @@ export class GenerateERDCommand extends Command {
return;
}
const outputDir = fs.mkdtempSync(path.join(os.tmpdir(), 'mermaid-erd'));
const { solutionProjects } = await ProjectFilesProvider.getProjectFiles();
return new GenerateERDAction(
this.logger,
this.terminalProvider,
this.item.label,
this.item.projectFile,
outputDir,
this.extensionUri,
this.solutionProjects,
solutionProjects,
).run();
}
}
6 changes: 3 additions & 3 deletions src/commands/ScaffoldCommand.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
import type { Project } from 'nuget-deps-tree';
import { ScaffoldAction } from '../actions/ScaffoldAction';
import type { TerminalProvider } from '../terminal/TerminalProvider';
import { type DbContextTreeItem } from '../treeView/DbContextTreeItem';
import { Command } from './Command';
import { ProjectFilesProvider } from '../solution/ProjectFilesProvider';

export class ScaffoldCommand extends Command {
public static commandName = 'scaffold';

constructor(
private readonly terminalProvider: TerminalProvider,
private readonly item?: DbContextTreeItem,
private readonly solutionProjects?: Project[],
) {
super();
}
Expand All @@ -19,10 +18,11 @@ export class ScaffoldCommand extends Command {
if (!this.item) {
return;
}
const { solutionProjects } = await ProjectFilesProvider.getProjectFiles();
return new ScaffoldAction(
this.terminalProvider,
this.item.projectFile,
this.solutionProjects,
solutionProjects,
).run();
}
}
8 changes: 1 addition & 7 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,24 @@ import { MigrationTreeItemDecorationProvider } from './treeView/MigrationTreeIte
import { Terminal } from './terminal/Terminal';
import { TerminalProvider } from './terminal/TerminalProvider';
import { TextDocumentProvider } from './util/TextDocumentProvider';
import { ProjectFilesProvider } from './solution/ProjectFilesProvider';
import { Logger } from './util/Logger';
import { CLI } from './cli/CLI';

export async function activate(context: vscode.ExtensionContext) {
const logger = new Logger();
logger.info(`Extension activated`);

const { projectFiles, solutionProjects } =
await ProjectFilesProvider.getProjectFiles();
logger.info(`Discovered ${projectFiles.length} compatible projects`);

const cli = new CLI(logger);
const textDocumentProvider = new TextDocumentProvider();
const migrationTreeItemDecorationProvider =
new MigrationTreeItemDecorationProvider();
const treeDataProvider = new TreeDataProvider(logger, projectFiles, cli);
const treeDataProvider = new TreeDataProvider(logger, cli);
const terminalProvider = new TerminalProvider(new Terminal(cli));
const commandProvider = new CommandProvider(
logger,
treeDataProvider,
terminalProvider,
context.extensionUri,
solutionProjects,
);

context.subscriptions.push(
Expand Down
6 changes: 3 additions & 3 deletions src/treeView/TreeDataProvider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ import * as vscode from 'vscode';
import { type TreeItem } from './TreeItem';
import { Disposable } from '../util/Disposable';
import { EXTENSION_NAMESPACE } from '../constants/constants';
import type { ProjectFile } from '../types/ProjectFile';
import { ProjectTreeItem } from './ProjectTreeItem';
import type { CLI } from '../cli/CLI';
import { MigrationTreeItem } from './MigrationTreeItem';
import { CommandProvider } from '../commands/CommandProvider';
import { OpenMigrationFileCommand } from '../commands/OpenMigrationFileCommand';
import type { Logger } from '../util/Logger';
import { getProjectsConfig } from '../config/config';
import { ProjectFilesProvider } from '../solution/ProjectFilesProvider';

export class TreeDataProvider
extends Disposable
Expand All @@ -25,7 +25,6 @@ export class TreeDataProvider

constructor(
private readonly logger: Logger,
private readonly projectFiles: ProjectFile[],
private readonly cli: CLI,
) {
super();
Expand Down Expand Up @@ -68,8 +67,9 @@ export class TreeDataProvider
return element.getChildren();
} else {
const { project } = getProjectsConfig();
const { projectFiles } = await ProjectFilesProvider.getProjectFiles();

return this.projectFiles
return projectFiles
.filter(projectFile => !project || projectFile.name === project)
.map(
projectFile =>
Expand Down

0 comments on commit 29bdb7c

Please sign in to comment.