Skip to content

Commit

Permalink
Fix #29, Add custom when clause context keys
Browse files Browse the repository at this point in the history
  • Loading branch information
paulober committed Jul 15, 2023
1 parent f894751 commit 73938ed
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 13 deletions.
8 changes: 8 additions & 0 deletions src/activator.mts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ import { basename, dirname, join, relative, sep } from "path";
import { PicoWFs } from "./filesystem.mjs";
import { Terminal } from "./terminal.mjs";
import { fileURLToPath } from "url";
import { ContextKeys } from "./models/contextKeys.mjs";

/*const pkg: {} | undefined = vscode.extensions.getExtension("paulober.pico-w-go")
?.packageJSON as object;*/
Expand Down Expand Up @@ -81,6 +82,13 @@ export default class Activator {
);
}

// execute async not await
void vscode.commands.executeCommand(
"setContext",
ContextKeys.isActivated,
true
);

this.stubs = new Stubs();
await this.stubs.update();

Expand Down
11 changes: 7 additions & 4 deletions src/extension.mts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type * as vscode from "vscode";
import { type ExtensionContext, commands } from "vscode";
import Activator from "./activator.mjs";
import type UI from "./ui.mjs";
import { ContextKeys } from "./models/contextKeys.mjs";

let view: UI | undefined;

Expand All @@ -12,15 +13,17 @@ let view: UI | undefined;
*
* @param context The vscode context for this extension
*/
export async function activate(
context: vscode.ExtensionContext
): Promise<void> {
export async function activate(context: ExtensionContext): Promise<void> {
const activator = new Activator();
view = await activator.activate(context);
}

// this method is called when your extension is deactivated
export function deactivate(): void {
// execute async not await
void commands.executeCommand("setContext", ContextKeys.isActivated, false);
void commands.executeCommand("setContext", ContextKeys.isConnected, false);
// destry view
if (view !== undefined) {
setTimeout(() => {
view?.destroy();
Expand Down
14 changes: 12 additions & 2 deletions src/filesystem.mts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import {
FilePermission,
FileSystemError,
FileType,
window,
} from "vscode";
import { PyOutType } from "@paulober/pyboard-serial-com";
import type {
Expand All @@ -38,11 +39,11 @@ const picoWFsVscodeConfiguration = false;
export class PicoWFs implements FileSystemProvider {
private logger: Logger;

private cache: Map<string, any> = new Map();
//private cache: Map<string, any> = new Map();
private remoteConfigFs = remoteConfigFs;

private pyb: PyboardRunner;
private cacheEnabled = false;
//private cacheEnabled = false;

// FileSystemProvider stuff
private _emitter = new EventEmitter<FileChangeEvent[]>();
Expand Down Expand Up @@ -308,6 +309,13 @@ export class PicoWFs implements FileSystemProvider {
// does always overwrite
options: { readonly overwrite: boolean }
): Promise<void> {
//if old uri is open in editor close this editor window
for (const editor of window.visibleTextEditors) {
if (editor.document.uri.path === oldUri.path) {
await editor.document.save();
}
}

if (forbiddenFolders.some(folder => oldUri.path.includes(folder))) {
this.logger.error("rename: file destination in forbidden folder");
throw FileSystemError.NoPermissions(oldUri);
Expand All @@ -320,6 +328,8 @@ export class PicoWFs implements FileSystemProvider {
if (!status) {
throw FileSystemError.FileExists(newUri);
}

return;
}

this.logger.error("rename: unexpected result type");
Expand Down
7 changes: 7 additions & 0 deletions src/models/contextKeys.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
/**
* Contributed when-clause context keys.
*/
export enum ContextKeys {
isActivated = "pico-w-go.isActivated",
isConnected = "pico-w-go.isConnected",
}
12 changes: 5 additions & 7 deletions src/ui.mts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import type { StatusBarItem } from "vscode";
import Logger from "./logger.mjs";
import { SettingsKey } from "./settings.mjs";
import type Settings from "./settings.mjs";
import { ContextKeys } from "./models/contextKeys.mjs";

interface PkgJSON {
statusBar: Array<{
Expand Down Expand Up @@ -102,15 +103,12 @@ export default class UI {
);
}

public refreshState(force?: boolean): void {
if (force !== undefined) {
this.setState(force);
public refreshState(force: boolean): void {
this.setState(force);

return;
}
void commands.executeCommand("setContext", ContextKeys.isConnected, force);

// TODO: if board is connected setState(true) else setState(false)
throw new Error("Method not implemented.");
return;
}

private statusbarItemPriority = 11;
Expand Down

0 comments on commit 73938ed

Please sign in to comment.