From 95bba8b12bd75c5690061abe4e6a6bd176f8000e Mon Sep 17 00:00:00 2001 From: Nate Date: Sun, 30 Mar 2025 22:34:43 -0700 Subject: [PATCH] format --- .../providers/GitCommitContextProvider.ts | 94 +++++++++++-------- 1 file changed, 57 insertions(+), 37 deletions(-) diff --git a/core/context/providers/GitCommitContextProvider.ts b/core/context/providers/GitCommitContextProvider.ts index 24d2eab7b..e57b50c86 100644 --- a/core/context/providers/GitCommitContextProvider.ts +++ b/core/context/providers/GitCommitContextProvider.ts @@ -1,12 +1,12 @@ +import { fileURLToPath } from "node:url"; import { - ContextItem, - ContextProviderDescription, - ContextProviderExtras, - ContextSubmenuItem, - LoadSubmenuItemsArgs, - } from "../../index.js"; + ContextItem, + ContextProviderDescription, + ContextProviderExtras, + ContextSubmenuItem, + LoadSubmenuItemsArgs, +} from "../../index.js"; import { BaseContextProvider } from "../index.js"; -import { fileURLToPath} from "node:url"; class GitCommitContextProvider extends BaseContextProvider { static description: ContextProviderDescription = { @@ -16,29 +16,41 @@ class GitCommitContextProvider extends BaseContextProvider { type: "submenu", }; - async getContextItems(query: string, extras: ContextProviderExtras): Promise { + async getContextItems( + query: string, + extras: ContextProviderExtras, + ): Promise { const lastXCommitsDepth = this.options?.LastXCommitsDepth ?? 10; const topLevelDir = fileURLToPath((await extras.ide.getWorkspaceDirs())[0]); - try{ - if(query.includes("last ")){ + try { + if (query.includes("last ")) { return [ { - name: query, - description: query, - content: (await extras.ide.subprocess(`git --no-pager log --pretty=format:"%H,%h,%an,%ae,%ad,%P,%s,%b" -p -n ${lastXCommitsDepth}`, topLevelDir))[0], - } - ] - } - else{ + name: query, + description: query, + content: ( + await extras.ide.subprocess( + `git --no-pager log --pretty=format:"%H,%h,%an,%ae,%ad,%P,%s,%b" -p -n ${lastXCommitsDepth}`, + topLevelDir, + ) + )[0], + }, + ]; + } else { return [ { name: query, description: `commit ${query}`, - content: (await extras.ide.subprocess(`git --no-pager show --pretty=format:"%H,%h,%an,%ae,%ad,%P,%s,%b" ${query}`, topLevelDir))[0], - } - ] + content: ( + await extras.ide.subprocess( + `git --no-pager show --pretty=format:"%H,%h,%an,%ae,%ad,%P,%s,%b" ${query}`, + topLevelDir, + ) + )[0], + }, + ]; } - }catch(err){ + } catch (err) { return []; } } @@ -48,24 +60,32 @@ class GitCommitContextProvider extends BaseContextProvider { ): Promise { const depth = this.options?.Depth ?? 50; const lastXCommitsDepth = this.options?.LastXCommitsDepth ?? 10; - const topLevelDir = fileURLToPath((await args.ide.getWorkspaceDirs())[0]); - try{ - const [gitResult] = await args.ide.subprocess(`git --no-pager log --pretty=format:"%H%x00%s" -n ${depth}`, topLevelDir); - const recentCommits = [{ id: `last ${lastXCommitsDepth} commits`, title: `last ${lastXCommitsDepth} commits`, description: "recent commits" }]; - const allCommits = gitResult - .trim() - .split('\n') - .map(line => { - const [hash, message] = line.split("\0"); - return { - id: hash, - title: message, - description: hash - }; - } + const topLevelDir = fileURLToPath((await args.ide.getWorkspaceDirs())[0]); + try { + const [gitResult] = await args.ide.subprocess( + `git --no-pager log --pretty=format:"%H%x00%s" -n ${depth}`, + topLevelDir, ); + const recentCommits = [ + { + id: `last ${lastXCommitsDepth} commits`, + title: `last ${lastXCommitsDepth} commits`, + description: "recent commits", + }, + ]; + const allCommits = gitResult + .trim() + .split("\n") + .map((line) => { + const [hash, message] = line.split("\0"); + return { + id: hash, + title: message, + description: hash, + }; + }); return recentCommits.concat(allCommits); - }catch(err: any){ + } catch (err: any) { //could be nice to toast the error eg. not a git repo or git is not installed return []; }