Skip to content

Commit

Permalink
Remove public exports. Add DotRush status bar integration
Browse files Browse the repository at this point in the history
  • Loading branch information
JaneySprings committed Nov 17, 2024
1 parent 7f3b217 commit bf20e18
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 68 deletions.
59 changes: 41 additions & 18 deletions src/VSCode.Extension/controllers/statusbarController.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { ConfigurationController } from './configurationController';
import { Interop } from "../interop/interop";
import { StateController } from './stateController';
import { PublicExports } from '../publicExports';
import { Interop } from "../interop/interop";
import { Project } from '../models/project';
import { ProjectItem } from '../models/projectItem';
import { Device } from '../models/device';
Expand All @@ -19,10 +18,12 @@ export class StatusBarController {
public static projects: Project[];
public static devices: Device[];

public static activate(context: vscode.ExtensionContext) {
private static dotrushExports: any | undefined;

public static async activate(context: vscode.ExtensionContext): Promise<void> {
StatusBarController.projectStatusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 100);
StatusBarController.targetStatusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 90);
StatusBarController.deviceStatusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 80);
StatusBarController.targetStatusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 99);
StatusBarController.deviceStatusItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Left, 98);

StatusBarController.targetStatusItem.command = res.commandIdSelectActiveConfiguration;
StatusBarController.projectStatusItem.command = res.commandIdSelectActiveProject;
Expand All @@ -32,22 +33,42 @@ export class StatusBarController {
context.subscriptions.push(StatusBarController.targetStatusItem);
context.subscriptions.push(StatusBarController.deviceStatusItem);

context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(StatusBarController.update));
context.subscriptions.push(vscode.workspace.onDidSaveTextDocument(ev => {
if (ev.fileName.endsWith('proj') || ev.fileName.endsWith('.props'))
StatusBarController.update();
}));
context.subscriptions.push(vscode.commands.registerCommand(res.commandIdSelectActiveProject, StatusBarController.showQuickPickProject));
context.subscriptions.push(vscode.commands.registerCommand(res.commandIdSelectActiveConfiguration, StatusBarController.showQuickPickConfiguration));
context.subscriptions.push(vscode.commands.registerCommand(res.commandIdSelectActiveDevice, StatusBarController.showQuickPickDevice));

if (vscode.extensions.getExtension(res.dotrushExtensionId) !== undefined)
StatusBarController.dotrushExports = await vscode.extensions.getExtension(res.dotrushExtensionId)?.activate();

