From 4fc82aeb07a7b2aefa2b405889040ff83d71a87f Mon Sep 17 00:00:00 2001 From: Zlatin Stanimirov Date: Tue, 12 Dec 2023 09:31:12 +0200 Subject: [PATCH] fix: vscode plugin get commit hash bug --- package.json | 2 +- src/explorer/explorer.ts | 4 +++- src/explorer/getCommitHash.ts | 5 +++-- 3 files changed, 7 insertions(+), 4 deletions(-) diff --git a/package.json b/package.json index 4bf6881..3a2f493 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "@stanimirovv/tsoogle", - "version": "1.5.1", + "version": "1.6.1", "description": "Find functions or methods by approximate signature - return type, argument types or both. Supports optional arguments, rest arguments and partial type checking.", "main": "dist/index.js", "bin": "dist/index.js", diff --git a/src/explorer/explorer.ts b/src/explorer/explorer.ts index 12203cb..257938e 100644 --- a/src/explorer/explorer.ts +++ b/src/explorer/explorer.ts @@ -2,6 +2,7 @@ import { type MethodDeclaration, type FunctionDeclaration, type ArrowFunction, P import { type ProjectFunction } from '../projectFunction.interface' import { getCommitHash } from './getCommitHash' import { doesDatabaseExist, initializeDatabase, getFunctionsFromDb, storeFunctionInDatabase } from './indexer' +import path from 'path' type tsMorphFunction = MethodDeclaration | FunctionDeclaration | ArrowFunction type FunctionFetcher = (sourceFile: SourceFile) => tsMorphFunction[] @@ -15,7 +16,8 @@ export async function getMethodsAndFunctions (kind: 'both' | 'function' | 'metho await initializeDatabase(tsconfigPath) } - const currentGitCommitId = await getCommitHash() + const tsConfigDir = path.dirname(tsconfigPath) + const currentGitCommitId = await getCommitHash(tsConfigDir) let functions = await getFunctionsFromDb(tsconfigPath, currentGitCommitId) if (functions.length === 0) { diff --git a/src/explorer/getCommitHash.ts b/src/explorer/getCommitHash.ts index 708409e..1568aac 100644 --- a/src/explorer/getCommitHash.ts +++ b/src/explorer/getCommitHash.ts @@ -3,9 +3,10 @@ import { promisify } from 'util' const exec = promisify(execCallback) -export async function getCommitHash (): Promise { +export async function getCommitHash (cwd: string): Promise { try { - const { stdout } = await exec('git rev-parse HEAD') + // NOTE: bellow is unsafe + const { stdout } = await exec(`cd ${cwd} && git rev-parse HEAD`) return stdout.trim() } catch (e) { return 'unknown'