Skip to content

Commit

Permalink
Merge pull request #1367 from posit-dev/sagerb-update-extension-provi…
Browse files Browse the repository at this point in the history
…ders-to-have-consistent-initialization

Refactor extension and providers to have consistency in constructor and registration
  • Loading branch information
sagerb authored Apr 17, 2024
2 parents 7e16cdc + 52ed812 commit dd02fae
Showing 11 changed files with 156 additions and 182 deletions.
18 changes: 9 additions & 9 deletions extensions/vscode/src/extension.ts
Original file line number Diff line number Diff line change
@@ -142,15 +142,15 @@ export async function activate(context: ExtensionContext) {
service = new Service(context, port);
checkForCredentials();

new ProjectTreeDataProvider().register(context);
new DeploymentsTreeDataProvider(stream).register(context);
new ConfigurationsTreeDataProvider().register(context);
new FilesTreeDataProvider().register(context);
new RequirementsTreeDataProvider().register(context);
new CredentialsTreeDataProvider().register(context);
new HelpAndFeedbackTreeDataProvider().register(context);
new LogsTreeDataProvider(stream).register(context);
new HomeViewProvider(context.extensionUri, stream).register(context);
new ProjectTreeDataProvider(context).register();
new DeploymentsTreeDataProvider(context, stream).register();
new ConfigurationsTreeDataProvider(context).register();
new FilesTreeDataProvider(context).register();
new RequirementsTreeDataProvider(context).register();
new CredentialsTreeDataProvider(context).register();
new HelpAndFeedbackTreeDataProvider(context).register();
new LogsTreeDataProvider(context, stream).register();
new HomeViewProvider(context, stream).register();

await service.start();

8 changes: 4 additions & 4 deletions extensions/vscode/src/views/configurations.ts
Original file line number Diff line number Diff line change
@@ -53,7 +53,7 @@ export class ConfigurationsTreeDataProvider
readonly onDidChangeTreeData: ConfigurationEvent =
this._onDidChangeTreeData.event;

constructor() {
constructor(private readonly _context: ExtensionContext) {
const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders !== undefined) {
this.root = workspaceFolders[0];
@@ -98,12 +98,12 @@ export class ConfigurationsTreeDataProvider
}
}

public register(context: ExtensionContext) {
public register() {
const treeView = window.createTreeView(viewName, {
treeDataProvider: this,
});

context.subscriptions.push(
this._context.subscriptions.push(
treeView,
commands.registerCommand(refreshCommand, this.refresh),
commands.registerCommand(addCommand, this.add),
@@ -113,7 +113,7 @@ export class ConfigurationsTreeDataProvider
commands.registerCommand(deleteCommand, this.delete),
);
if (this.root !== undefined) {
context.subscriptions.push(this.createFileSystemWatcher(this.root));
this._context.subscriptions.push(this.createFileSystemWatcher(this.root));
}
}

8 changes: 4 additions & 4 deletions extensions/vscode/src/views/credentials.ts
Original file line number Diff line number Diff line change
@@ -30,7 +30,7 @@ export class CredentialsTreeDataProvider
readonly onDidChangeTreeData: CredentialEvent =
this._onDidChangeTreeData.event;

constructor() {}
constructor(private readonly _context: ExtensionContext) {}

getTreeItem(element: CredentialsTreeItem): TreeItem | Thenable<TreeItem> {
return element;
@@ -66,12 +66,12 @@ export class CredentialsTreeDataProvider
this._onDidChangeTreeData.fire();
};

public register(context: ExtensionContext) {
context.subscriptions.push(
public register() {
this._context.subscriptions.push(
window.createTreeView(viewName, { treeDataProvider: this }),
);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(refreshCommand, this.refresh),
);
}
45 changes: 0 additions & 45 deletions extensions/vscode/src/views/dependencies.ts

This file was deleted.

29 changes: 16 additions & 13 deletions extensions/vscode/src/views/deployments.ts
Original file line number Diff line number Diff line change
@@ -59,7 +59,10 @@ export class DeploymentsTreeDataProvider
readonly onDidChangeTreeData: DeploymentsEvent =
this._onDidChangeTreeData.event;

constructor(private stream: EventStream) {
constructor(
private readonly _context: ExtensionContext,
private readonly _stream: EventStream,
) {
const workspaceFolders = workspace.workspaceFolders;
if (workspaceFolders !== undefined) {
this.root = workspaceFolders[0];
@@ -116,44 +119,44 @@ export class DeploymentsTreeDataProvider
}
}

public register(context: ExtensionContext) {
public register() {
const treeView = window.createTreeView(viewName, {
treeDataProvider: this,
});
context.subscriptions.push(treeView);
this._context.subscriptions.push(treeView);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(addDeploymentCommand, () => {
return newDeployment(
"Deploy Your Project to a New Location",
true,
this.stream,
this._stream,
);
}),
);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(createNewDeploymentFileCommand, () => {
return newDeployment("Create a Deployment File for your Project");
}),
);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(refreshCommand, this.refresh),
);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(
deployCommand,
async (item: DeploymentsTreeItem) => {
if (!isDeploymentError(item.deployment)) {
publishDeployment(item.deployment, this.stream);
publishDeployment(item.deployment, this._stream);
}
},
),
);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(
forgetCommand,
async (item: DeploymentsTreeItem) => {
@@ -168,7 +171,7 @@ export class DeploymentsTreeDataProvider
),
);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(
editCommand,
async (item: DeploymentsTreeItem) => {
@@ -177,7 +180,7 @@ export class DeploymentsTreeDataProvider
),
);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(
visitCommand,
async (item: DeploymentsTreeItem) => {
@@ -197,7 +200,7 @@ export class DeploymentsTreeDataProvider
watcher.onDidCreate(this.refresh);
watcher.onDidDelete(this.refresh);
watcher.onDidChange(this.refresh);
context.subscriptions.push(watcher);
this._context.subscriptions.push(watcher);
}
}
}
10 changes: 5 additions & 5 deletions extensions/vscode/src/views/files.ts
Original file line number Diff line number Diff line change
@@ -42,7 +42,7 @@ export class FilesTreeDataProvider implements TreeDataProvider<TreeEntries> {
private _onDidChangeTreeData: FilesEventEmitter = new EventEmitter();
readonly onDidChangeTreeData: FilesEvent = this._onDidChangeTreeData.event;

constructor() {
constructor(private readonly _context: ExtensionContext) {
const workspaceFolders = workspace.workspaceFolders;
this.root = Uri.parse("positPublisherFiles://unknown");
if (workspaceFolders !== undefined) {
@@ -94,12 +94,12 @@ export class FilesTreeDataProvider implements TreeDataProvider<TreeEntries> {
return [];
}

public register(context: ExtensionContext) {
public register() {
const treeView = window.createTreeView(viewName, {
treeDataProvider: this,
});
context.subscriptions.push(treeView);
context.subscriptions.push(
this._context.subscriptions.push(treeView);
this._context.subscriptions.push(
commands.registerCommand(refreshCommand, this.refresh),
);

@@ -110,7 +110,7 @@ export class FilesTreeDataProvider implements TreeDataProvider<TreeEntries> {
watcher.onDidCreate(this.refresh);
watcher.onDidDelete(this.refresh);
watcher.onDidChange(this.refresh);
context.subscriptions.push(watcher);
this._context.subscriptions.push(watcher);
}
}
}
10 changes: 5 additions & 5 deletions extensions/vscode/src/views/helpAndFeedback.ts
Original file line number Diff line number Diff line change
@@ -18,7 +18,7 @@ const openFeedbackCommand = viewName + "openFeedback";
export class HelpAndFeedbackTreeDataProvider
implements TreeDataProvider<HelpAndFeedbackTreeItem>
{
constructor() {}
constructor(private readonly _context: ExtensionContext) {}

getTreeItem(element: HelpAndFeedbackTreeItem): TreeItem | Thenable<TreeItem> {
return element;
@@ -44,12 +44,12 @@ export class HelpAndFeedbackTreeDataProvider
return [];
}

public register(context: ExtensionContext) {
context.subscriptions.push(
public register() {
this._context.subscriptions.push(
window.createTreeView(viewName, { treeDataProvider: this }),
);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(openGettingStartedCommand, () => {
env.openExternal(
Uri.parse(
@@ -59,7 +59,7 @@ export class HelpAndFeedbackTreeDataProvider
}),
);

context.subscriptions.push(
this._context.subscriptions.push(
commands.registerCommand(openFeedbackCommand, () => {
env.openExternal(
Uri.parse("https://positpbc.slack.com/channels/publisher-feedback"),
Loading

0 comments on commit dd02fae

Please sign in to comment.