if (StatusBarController.dotrushExports === undefined) {
context.subscriptions.push(vscode.workspace.onDidChangeWorkspaceFolders(() => StatusBarController.update()));
context.subscriptions.push(vscode.workspace.onDidSaveTextDocument(ev => {
if (ev.fileName.endsWith('proj') || ev.fileName.endsWith('.props'))
StatusBarController.update();
}));

StatusBarController.update();
} else {
StatusBarController.dotrushExports.onProjectsChanged.add(StatusBarController.update);
StatusBarController.dotrushExports.onActiveProjectChanged.add(StatusBarController.performSelectProject);
StatusBarController.dotrushExports.onActiveConfigurationChanged.add(StatusBarController.performSelectConfiguration);
}
}
public static deactivate() {
StatusBarController.dotrushExports?.onProjectsChanged?.remove(StatusBarController.update);
StatusBarController.dotrushExports?.onActiveProjectChanged?.remove(StatusBarController.performSelectProject);
StatusBarController.dotrushExports?.onActiveConfigurationChanged?.remove(StatusBarController.performSelectConfiguration);
}
public static async update() : Promise<void> {

public static async update(projects: Project[] | undefined = undefined, devices: Device[] | undefined = undefined) : Promise<void> {
const folders = vscode.workspace.workspaceFolders!.map(it => it.uri.fsPath);
StatusBarController.projects = await Interop.getProjects(folders);
StatusBarController.devices = await Interop.getDevices();
StatusBarController.projects = projects ?? await Interop.getProjects(folders);
StatusBarController.devices = devices ?? await Interop.getDevices();

if (StatusBarController.projects.length === 0 || StatusBarController.devices.length === 0) {
StatusBarController.projectStatusItem.hide();
StatusBarController.targetStatusItem.hide();
StatusBarController.deviceStatusItem.hide();
PublicExports.instance.invokeAll();
return;
}

Expand All @@ -56,8 +77,13 @@ export class StatusBarController {
StatusBarController.performSelectConfiguration(ConfigurationController.configuration);
StatusBarController.performSelectDevice(ConfigurationController.device);

StatusBarController.targetStatusItem.show();
if (StatusBarController.dotrushExports !== undefined) {
StatusBarController.deviceStatusItem.show();
return;
}

StatusBarController.deviceStatusItem.show();
StatusBarController.targetStatusItem.show();
StatusBarController.projects.length === 1
? StatusBarController.projectStatusItem.hide()
: StatusBarController.projectStatusItem.show();
Expand All @@ -66,19 +92,16 @@ export class StatusBarController {
public static performSelectProject(item: Project | undefined = undefined) {
ConfigurationController.project = item ?? StatusBarController.projects[0];
StatusBarController.projectStatusItem.text = `${Icons.project} ${ConfigurationController.project?.name}`;
PublicExports.instance.projectChangedEventHandler.invoke(ConfigurationController.project);
StateController.saveProject();
}
public static performSelectConfiguration(item: string | undefined = undefined) {
ConfigurationController.configuration = item ?? 'Debug';
StatusBarController.targetStatusItem.text = `${Icons.target} ${ConfigurationController.configuration} | Any CPU`;
PublicExports.instance.configurationChangedEventHandler.invoke(ConfigurationController.configuration);
StateController.saveTarget();
}
public static performSelectDevice(item: Device | undefined = undefined) {
ConfigurationController.device = item ?? StatusBarController.devices[0];
StatusBarController.deviceStatusItem.text = `${Icons.deviceKind(ConfigurationController.device)} ${ConfigurationController.device?.name}`;
PublicExports.instance.deviceChangedEventHandler.invoke(ConfigurationController.device);
StateController.saveDevice();
}

Expand Down
12 changes: 2 additions & 10 deletions src/VSCode.Extension/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import { ConfigurationController } from './controllers/configurationController';
import { StatusBarController } from './controllers/statusbarController';
import { Interop } from './interop/interop';
import { StateController } from './controllers/stateController';
import { PublicExports } from './publicExports';
import { ModulesView } from './features/modulesView';
import { MauiEssentials } from './features/mauiEssentials';
import { ExternalTypeResolver } from './features/externalTypeResolver';
Expand All @@ -13,27 +12,21 @@ import * as res from './resources/constants';
import * as vscode from 'vscode';


export function activate(context: vscode.ExtensionContext): PublicExports | undefined {
export function activate(context: vscode.ExtensionContext) {
Interop.initialize(context.extensionPath);

if (vscode.workspace.workspaceFolders === undefined)
return undefined;

const exports = new PublicExports();

ConfigurationController.activate(context);
StateController.activate(context);
StatusBarController.activate(context);
StatusBarController.update();

ModulesView.feature.activate(context);
MauiEssentials.feature.activate(context);
ExternalTypeResolver.feature.activate(context);
RemoteHostProvider.feature.activate(context);

context.subscriptions.push(vscode.commands.registerCommand(res.commandIdSelectActiveProject, StatusBarController.showQuickPickProject));
context.subscriptions.push(vscode.commands.registerCommand(res.commandIdSelectActiveConfiguration, StatusBarController.showQuickPickConfiguration));
context.subscriptions.push(vscode.commands.registerCommand(res.commandIdSelectActiveDevice, StatusBarController.showQuickPickDevice));
context.subscriptions.push(vscode.commands.registerCommand(res.commandIdActiveTargetFramework, () => ConfigurationController.getTargetFramework()));
context.subscriptions.push(vscode.commands.registerCommand(res.commandIdActiveConfiguration, () => ConfigurationController.configuration));
context.subscriptions.push(vscode.commands.registerCommand(res.commandIdActiveProjectPath, () => ConfigurationController.project?.path));
Expand All @@ -42,10 +35,9 @@ export function activate(context: vscode.ExtensionContext): PublicExports | unde

context.subscriptions.push(vscode.debug.registerDebugConfigurationProvider(res.debuggerMeteorId, new MonoDebugConfigurationProvider()));
context.subscriptions.push(vscode.tasks.registerTaskProvider(res.taskDefinitionId, new DotNetTaskProvider()));

return exports;
}

export function deactivate() {
StateController.deactivate();
StatusBarController.deactivate();
}
40 changes: 0 additions & 40 deletions src/VSCode.Extension/publicExports.ts

This file was deleted.

0 comments on commit bf20e18

Please sign in to comment.