Skip to content

Commit

Permalink
fix: vscode plugin get commit hash bug
Browse files Browse the repository at this point in the history
  • Loading branch information
stanimirovv committed Dec 12, 2023
1 parent 962633b commit 4fc82ae
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -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",
Expand Down
4 changes: 3 additions & 1 deletion src/explorer/explorer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand All @@ -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) {
Expand Down
5 changes: 3 additions & 2 deletions src/explorer/getCommitHash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ import { promisify } from 'util'

const exec = promisify(execCallback)

export async function getCommitHash (): Promise<string> {
export async function getCommitHash (cwd: string): Promise<string> {
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'
Expand Down

0 comments on commit 4fc82ae

Please sign in to comment.