From c60851fbaa0dea3faf667b6ac6c67f7cef4a1f80 Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:16:54 -0400 Subject: [PATCH 01/11] parses groups --- src/EnvironmentTreeviewProvider.ts | 18 ++-- .../TreeItems/EnvironmentFileTreeItem.ts | 7 +- .../TreeItems/EnvironmentGroupTreeItem.ts | 16 ++++ .../TreeItems/EnvironmentKeyValueTreeItem.ts | 2 +- src/helpers/parse.ts | 89 +++++++++++++------ src/types.d.ts | 5 +- 6 files changed, 95 insertions(+), 42 deletions(-) create mode 100644 src/classes/TreeItems/EnvironmentGroupTreeItem.ts diff --git a/src/EnvironmentTreeviewProvider.ts b/src/EnvironmentTreeviewProvider.ts index 2a49e7b..ee13d36 100644 --- a/src/EnvironmentTreeviewProvider.ts +++ b/src/EnvironmentTreeviewProvider.ts @@ -3,6 +3,7 @@ import { parseEnvironmentContent, replace } from "./helpers/parse"; import { EnvironmentWorkspaceFolderTreeItem } from "./classes/TreeItems/EnvironmentWorkspaceFolderTreeItem"; import { EnvironmentKeyValueTreeItem } from "./classes/TreeItems/EnvironmentKeyValueTreeItem"; import { EnvironmentFileTreeItem } from "./classes/TreeItems/EnvironmentFileTreeItem"; +import { EnvironmentGroupTreeItem } from "./classes/TreeItems/EnvironmentGroupTreeItem"; export class EnvironmentTreeviewProvider implements vscode.TreeDataProvider @@ -36,7 +37,7 @@ export class EnvironmentTreeviewProvider const selected = e.selection[0]; if (selected instanceof EnvironmentKeyValueTreeItem) { await vscode.window.showTextDocument( - await vscode.workspace.openTextDocument(selected.parent.uri) + await vscode.workspace.openTextDocument(selected.file) ); } }); @@ -120,11 +121,11 @@ export class EnvironmentTreeviewProvider async edit(element: EnvironmentKeyValueTreeItem, input: string) { const content = new TextDecoder().decode( - await vscode.workspace.fs.readFile(element.parent.uri) + await vscode.workspace.fs.readFile(element.file) ); await vscode.workspace.fs.writeFile( - element.parent.uri, + element.file, new TextEncoder().encode(replace(content, element.key, input)) ); @@ -160,13 +161,10 @@ export class EnvironmentTreeviewProvider } } else if (element instanceof EnvironmentWorkspaceFolderTreeItem) { return this.getFileData(element.folder); + } else if (element instanceof EnvironmentGroupTreeItem) { + return element.children; } else if (element instanceof EnvironmentFileTreeItem) { - return Promise.resolve( - Object.keys(element.content).map( - (key): EnvironmentKeyValueTreeItem => - new EnvironmentKeyValueTreeItem(key, element.content[key], element) - ) - ); + return element.children; } } @@ -194,7 +192,7 @@ export class EnvironmentTreeviewProvider new EnvironmentFileTreeItem( path, fileUris[index], - parseEnvironmentContent(fileContentStrings[index]) + parseEnvironmentContent(fileContentStrings[index], fileUris[index]) ) ); } diff --git a/src/classes/TreeItems/EnvironmentFileTreeItem.ts b/src/classes/TreeItems/EnvironmentFileTreeItem.ts index 1bfd699..f4780b7 100644 --- a/src/classes/TreeItems/EnvironmentFileTreeItem.ts +++ b/src/classes/TreeItems/EnvironmentFileTreeItem.ts @@ -1,11 +1,14 @@ import * as vscode from "vscode"; -import type { EnvironmentContent } from "../../types"; +import { EnvironmentGroupTreeItem } from "./EnvironmentGroupTreeItem"; +import { EnvironmentKeyValueTreeItem } from "./EnvironmentKeyValueTreeItem"; export class EnvironmentFileTreeItem extends vscode.TreeItem { constructor( public readonly name: string, public readonly uri: vscode.Uri, - public readonly content: EnvironmentContent, + public readonly children: Array< + EnvironmentGroupTreeItem | EnvironmentKeyValueTreeItem + >, public readonly collapsibleState: vscode.TreeItemCollapsibleState = vscode .TreeItemCollapsibleState.Collapsed ) { diff --git a/src/classes/TreeItems/EnvironmentGroupTreeItem.ts b/src/classes/TreeItems/EnvironmentGroupTreeItem.ts new file mode 100644 index 0000000..3a3cb01 --- /dev/null +++ b/src/classes/TreeItems/EnvironmentGroupTreeItem.ts @@ -0,0 +1,16 @@ +import * as vscode from "vscode"; +import { EnvironmentKeyValueTreeItem } from "./EnvironmentKeyValueTreeItem"; + +export class EnvironmentGroupTreeItem extends vscode.TreeItem { + constructor( + public readonly name: string, + public readonly presets: string[], + public readonly children: EnvironmentKeyValueTreeItem[], + public readonly collapsibleState: vscode.TreeItemCollapsibleState = vscode + .TreeItemCollapsibleState.Collapsed + ) { + super(name, collapsibleState); + this.contextValue = "group"; + this.presets = presets; + } +} diff --git a/src/classes/TreeItems/EnvironmentKeyValueTreeItem.ts b/src/classes/TreeItems/EnvironmentKeyValueTreeItem.ts index c202886..4af6c62 100644 --- a/src/classes/TreeItems/EnvironmentKeyValueTreeItem.ts +++ b/src/classes/TreeItems/EnvironmentKeyValueTreeItem.ts @@ -6,7 +6,7 @@ export class EnvironmentKeyValueTreeItem extends vscode.TreeItem { constructor( public readonly key: string, public readonly value: EnvironmentKeyValue, - public readonly parent: EnvironmentFileTreeItem, + public readonly file: vscode.Uri, public readonly collapsibleState: vscode.TreeItemCollapsibleState = vscode .TreeItemCollapsibleState.None ) { diff --git a/src/helpers/parse.ts b/src/helpers/parse.ts index f5208e7..708c700 100644 --- a/src/helpers/parse.ts +++ b/src/helpers/parse.ts @@ -1,45 +1,78 @@ +import * as vscode from "vscode"; +import { EnvironmentGroupTreeItem } from "../classes/TreeItems/EnvironmentGroupTreeItem"; +import { EnvironmentKeyValueTreeItem } from "../classes/TreeItems/EnvironmentKeyValueTreeItem"; import type { EnvironmentContent, EnvironmentKeyValueType } from "../types"; const LINE = - /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(#.*)?(?:$|$)/gm; + /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(#.*)?(?:$|$)|^\s*(###.*)$/gm; -export const parseEnvironmentContent = (lines: string): EnvironmentContent => { - const obj: EnvironmentContent = {}; +export const parseEnvironmentContent = ( + lines: string, + file: vscode.Uri +): EnvironmentContent => { + const items: (EnvironmentKeyValueTreeItem | EnvironmentGroupTreeItem)[] = []; + let currentGroup: EnvironmentGroupTreeItem | null = null; // Convert line breaks to same format lines = lines.replace(/\r\n?/gm, "\n"); let match; while ((match = LINE.exec(lines)) != null) { - const key = match[1]; - - // Default undefined or null to empty string - let value = match[2] || ""; - - // Remove whitespace - value = value.trim(); - - // Check if double quoted - const maybeQuote = value[0]; - - // Remove surrounding quotes - value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2"); - - // Expand newlines if double quoted - if (maybeQuote === '"') { - value = value.replace(/\\n/g, "\n"); - value = value.replace(/\\r/g, "\r"); + if (match[4]) { + if (currentGroup && match[4].trim().endsWith("###")) { + // Group end + items.push(currentGroup); + currentGroup = null; + } else { + // Group start + currentGroup = new EnvironmentGroupTreeItem( + match[4].split(" ")[1], + [], + [] + ); + items.push(currentGroup); + } + } else { + const key = match[1]; + + // Default undefined or null to empty string + let value = match[2] || ""; + + // Remove whitespace + value = value.trim(); + + // Check if double quoted + const maybeQuote = value[0]; + + // Remove surrounding quotes + value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2"); + + // Expand newlines if double quoted + if (maybeQuote === '"') { + value = value.replace(/\\n/g, "\n"); + value = value.replace(/\\r/g, "\r"); + } + + const keyValueItem = new EnvironmentKeyValueTreeItem( + key, + { type: inferType(value), value, options: parseOptions(match[3]) }, + file + ); + + // Add to items + if (currentGroup) { + currentGroup.children.push(keyValueItem); + } else { + items.push(keyValueItem); + } } + } - // Add to object - obj[key] = { - value, - type: inferType(value), - options: parseOptions(match[3]), - }; + if (currentGroup) { + items.push(currentGroup); } - return obj; + return items; }; export const inferType = (value: string): EnvironmentKeyValueType => { diff --git a/src/types.d.ts b/src/types.d.ts index eabb3b6..1dbf179 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -1,4 +1,7 @@ -export type EnvironmentContent = Record; +export type EnvironmentContent = Record< + string, + EnvironmentContent | EnvironmentKeyValue +>; export interface EnvironmentKeyValue { value: string; From 31ee50484f937be5ad1119332c6338878a77b084 Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:28:16 -0400 Subject: [PATCH 02/11] parses presets --- src/helpers/parse.ts | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/src/helpers/parse.ts b/src/helpers/parse.ts index 708c700..0aa4394 100644 --- a/src/helpers/parse.ts +++ b/src/helpers/parse.ts @@ -27,8 +27,7 @@ export const parseEnvironmentContent = ( // Group start currentGroup = new EnvironmentGroupTreeItem( match[4].split(" ")[1], - [], - [] + parsePresets(match[4]) ); items.push(currentGroup); } @@ -93,5 +92,15 @@ export const parseOptions = (input: string | undefined): string[] => { return match?.[1].split(",") ?? []; }; +export const parsePresets = (input: string | undefined): string[] => { + // Create a regex that finds the key followed by a colon and captures the value + const regex = new RegExp(`presets:([^\\s]*)`, "i"); + + // Execute the regex on the input string + const match = input?.match(regex); + + return match?.[1].split(",") ?? []; +}; + export const replace = (content: string, key: string, value: string): string => content.replace(new RegExp(`(${key}="?)([^\\s"]*)`, "g"), `$1${value}`); From d157677e8b226816618555ad9e475b5cab2660b3 Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:28:34 -0400 Subject: [PATCH 03/11] adds default to children --- src/classes/TreeItems/EnvironmentGroupTreeItem.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/classes/TreeItems/EnvironmentGroupTreeItem.ts b/src/classes/TreeItems/EnvironmentGroupTreeItem.ts index 3a3cb01..b7ac8f6 100644 --- a/src/classes/TreeItems/EnvironmentGroupTreeItem.ts +++ b/src/classes/TreeItems/EnvironmentGroupTreeItem.ts @@ -5,12 +5,13 @@ export class EnvironmentGroupTreeItem extends vscode.TreeItem { constructor( public readonly name: string, public readonly presets: string[], - public readonly children: EnvironmentKeyValueTreeItem[], + public readonly children: EnvironmentKeyValueTreeItem[] = [], public readonly collapsibleState: vscode.TreeItemCollapsibleState = vscode .TreeItemCollapsibleState.Collapsed ) { super(name, collapsibleState); this.contextValue = "group"; this.presets = presets; + this.children = children; } } From 81254ae1c96cc4bf149ac9cfb75d8da9be9275e9 Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:30:16 -0400 Subject: [PATCH 04/11] prevents duplicate groups --- src/helpers/parse.ts | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/helpers/parse.ts b/src/helpers/parse.ts index 0aa4394..7ae4f83 100644 --- a/src/helpers/parse.ts +++ b/src/helpers/parse.ts @@ -4,7 +4,7 @@ import { EnvironmentKeyValueTreeItem } from "../classes/TreeItems/EnvironmentKey import type { EnvironmentContent, EnvironmentKeyValueType } from "../types"; const LINE = - /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(#.*)?(?:$|$)|^\s*(###.*)$/gm; + /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(#.*)?(?:$|$)|^\s*(\n###.*)$/gm; export const parseEnvironmentContent = ( lines: string, @@ -67,10 +67,6 @@ export const parseEnvironmentContent = ( } } - if (currentGroup) { - items.push(currentGroup); - } - return items; }; From 7756bb69d2b524596d9bf8bf82b4d3ebddb754ac Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 19:44:39 -0400 Subject: [PATCH 05/11] parses group name --- src/helpers/parse.ts | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/src/helpers/parse.ts b/src/helpers/parse.ts index 7ae4f83..b6d02d4 100644 --- a/src/helpers/parse.ts +++ b/src/helpers/parse.ts @@ -4,7 +4,7 @@ import { EnvironmentKeyValueTreeItem } from "../classes/TreeItems/EnvironmentKey import type { EnvironmentContent, EnvironmentKeyValueType } from "../types"; const LINE = - /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(#.*)?(?:$|$)|^\s*(\n###.*)$/gm; + /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(#.*)?(?:$|$)|^\s*(\n?###.*)$/gm; export const parseEnvironmentContent = ( lines: string, @@ -26,7 +26,7 @@ export const parseEnvironmentContent = ( } else { // Group start currentGroup = new EnvironmentGroupTreeItem( - match[4].split(" ")[1], + parseGroupName(match[4]), parsePresets(match[4]) ); items.push(currentGroup); @@ -100,3 +100,14 @@ export const parsePresets = (input: string | undefined): string[] => { export const replace = (content: string, key: string, value: string): string => content.replace(new RegExp(`(${key}="?)([^\\s"]*)`, "g"), `$1${value}`); + +export const parseGroupName = (input: string): string => { + // Create a regex to capture the group name between ### and presets + const regex = /###\s*(.*?)\s*(?=presets|$)/i; + + // Execute the regex on the input string + const match = input.match(regex); + + // Return the captured group name or an empty string if not found + return match?.[1].trim() ?? ""; +}; From da2f02bebd5bef5e13c64388aa474992b47f2d78 Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 20:16:03 -0400 Subject: [PATCH 06/11] fixes issues with duplicate groups --- src/helpers/parse.ts | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/helpers/parse.ts b/src/helpers/parse.ts index b6d02d4..e43c7ab 100644 --- a/src/helpers/parse.ts +++ b/src/helpers/parse.ts @@ -4,7 +4,7 @@ import { EnvironmentKeyValueTreeItem } from "../classes/TreeItems/EnvironmentKey import type { EnvironmentContent, EnvironmentKeyValueType } from "../types"; const LINE = - /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(#.*)?(?:$|$)|^\s*(\n?###.*)$/gm; + /(?:^|^)\s*(?:export\s+)?([\w.-]+)(?:\s*=\s*?|:\s+?)(\s*'(?:\\'|[^'])*'|\s*"(?:\\"|[^"])*"|\s*`(?:\\`|[^`])*`|[^#\r\n]+)?\s*(#.*)?(?:$|$)|^\s*(\n###.*)$/gm; export const parseEnvironmentContent = ( lines: string, @@ -13,6 +13,8 @@ export const parseEnvironmentContent = ( const items: (EnvironmentKeyValueTreeItem | EnvironmentGroupTreeItem)[] = []; let currentGroup: EnvironmentGroupTreeItem | null = null; + // Add a new line at start of file to match first line + lines = "\n" + lines; // Convert line breaks to same format lines = lines.replace(/\r\n?/gm, "\n"); From eb7244437e92a9f97baf0f8dfbd4b532f90124c2 Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:45:15 -0400 Subject: [PATCH 07/11] toggles presets --- package.json | 12 +++++- src/EnvironmentTreeviewProvider.ts | 8 ++++ src/extension.ts | 20 +++++++++ src/helpers/parse.ts | 67 ++++++++++++++++++++++-------- src/types.d.ts | 1 + 5 files changed, 90 insertions(+), 18 deletions(-) diff --git a/package.json b/package.json index 821aec2..ad7eda5 100644 --- a/package.json +++ b/package.json @@ -32,6 +32,11 @@ "title": "Refresh", "icon": "$(refresh)" }, + { + "command": "environments.set-preset", + "title": "Set Preset", + "icon": "$(edit)" + }, { "command": "environments.edit", "title": "Edit", @@ -80,6 +85,11 @@ "when": "viewItem == file", "group": "inline" }, + { + "command": "environments.set-preset", + "when": "viewItem == group", + "group": "inline" + }, { "command": "environments.rename", "when": "viewItem == file" @@ -149,4 +159,4 @@ "typescript": "^5.5.3", "vite": "^5.3.3" } -} +} \ No newline at end of file diff --git a/src/EnvironmentTreeviewProvider.ts b/src/EnvironmentTreeviewProvider.ts index ee13d36..07f72d4 100644 --- a/src/EnvironmentTreeviewProvider.ts +++ b/src/EnvironmentTreeviewProvider.ts @@ -115,6 +115,14 @@ export class EnvironmentTreeviewProvider this.edit(element, element.value.value === "true" ? "false" : "true"); } + async setPreset(element: EnvironmentGroupTreeItem, preset: string) { + for (const child of element.children) { + if (child.value.presets) { + await this.edit(child, child.value.presets[preset]); + } + } + } + refresh() { this._onDidChangeTreeData?.fire(); } diff --git a/src/extension.ts b/src/extension.ts index b394b15..9a51527 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -3,6 +3,7 @@ import { EnvironmentTreeviewProvider } from "./EnvironmentTreeviewProvider"; import { EnvironmentWorkspaceFolderTreeItem } from "./classes/TreeItems/EnvironmentWorkspaceFolderTreeItem"; import { EnvironmentFileTreeItem } from "./classes/TreeItems/EnvironmentFileTreeItem"; import { EnvironmentKeyValueTreeItem } from "./classes/TreeItems/EnvironmentKeyValueTreeItem"; +import { EnvironmentGroupTreeItem } from "./classes/TreeItems/EnvironmentGroupTreeItem"; export function activate(context: vscode.ExtensionContext) { const treeDataProvider = new EnvironmentTreeviewProvider(context).register(); @@ -39,6 +40,25 @@ export function activate(context: vscode.ExtensionContext) { } ); + vscode.commands.registerCommand( + "environments.set-preset", + async (element: EnvironmentGroupTreeItem) => { + const preset = await vscode.window.showQuickPick(element.presets, { + placeHolder: "Select a preset", + }); + + if (!preset) { + return; + } + + if (!element.presets.includes(preset)) { + vscode.window.showErrorMessage("Invalid preset"); + } else { + await treeDataProvider.setPreset(element, preset); + } + } + ); + vscode.commands.registerCommand( "environments.add", async (element: EnvironmentFileTreeItem) => { diff --git a/src/helpers/parse.ts b/src/helpers/parse.ts index e43c7ab..741ade7 100644 --- a/src/helpers/parse.ts +++ b/src/helpers/parse.ts @@ -37,26 +37,16 @@ export const parseEnvironmentContent = ( const key = match[1]; // Default undefined or null to empty string - let value = match[2] || ""; - - // Remove whitespace - value = value.trim(); - - // Check if double quoted - const maybeQuote = value[0]; - - // Remove surrounding quotes - value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2"); - - // Expand newlines if double quoted - if (maybeQuote === '"') { - value = value.replace(/\\n/g, "\n"); - value = value.replace(/\\r/g, "\r"); - } + let value = sanitizeValue(match[2] || ""); const keyValueItem = new EnvironmentKeyValueTreeItem( key, - { type: inferType(value), value, options: parseOptions(match[3]) }, + { + type: inferType(value), + value, + options: parseOptions(match[3]), + presets: parsePresetValues(currentGroup?.presets, match[3]), + }, file ); @@ -72,6 +62,25 @@ export const parseEnvironmentContent = ( return items; }; +export const sanitizeValue = (value: string): string => { + // Remove whitespace + value = value.trim(); + + // Check if double quoted + const maybeQuote = value[0]; + + // Remove surrounding quotes + value = value.replace(/^(['"`])([\s\S]*)\1$/gm, "$2"); + + // Expand newlines if double quoted + if (maybeQuote === '"') { + value = value.replace(/\\n/g, "\n"); + value = value.replace(/\\r/g, "\r"); + } + + return value; +}; + export const inferType = (value: string): EnvironmentKeyValueType => { if (value === "true" || value === "false") { return "bool"; @@ -100,6 +109,30 @@ export const parsePresets = (input: string | undefined): string[] => { return match?.[1].split(",") ?? []; }; +export const parsePresetValues = ( + presets: string[] | undefined, + input: string | undefined +): Record => { + const result: Record = {}; + + // If no presets, return empty object + if (!presets) { + return result; + } + + for (const preset of presets) { + // Create a regex that finds the key followed by a colon and captures the value + const regex = new RegExp(`${preset}:([^\\s]*)`, "i"); + // Execute the regex on the input string + const match = input?.match(regex); + if (match) { + result[preset] = sanitizeValue(match[1]); + } + } + + return result; +}; + export const replace = (content: string, key: string, value: string): string => content.replace(new RegExp(`(${key}="?)([^\\s"]*)`, "g"), `$1${value}`); diff --git a/src/types.d.ts b/src/types.d.ts index 1dbf179..16efd3f 100644 --- a/src/types.d.ts +++ b/src/types.d.ts @@ -7,6 +7,7 @@ export interface EnvironmentKeyValue { value: string; type: EnvironmentKeyValueType; options?: string[]; + presets?: Record; } export type EnvironmentKeyValueType = "string" | "bool"; From 795c25893a2b0d7d8098338edc45ae13c9a46aef Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:51:49 -0400 Subject: [PATCH 08/11] updates icon --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index ad7eda5..d88af21 100644 --- a/package.json +++ b/package.json @@ -35,7 +35,7 @@ { "command": "environments.set-preset", "title": "Set Preset", - "icon": "$(edit)" + "icon": "$(library)" }, { "command": "environments.edit", From fb954819b66408fafdea007850eb1fdf9d40b328 Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:54:32 -0400 Subject: [PATCH 09/11] adds conditional for preset icon --- package.json | 2 +- src/classes/TreeItems/EnvironmentGroupTreeItem.ts | 7 ++++++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d88af21..e232733 100644 --- a/package.json +++ b/package.json @@ -87,7 +87,7 @@ }, { "command": "environments.set-preset", - "when": "viewItem == group", + "when": "viewItem == group-has-presets", "group": "inline" }, { diff --git a/src/classes/TreeItems/EnvironmentGroupTreeItem.ts b/src/classes/TreeItems/EnvironmentGroupTreeItem.ts index b7ac8f6..07c8c34 100644 --- a/src/classes/TreeItems/EnvironmentGroupTreeItem.ts +++ b/src/classes/TreeItems/EnvironmentGroupTreeItem.ts @@ -10,8 +10,13 @@ export class EnvironmentGroupTreeItem extends vscode.TreeItem { .TreeItemCollapsibleState.Collapsed ) { super(name, collapsibleState); - this.contextValue = "group"; this.presets = presets; this.children = children; + + if (presets.length > 1) { + this.contextValue = "group-has-presets"; + } else { + this.contextValue = "group"; + } } } From 2e6c89ac57a129e50566e56b806315fd14bac353 Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:54:54 -0400 Subject: [PATCH 10/11] allows for one preset --- src/classes/TreeItems/EnvironmentGroupTreeItem.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/classes/TreeItems/EnvironmentGroupTreeItem.ts b/src/classes/TreeItems/EnvironmentGroupTreeItem.ts index 07c8c34..8f03bcc 100644 --- a/src/classes/TreeItems/EnvironmentGroupTreeItem.ts +++ b/src/classes/TreeItems/EnvironmentGroupTreeItem.ts @@ -13,7 +13,7 @@ export class EnvironmentGroupTreeItem extends vscode.TreeItem { this.presets = presets; this.children = children; - if (presets.length > 1) { + if (presets.length > 0) { this.contextValue = "group-has-presets"; } else { this.contextValue = "group"; From aa9d73d28b919587c7f0fefbca1541c1607f96a4 Mon Sep 17 00:00:00 2001 From: Isaac Poole <55164207+isfopo@users.noreply.github.com> Date: Tue, 16 Jul 2024 22:55:48 -0400 Subject: [PATCH 11/11] removes period from description --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index e232733..555856c 100644 --- a/package.json +++ b/package.json @@ -2,7 +2,7 @@ "name": "environments", "displayName": "Environments", "publisher": "isfopo", - "description": "Manage your environments from your sidebar.", + "description": "Manage your environments from your sidebar", "version": "0.0.36", "icon": "assets/icon.png", "type": "module",