From 774eb7d57db362ec5077a33eb98003643949e328 Mon Sep 17 00:00:00 2001 From: "hugues.verlin" Date: Mon, 11 Nov 2024 10:03:04 -0500 Subject: [PATCH] update --- .github/workflows/ci.yml | 1 + biome.json | 33 ++++++ mise.toml | 5 +- package.json | 169 ++++++++++++++------------- pnpm-lock.yaml | 91 +++++++++++++++ resources/icon.png | Bin 0 -> 3659 bytes resources/icon.svg | 12 +- src/extension.ts | 98 +++++++++------- src/miseService.ts | 116 ++++++++++--------- src/providers/envProvider.ts | 44 +++---- src/providers/tasksProvider.ts | 42 +++---- src/providers/toolsProvider.ts | 44 +++---- src/types.ts | 24 ++-- src/utils/logger.ts | 202 +++++++++++++++++---------------- tsconfig.json | 22 ++-- webpack.config.js | 85 +++++++------- 16 files changed, 575 insertions(+), 413 deletions(-) create mode 100644 biome.json create mode 100644 resources/icon.png diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index c36b420..e2c09c9 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -23,6 +23,7 @@ jobs: node-version: ${{ matrix.node-version }} - run: corepack enable && pnpm i --frozen-lockfile + - run: pnpm lint - run: pnpm compile publish-vscode-openvsx: diff --git a/biome.json b/biome.json new file mode 100644 index 0000000..14b8b3a --- /dev/null +++ b/biome.json @@ -0,0 +1,33 @@ +{ + "$schema": "https://biomejs.dev/schemas/1.9.4/schema.json", + "vcs": { + "enabled": false, + "clientKind": "git", + "useIgnoreFile": true + }, + "files": { + "ignoreUnknown": false, + "ignore": ["node_modules", "dist", ".vscode"] + }, + "formatter": { + "enabled": true, + "indentStyle": "tab" + }, + "organizeImports": { + "enabled": true + }, + "linter": { + "enabled": true, + "rules": { + "recommended": true, + "suspicious": { + "noConfusingVoidType": "off" + } + } + }, + "javascript": { + "formatter": { + "quoteStyle": "double" + } + } +} diff --git a/mise.toml b/mise.toml index 46aafd5..a32619f 100644 --- a/mise.toml +++ b/mise.toml @@ -1,2 +1,5 @@ [tools] -node = '22' \ No newline at end of file +node = '22' + +[tasks] +run = 'echo "Hello, World!"' \ No newline at end of file diff --git a/package.json b/package.json index 332fe1b..c3dbc55 100644 --- a/package.json +++ b/package.json @@ -1,81 +1,92 @@ { - "name": "mise-vscode", - "displayName": "Mise VSCode", - "publisher": "hverlin", - "description": "VSCode extension for mise (manged dev tools, tasks and environment variables)", - "version": "0.0.1", - "repository": { - "type": "git", - "url": "https://github.com/hverlin/mise-vscode" - }, - "engines": { - "vscode": "^1.85.0" - }, - "categories": [ - "Other" - ], - "activationEvents": [ - "onView:miseTasksView", - "onView:miseToolsView", - "onView:miseEnvsView" - ], - "main": "./dist/extension.js", - "contributes": { - "viewsContainers": { - "activitybar": [ - { - "id": "mise-panel", - "title": "Mise panel", - "icon": "resources/icon.svg" - } - ] - }, - "views": { - "mise-panel": [ - { - "id": "miseTasksView", - "name": "Mise Tasks" - }, - { - "id": "miseToolsView", - "name": "Mise Tools" - }, - { - "id": "miseEnvsView", - "name": "Environment Variables" - } - ] - }, - "commands": [ - { - "command": "mise.refreshEntry", - "title": "Refresh", - "icon": "$(refresh)" - } - ], - "menus": { - "view/title": [ - { - "command": "mise.refreshEntry", - "when": "view == miseTasksView || view == miseToolsView || view == miseEnvsView", - "group": "navigation" - } - ] - } - }, - "scripts": { - "vscode:prepublish": "npm run package --no-optional", - "compile": "webpack", - "watch": "webpack --watch", - "package": "webpack --mode production --devtool hidden-source-map" - }, - "devDependencies": { - "@types/vscode": "^1.85.0", - "@types/node": "^22.9.0", - "typescript": "^5.6.3", - "ts-loader": "^9.5.1", - "webpack": "5.96.1", - "webpack-cli": "^5.1.4" - }, - "packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228" + "name": "mise-vscode", + "displayName": "Mise VSCode", + "publisher": "hverlin", + "description": "VSCode extension for mise (manged dev tools, tasks and environment variables)", + "version": "0.0.1", + "repository": { + "type": "git", + "url": "https://github.com/hverlin/mise-vscode" + }, + "bugs": { + "url": "https://github.com/hverlin/mise-vscode/issues" + }, + "license": "MIT", + "engines": { + "vscode": "^1.85.0" + }, + "categories": ["Other"], + "keywords": [ + "mise", + "mise-en-place", + "rtx", + "devtools", + "tasks", + "envs", + "environment variables", + "scripts" + ], + "icon": "resources/icon.png", + "main": "./dist/extension.js", + "contributes": { + "viewsContainers": { + "activitybar": [ + { + "id": "mise-panel", + "title": "Mise panel", + "icon": "$(terminal)" + } + ] + }, + "views": { + "mise-panel": [ + { + "id": "miseTasksView", + "name": "Mise Tasks" + }, + { + "id": "miseToolsView", + "name": "Mise Tools" + }, + { + "id": "miseEnvsView", + "name": "Environment Variables" + } + ] + }, + "commands": [ + { + "command": "mise.refreshEntry", + "title": "Refresh", + "icon": "$(refresh)" + } + ], + "menus": { + "view/title": [ + { + "command": "mise.refreshEntry", + "when": "view == miseTasksView || view == miseToolsView || view == miseEnvsView", + "group": "navigation" + } + ] + } + }, + "scripts": { + "vscode:prepublish": "npm run package --no-optional", + "compile": "webpack", + "watch": "webpack --watch", + "lint-fix": "biome check --fix", + "lint": "biome ci", + "package": "webpack --mode production --devtool hidden-source-map" + }, + "devDependencies": { + "@biomejs/biome": "1.9.4", + "@types/node": "^22.9.0", + "@types/vscode": "^1.85.0", + "ts-loader": "^9.5.1", + "typescript": "^5.6.3", + "webpack": "5.96.1", + "webpack-cli": "^5.1.4" + }, + "packageManager": "pnpm@9.12.2+sha512.22721b3a11f81661ae1ec68ce1a7b879425a1ca5b991c975b074ac220b187ce56c708fe5db69f4c962c989452eee76c82877f4ee80f474cebd61ee13461b6228" } diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index 4d5de1b..e2eb3b5 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -8,6 +8,9 @@ importers: .: devDependencies: + '@biomejs/biome': + specifier: 1.9.4 + version: 1.9.4 '@types/node': specifier: ^22.9.0 version: 22.9.0 @@ -29,6 +32,59 @@ importers: packages: + '@biomejs/biome@1.9.4': + resolution: {integrity: sha512-1rkd7G70+o9KkTn5KLmDYXihGoTaIGO9PIIN2ZB7UJxFrWw04CZHPYiMRjYsaDvVV7hP1dYNRLxSANLaBFGpog==} + engines: {node: '>=14.21.3'} + hasBin: true + + '@biomejs/cli-darwin-arm64@1.9.4': + resolution: {integrity: sha512-bFBsPWrNvkdKrNCYeAp+xo2HecOGPAy9WyNyB/jKnnedgzl4W4Hb9ZMzYNbf8dMCGmUdSavlYHiR01QaYR58cw==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [darwin] + + '@biomejs/cli-darwin-x64@1.9.4': + resolution: {integrity: sha512-ngYBh/+bEedqkSevPVhLP4QfVPCpb+4BBe2p7Xs32dBgs7rh9nY2AIYUL6BgLw1JVXV8GlpKmb/hNiuIxfPfZg==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [darwin] + + '@biomejs/cli-linux-arm64-musl@1.9.4': + resolution: {integrity: sha512-v665Ct9WCRjGa8+kTr0CzApU0+XXtRgwmzIf1SeKSGAv+2scAlW6JR5PMFo6FzqqZ64Po79cKODKf3/AAmECqA==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [linux] + + '@biomejs/cli-linux-arm64@1.9.4': + resolution: {integrity: sha512-fJIW0+LYujdjUgJJuwesP4EjIBl/N/TcOX3IvIHJQNsAqvV2CHIogsmA94BPG6jZATS4Hi+xv4SkBBQSt1N4/g==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [linux] + + '@biomejs/cli-linux-x64-musl@1.9.4': + resolution: {integrity: sha512-gEhi/jSBhZ2m6wjV530Yy8+fNqG8PAinM3oV7CyO+6c3CEh16Eizm21uHVsyVBEB6RIM8JHIl6AGYCv6Q6Q9Tg==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [linux] + + '@biomejs/cli-linux-x64@1.9.4': + resolution: {integrity: sha512-lRCJv/Vi3Vlwmbd6K+oQ0KhLHMAysN8lXoCI7XeHlxaajk06u7G+UsFSO01NAs5iYuWKmVZjmiOzJ0OJmGsMwg==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [linux] + + '@biomejs/cli-win32-arm64@1.9.4': + resolution: {integrity: sha512-tlbhLk+WXZmgwoIKwHIHEBZUwxml7bRJgk0X2sPyNR3S93cdRq6XulAZRQJ17FYGGzWne0fgrXBKpl7l4M87Hg==} + engines: {node: '>=14.21.3'} + cpu: [arm64] + os: [win32] + + '@biomejs/cli-win32-x64@1.9.4': + resolution: {integrity: sha512-8Y5wMhVIPaWe6jw2H+KlEm4wP/f7EW3810ZLmDlrEEy5KvBsb9ECEfu/kMWD484ijfQ8+nIi0giMgu9g1UAuuA==} + engines: {node: '>=14.21.3'} + cpu: [x64] + os: [win32] + '@discoveryjs/json-ext@0.5.7': resolution: {integrity: sha512-dBVuXR082gk3jsFp7Rd/JI4kytwGHecnCoTtXFb7DB6CNHp4rg5k1bhg0nWdLGLnOV71lmDzGQaLMy8iPLY0pw==} engines: {node: '>=10.0.0'} @@ -571,6 +627,41 @@ packages: snapshots: + '@biomejs/biome@1.9.4': + optionalDependencies: + '@biomejs/cli-darwin-arm64': 1.9.4 + '@biomejs/cli-darwin-x64': 1.9.4 + '@biomejs/cli-linux-arm64': 1.9.4 + '@biomejs/cli-linux-arm64-musl': 1.9.4 + '@biomejs/cli-linux-x64': 1.9.4 + '@biomejs/cli-linux-x64-musl': 1.9.4 + '@biomejs/cli-win32-arm64': 1.9.4 + '@biomejs/cli-win32-x64': 1.9.4 + + '@biomejs/cli-darwin-arm64@1.9.4': + optional: true + + '@biomejs/cli-darwin-x64@1.9.4': + optional: true + + '@biomejs/cli-linux-arm64-musl@1.9.4': + optional: true + + '@biomejs/cli-linux-arm64@1.9.4': + optional: true + + '@biomejs/cli-linux-x64-musl@1.9.4': + optional: true + + '@biomejs/cli-linux-x64@1.9.4': + optional: true + + '@biomejs/cli-win32-arm64@1.9.4': + optional: true + + '@biomejs/cli-win32-x64@1.9.4': + optional: true + '@discoveryjs/json-ext@0.5.7': {} '@jridgewell/gen-mapping@0.3.5': diff --git a/resources/icon.png b/resources/icon.png new file mode 100644 index 0000000000000000000000000000000000000000..a37c550e5ac0bd1ef1daeab41052ddc2eca7c8cb GIT binary patch literal 3659 zcmeI!e@v8R902g|^WJ;hb;+-eA0g1)LW1T38VjiqP%s3Hn4w-Y;MG5bfI!sn0Og)2 zWNZesM09gOIakRP8u4QSds)oUf|xYcUNPu3a}1FoQw|F5-k$GPY)$`Ay0(_xANPIs zeBST(`99CR+db8(DGAQHwK@QBPTU&59e`&;9<=Nm(u)sfvB2#~PKXDks&+^OaN!f< zH>H`!X2!bDo!$XQudORY&xv+Y|f296W^m!?R?rd zt~6O6e`c<(KYHkzvipb9#!2qzsrfs-ZF}27v%2}Tj3V9$lr6;;cGSRel~y|Xzog?% zz;TuS_<1;48w)^y2RCrkz;TsUI{Fuuq(PaMtNO}Z$XvQPxUg}%^y5ggeny$zP!qj4 zm+k6VLCihMKw|=FdXkC@El{_nFJ@^MXq{xywjO@rZjahMVGl9yRdnzLM0Hx!G!-%> zk&Ar>KD(7gj8D+lF-_a&gK4}x#L~7I=mBdBgq6VXxXAU5k}iRz>oxM%h`!Vr@hylL zV|biM`w*Rk>xka;Im9=h12K(A`w`W`G@_pRBPK#Iq6d+R5P4ye;Ti+oh-d~Y;$t zJ~&hV@xXjp(6Bf8W`Y#pt5>dGRlE1;EI*YtOr%dg-@EW#;c&wZ_U}DdGWk(^=C32! z;!Byl+`3?ytZ%m}Q-^B2Nvp*TmNX9*cvwn+R?9sh`>BB%!FzV1q~z?ba`W_s>zAD6 zR#6d6c}i`;)fi5;yK;hJ1na{EEm&(oQ2q?m#!3kao0CLa09XqZ?SoFe2T}}s_-}@X zTXUsZ2ds>ZA6E&=WoK%O+rZ9ooJ}134^H%dUo#{2DvkMaUC)%$$~#l%dY^sw=epPp z@76?TpoNvOJjdlhQe3Ad!oQ7UljOI`;C#ExYfl=cJfp?(_wnpoAsC ziBM|mk0hpx>?{M+!WBeM8u&QFbU3k|p_!P@Avy`C5PfJMX6AwwGrNe?iKr1oM1Oh& zu@s6C7m3u)Fq{`U84kJA48&yUK#U?%2clZ&M)ag_Bfbd{h=+;v6{3^ShUi0IMa+Yc z5QaUZ>vKenyo~5i?;w`JFybJ>;~TZjvUP_I7wCwe-`_LZvZYg4yc za@6t^OCRNKTgWX#DOtpQT!N@)+4JFG@$9qj_8ka6a#CZ+uuTM1=0M1}I9t8>ZqPj! w|92W%UR3Q#(cg%7yMxD=9}=I75a<{D - - - - - + + + + + \ No newline at end of file diff --git a/src/extension.ts b/src/extension.ts index a875911..5556179 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -1,50 +1,60 @@ -import * as vscode from 'vscode'; -import { MiseTasksProvider } from './providers/tasksProvider'; -import { MiseToolsProvider } from './providers/toolsProvider'; -import { MiseEnvsProvider } from './providers/envProvider'; -import { MiseService } from './miseService'; +import * as vscode from "vscode"; +import { MiseService } from "./miseService"; +import { MiseEnvsProvider } from "./providers/envProvider"; +import { MiseTasksProvider } from "./providers/tasksProvider"; +import { MiseToolsProvider } from "./providers/toolsProvider"; let statusBarItem: vscode.StatusBarItem; export function activate(context: vscode.ExtensionContext) { - const miseService = new MiseService(); - - const tasksProvider = new MiseTasksProvider(miseService); - const toolsProvider = new MiseToolsProvider(miseService); - const envsProvider = new MiseEnvsProvider(miseService); - - vscode.window.registerTreeDataProvider('miseTasksView', tasksProvider); - vscode.window.registerTreeDataProvider('miseToolsView', toolsProvider); - vscode.window.registerTreeDataProvider('miseEnvsView', envsProvider); - - statusBarItem = vscode.window.createStatusBarItem(vscode.StatusBarAlignment.Right, 100); - statusBarItem.text = "$(tools) Mise"; - statusBarItem.tooltip = "Click to refresh Mise views"; - statusBarItem.command = 'mise.refreshEntry'; - statusBarItem.show(); - - context.subscriptions.push(statusBarItem); - - // Update status bar on refresh - context.subscriptions.push( - vscode.commands.registerCommand('mise.refreshEntry', async () => { - statusBarItem.text = "$(sync~spin) Mise"; - try { - await Promise.allSettled([ - tasksProvider.refresh(), - toolsProvider.refresh(), - envsProvider.refresh() - ]); - statusBarItem.text = "$(check) Mise"; - setTimeout(() => { - statusBarItem.text = "$(tools) Mise"; - }, 2000); - } catch (error) { - statusBarItem.text = "$(error) Mise"; - vscode.window.showErrorMessage(`Failed to refresh Mise views: ${error}`); - } - }) - ); + const miseService = new MiseService(); + + const tasksProvider = new MiseTasksProvider(miseService); + const toolsProvider = new MiseToolsProvider(miseService); + const envsProvider = new MiseEnvsProvider(miseService); + + statusBarItem = vscode.window.createStatusBarItem( + vscode.StatusBarAlignment.Right, + 100, + ); + statusBarItem.show(); + statusBarItem.text = "$(tools) Mise"; + statusBarItem.tooltip = "Click to refresh Mise views"; + + vscode.window.registerTreeDataProvider("miseTasksView", tasksProvider); + vscode.window.registerTreeDataProvider("miseToolsView", toolsProvider); + vscode.window.registerTreeDataProvider("miseEnvsView", envsProvider); + + statusBarItem.command = "mise.refreshEntry"; + statusBarItem.show(); + + context.subscriptions.push(statusBarItem); + + context.subscriptions.push( + vscode.commands.registerCommand("mise.refreshEntry", async () => { + await vscode.commands.executeCommand( + "workbench.view.extension.mise-panel", + ); + + statusBarItem.text = "$(sync~spin) Mise"; + try { + statusBarItem.text = "$(check) Mise"; + tasksProvider.refresh(); + toolsProvider.refresh(); + envsProvider.refresh(); + statusBarItem.text = "$(tools) Mise"; + } catch (error) { + statusBarItem.text = "$(error) Mise"; + vscode.window.showErrorMessage( + `Failed to refresh Mise views: ${error}`, + ); + } + }), + ); } -export function deactivate() {} \ No newline at end of file +export function deactivate() { + if (statusBarItem) { + statusBarItem.dispose(); + } +} diff --git a/src/miseService.ts b/src/miseService.ts index 860dcd0..84892af 100644 --- a/src/miseService.ts +++ b/src/miseService.ts @@ -1,68 +1,66 @@ -import {exec} from "child_process"; -import {promisify} from "util"; -import {logger} from "./utils/logger"; +import { exec } from "node:child_process"; +import { promisify } from "node:util"; import * as vscode from "vscode"; +import { logger } from "./utils/logger"; const execAsync = promisify(exec); export class MiseService { - async getTasks(): Promise { - try { - const {stdout} = await execAsync("mise tasks ls --json", { - cwd: vscode.workspace.rootPath, - }); - return JSON.parse(stdout).map((task: any) => - ({ - name: task.name, - source: task.source, - description: task.description, - }) - ); - } catch (error: Error | any) { - logger.error("Error fetching mise tasks:", error); - return []; - } - } + async getTasks(): Promise { + try { + const { stdout } = await execAsync("mise tasks ls --json", { + cwd: vscode.workspace.rootPath, + }); + return JSON.parse(stdout).map((task: MiseTask) => ({ + name: task.name, + source: task.source, + description: task.description, + })); + } catch (error: unknown) { + logger.error("Error fetching mise tasks:", error as Error); + return []; + } + } - async getTools(): Promise> { - logger.info("Executing mise ls 4 command"); + async getTools(): Promise> { + logger.info("Executing mise ls 4 command"); - try { - const {stdout} = await execAsync("mise ls --current --offline --json", { - cwd: vscode.workspace.rootPath, - }); - logger.info("Got stdout from mise ls 4 command " + stdout); - return Object.entries(JSON.parse(stdout)).flatMap(([toolName, tools]) => { - return (tools as any[]).map((tool: any) => { - return { - name: toolName, - version: tool.version, - requested_version: tool.requested_version, - active: tool.active, - installed: tool.installed, - install_path: tool.install_path, - } satisfies MiseTool; - }); - }); - } catch (error: Error | any) { - logger.error("Error fetching mise tools:", error); - return []; - } - } + try { + const { stdout } = await execAsync("mise ls --current --offline --json", { + cwd: vscode.workspace.rootPath, + }); + logger.info(`Got stdout from mise ls 4 command ${stdout}`); + return Object.entries(JSON.parse(stdout)).flatMap(([toolName, tools]) => { + return (tools as MiseTool[]).map((tool) => { + return { + name: toolName, + version: tool.version, + requested_version: tool.requested_version, + active: tool.active, + installed: tool.installed, + install_path: tool.install_path, + } satisfies MiseTool; + }); + }); + } catch (error) { + logger.error("Error fetching mise tools:", error as Error); + return []; + } + } - async getEnvs(): Promise { - try { - const {stdout} = await execAsync("mise env --json", { - cwd: vscode.workspace.rootPath, - }); - return Object.entries(JSON.parse(stdout)).map(([key, value]: any) => - ({ - name: key, value: value, - }) - ); - } catch (error: Error | any) { - logger.error("Error fetching mise environments:", error); - return []; - } - } + async getEnvs(): Promise { + try { + const { stdout } = await execAsync("mise env --json", { + cwd: vscode.workspace.rootPath, + }); + + return Object.entries(JSON.parse(stdout)).map(([key, value]) => ({ + name: key, + value: value as string, + })); + } catch (error) { + logger.error("Error fetching mise environments:", error as Error); + return []; + } + } } diff --git a/src/providers/envProvider.ts b/src/providers/envProvider.ts index af0995c..6355538 100644 --- a/src/providers/envProvider.ts +++ b/src/providers/envProvider.ts @@ -1,29 +1,33 @@ -import * as vscode from 'vscode'; -import { MiseService } from '../miseService'; +import * as vscode from "vscode"; +import type { MiseService } from "../miseService"; export class MiseEnvsProvider implements vscode.TreeDataProvider { - private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); - readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; + private _onDidChangeTreeData: vscode.EventEmitter< + void | EnvItem | null | undefined + > = new vscode.EventEmitter(); + readonly onDidChangeTreeData: vscode.Event< + EnvItem | undefined | null | void + > = this._onDidChangeTreeData.event; - constructor(private miseService: MiseService) {} + constructor(private miseService: MiseService) {} - refresh(): void { - this._onDidChangeTreeData.fire(); - } + refresh(): void { + this._onDidChangeTreeData.fire(); + } - getTreeItem(element: EnvItem): vscode.TreeItem { - return element; - } + getTreeItem(element: EnvItem): vscode.TreeItem { + return element; + } - async getChildren(): Promise { - const envs = await this.miseService.getEnvs(); - return envs.map(env => new EnvItem(env)); - } + async getChildren(): Promise { + const envs = await this.miseService.getEnvs(); + return envs.map((env) => new EnvItem(env)); + } } class EnvItem extends vscode.TreeItem { - constructor(env: MiseEnv) { - const label = env.value ? `${env.name}=${env.value}` : env.name; - super(label, vscode.TreeItemCollapsibleState.None); - } -} \ No newline at end of file + constructor(env: MiseEnv) { + const label = env.value ? `${env.name}=${env.value}` : env.name; + super(label, vscode.TreeItemCollapsibleState.None); + } +} diff --git a/src/providers/tasksProvider.ts b/src/providers/tasksProvider.ts index 05c3368..f151a9f 100644 --- a/src/providers/tasksProvider.ts +++ b/src/providers/tasksProvider.ts @@ -1,29 +1,33 @@ -import * as vscode from 'vscode'; -import { MiseService } from '../miseService'; +import * as vscode from "vscode"; +import type { MiseService } from "../miseService"; export class MiseTasksProvider implements vscode.TreeDataProvider { - private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); - readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; + private _onDidChangeTreeData: vscode.EventEmitter< + TaskItem | undefined | null | void + > = new vscode.EventEmitter(); + readonly onDidChangeTreeData: vscode.Event< + TaskItem | undefined | null | void + > = this._onDidChangeTreeData.event; - constructor(private miseService: MiseService) {} + constructor(private miseService: MiseService) {} - refresh(): void { - this._onDidChangeTreeData.fire(); - } + refresh(): void { + this._onDidChangeTreeData.fire(); + } - getTreeItem(element: TaskItem): vscode.TreeItem { - return element; - } + getTreeItem(element: TaskItem): vscode.TreeItem { + return element; + } - async getChildren(): Promise { - const tasks = await this.miseService.getTasks(); - return tasks.map(task => new TaskItem(task)); - } + async getChildren(): Promise { + const tasks = await this.miseService.getTasks(); + return tasks.map((task) => new TaskItem(task)); + } } class TaskItem extends vscode.TreeItem { - constructor(task: MiseTask) { - super(task.name, vscode.TreeItemCollapsibleState.None); - this.tooltip = `Task: ${task.name}\nSource: ${task.source}\nDescription: ${task.description}`; - } + constructor(task: MiseTask) { + super(task.name, vscode.TreeItemCollapsibleState.None); + this.tooltip = `Task: ${task.name}\nSource: ${task.source}\nDescription: ${task.description}`; + } } diff --git a/src/providers/toolsProvider.ts b/src/providers/toolsProvider.ts index f61800e..041c959 100644 --- a/src/providers/toolsProvider.ts +++ b/src/providers/toolsProvider.ts @@ -1,34 +1,38 @@ -import * as vscode from 'vscode'; -import { MiseService } from '../miseService'; +import * as vscode from "vscode"; +import type { MiseService } from "../miseService"; export class MiseToolsProvider implements vscode.TreeDataProvider { - private _onDidChangeTreeData: vscode.EventEmitter = new vscode.EventEmitter(); - readonly onDidChangeTreeData: vscode.Event = this._onDidChangeTreeData.event; + private _onDidChangeTreeData: vscode.EventEmitter< + ToolItem | undefined | null | void + > = new vscode.EventEmitter(); + readonly onDidChangeTreeData: vscode.Event< + ToolItem | undefined | null | void + > = this._onDidChangeTreeData.event; - constructor(private miseService: MiseService) {} + constructor(private miseService: MiseService) {} - refresh(): void { - this._onDidChangeTreeData.fire(); - } + refresh(): void { + this._onDidChangeTreeData.fire(); + } - getTreeItem(element: ToolItem): vscode.TreeItem { - return element; - } + getTreeItem(element: ToolItem): vscode.TreeItem { + return element; + } - async getChildren(): Promise { - const tools = await this.miseService.getTools(); - return tools.map(tool => new ToolItem(tool)); - } + async getChildren(): Promise { + const tools = await this.miseService.getTools(); + return tools.map((tool) => new ToolItem(tool)); + } } class ToolItem extends vscode.TreeItem { - constructor(tool: MiseTool) { - super(`${tool.name} ${tool.version}`, vscode.TreeItemCollapsibleState.None); - this.tooltip = `Tool: ${tool.name} + constructor(tool: MiseTool) { + super(`${tool.name} ${tool.version}`, vscode.TreeItemCollapsibleState.None); + this.tooltip = `Tool: ${tool.name} Version: ${tool.version} Requested Version: ${tool.requested_version} Activated: ${tool.active} Installed: ${tool.installed} Install Path: ${tool.install_path}`; - } -} \ No newline at end of file + } +} diff --git a/src/types.ts b/src/types.ts index 05f5b78..025697d 100644 --- a/src/types.ts +++ b/src/types.ts @@ -1,19 +1,19 @@ type MiseTask = { - name: string; - source: string; - description: string; + name: string; + source: string; + description: string; }; type MiseTool = { - name: string; - version: string; - requested_version: string; - installed: boolean; - active: boolean; - install_path: string; + name: string; + version: string; + requested_version: string; + installed: boolean; + active: boolean; + install_path: string; }; type MiseEnv = { - name: string; - value: string; -}; \ No newline at end of file + name: string; + value: string; +}; diff --git a/src/utils/logger.ts b/src/utils/logger.ts index 14d6bef..1a5e5b7 100644 --- a/src/utils/logger.ts +++ b/src/utils/logger.ts @@ -1,106 +1,110 @@ -import * as vscode from 'vscode'; +import * as vscode from "vscode"; export enum LogLevel { - // eslint-disable-next-line @typescript-eslint/naming-convention - DEBUG = 0, - INFO = 1, - WARN = 2, - ERROR = 3 + DEBUG = 0, + INFO = 1, + WARN = 2, + ERROR = 3, } export class Logger { - private static instance: Logger; - private outputChannel: vscode.OutputChannel; - private logLevel: LogLevel; - - private constructor() { - this.outputChannel = vscode.window.createOutputChannel('Mise'); - this.logLevel = LogLevel.INFO; // Default log level - } - - public static getInstance(): Logger { - if (!Logger.instance) { - Logger.instance = new Logger(); - } - return Logger.instance; - } - - public setLogLevel(level: LogLevel) { - this.logLevel = level; - this.info(`Log level set to ${LogLevel[level]}`); - } - - private formatMessage(level: string, message: string): string { - const timestamp = new Date().toISOString(); - return `[${timestamp}] [${level}] ${message}`; - } - - private shouldLog(level: LogLevel): boolean { - return level >= this.logLevel; - } - - private log(level: LogLevel, message: string, error?: Error) { - if (!this.shouldLog(level)) { - return; - } - - const formattedMessage = this.formatMessage(LogLevel[level], message); - this.outputChannel.appendLine(formattedMessage); - - if (error) { - this.outputChannel.appendLine(this.formatMessage(LogLevel[level], `Error Details: ${error.message}`)); - if (error.stack) { - this.outputChannel.appendLine(this.formatMessage(LogLevel[level], `Stack Trace: ${error.stack}`)); - } - } - - // Show in Problem panel for warnings and errors - if (level >= LogLevel.WARN) { - const severity = level === LogLevel.WARN ? - vscode.DiagnosticSeverity.Warning : - vscode.DiagnosticSeverity.Error; - - vscode.window.showErrorMessage(`Mise: ${message}`); - } - } - - public debug(message: string) { - this.log(LogLevel.DEBUG, message); - } - - public info(message: string) { - this.log(LogLevel.INFO, message); - } - - public warn(message: string) { - this.log(LogLevel.WARN, message); - } - - public error(message: string, error?: Error) { - this.log(LogLevel.ERROR, message, error); - } - - public group(title: string) { - if (!this.shouldLog(LogLevel.DEBUG)) { - return; - } - this.outputChannel.appendLine(`\n▼ ${title}`); - } - - public groupEnd() { - if (!this.shouldLog(LogLevel.DEBUG)) { - return; - } - this.outputChannel.appendLine('▲ End\n'); - } - - public show() { - this.outputChannel.show(); - } - - public dispose() { - this.outputChannel.dispose(); - } + private static instance: Logger; + private outputChannel: vscode.OutputChannel; + private logLevel: LogLevel; + + private constructor() { + this.outputChannel = vscode.window.createOutputChannel("Mise"); + this.logLevel = LogLevel.INFO; // Default log level + } + + public static getInstance(): Logger { + if (!Logger.instance) { + Logger.instance = new Logger(); + } + return Logger.instance; + } + + public setLogLevel(level: LogLevel) { + this.logLevel = level; + this.info(`Log level set to ${LogLevel[level]}`); + } + + private formatMessage(level: string, message: string): string { + const timestamp = new Date().toISOString(); + return `[${timestamp}] [${level}] ${message}`; + } + + private shouldLog(level: LogLevel): boolean { + return level >= this.logLevel; + } + + private log(level: LogLevel, message: string, error?: Error) { + if (!this.shouldLog(level)) { + return; + } + + const formattedMessage = this.formatMessage(LogLevel[level], message); + this.outputChannel.appendLine(formattedMessage); + + if (error) { + this.outputChannel.appendLine( + this.formatMessage(LogLevel[level], `Error Details: ${error.message}`), + ); + if (error.stack) { + this.outputChannel.appendLine( + this.formatMessage(LogLevel[level], `Stack Trace: ${error.stack}`), + ); + } + } + + // Show in Problem panel for warnings and errors + if (level >= LogLevel.WARN) { + const severity = + level === LogLevel.WARN + ? vscode.DiagnosticSeverity.Warning + : vscode.DiagnosticSeverity.Error; + + vscode.window.showErrorMessage(`Mise: ${message}`); + } + } + + public debug(message: string) { + this.log(LogLevel.DEBUG, message); + } + + public info(message: string) { + this.log(LogLevel.INFO, message); + } + + public warn(message: string) { + this.log(LogLevel.WARN, message); + } + + public error(message: string, error?: Error) { + this.log(LogLevel.ERROR, message, error); + } + + public group(title: string) { + if (!this.shouldLog(LogLevel.DEBUG)) { + return; + } + this.outputChannel.appendLine(`\n▼ ${title}`); + } + + public groupEnd() { + if (!this.shouldLog(LogLevel.DEBUG)) { + return; + } + this.outputChannel.appendLine("▲ End\n"); + } + + public show() { + this.outputChannel.show(); + } + + public dispose() { + this.outputChannel.dispose(); + } } -export const logger = Logger.getInstance(); \ No newline at end of file +export const logger = Logger.getInstance(); diff --git a/tsconfig.json b/tsconfig.json index 373ad38..40df4ee 100644 --- a/tsconfig.json +++ b/tsconfig.json @@ -1,12 +1,12 @@ { - "compilerOptions": { - "module": "commonjs", - "target": "ES2020", - "outDir": "out", - "lib": ["ES2020"], - "sourceMap": true, - "rootDir": "src", - "strict": true - }, - "exclude": ["node_modules", ".vscode-test"] -} \ No newline at end of file + "compilerOptions": { + "module": "commonjs", + "target": "ES2020", + "outDir": "out", + "lib": ["ES2020"], + "sourceMap": true, + "rootDir": "src", + "strict": true + }, + "exclude": ["node_modules", ".vscode-test"] +} diff --git a/webpack.config.js b/webpack.config.js index 6482792..23e4353 100644 --- a/webpack.config.js +++ b/webpack.config.js @@ -1,46 +1,45 @@ -// webpack.config.js -const path = require('path'); +const path = require("node:pathpath"); /** @type {import('webpack').Configuration} */ module.exports = { - target: 'node', - mode: 'development', // Set to 'none' for production - entry: './src/extension.ts', - output: { - path: path.resolve(__dirname, 'dist'), - filename: 'extension.js', - libraryTarget: 'commonjs2', - devtoolModuleFilenameTemplate: '../[resource-path]' - }, - devtool: 'source-map', - externals: { - vscode: 'commonjs vscode' - }, - resolve: { - extensions: ['.ts', '.js'] - }, - module: { - rules: [ - { - test: /\.ts$/, - exclude: /node_modules/, - use: [ - { - loader: 'ts-loader', - options: { - transpileOnly: true, // Faster builds with some type checking sacrifice - experimentalWatchApi: true, - } - } - ] - } - ] - }, - watchOptions: { - // Don't watch node_modules to reduce CPU usage - ignored: /node_modules/, - // Reduce polling interval for better performance - aggregateTimeout: 300, - poll: 1000 - } -}; \ No newline at end of file + target: "node", + mode: "development", // Set to 'none' for production + entry: "./src/extension.ts", + output: { + path: path.resolve(__dirname, "dist"), + filename: "extension.js", + libraryTarget: "commonjs2", + devtoolModuleFilenameTemplate: "../[resource-path]", + }, + devtool: "source-map", + externals: { + vscode: "commonjs vscode", + }, + resolve: { + extensions: [".ts", ".js"], + }, + module: { + rules: [ + { + test: /\.ts$/, + exclude: /node_modules/, + use: [ + { + loader: "ts-loader", + options: { + transpileOnly: true, // Faster builds with some type checking sacrifice + experimentalWatchApi: true, + }, + }, + ], + }, + ], + }, + watchOptions: { + // Don't watch node_modules to reduce CPU usage + ignored: /node_modules/, + // Reduce polling interval for better performance + aggregateTimeout: 300, + poll: 1000, + }, +};