forked from waderyan/vscode-gitblame
-
Notifications
You must be signed in to change notification settings - Fork 32
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix multiple parallel blames and use vscode.git
- Loading branch information
Showing
8 changed files
with
88 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
export interface IVscodeGitExtension { | ||
git: IGitPath; | ||
} | ||
|
||
export interface IGitPath { | ||
path: string; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,21 @@ | ||
import { access, constants as FSConstant } from "fs"; | ||
import { normalize } from "path"; | ||
|
||
import { workspace } from "vscode"; | ||
import { extensions } from "vscode"; | ||
|
||
import { GIT_COMMAND_IN_PATH } from "../constants"; | ||
import { ErrorHandler } from "./errorhandler"; | ||
|
||
export function getGitCommand(): Promise<string> { | ||
const gitConfig = workspace.getConfiguration("git"); | ||
const pathCommand = gitConfig.get("path") as string; | ||
const promise = new Promise<string>((resolve, reject) => { | ||
if (!pathCommand) { | ||
resolve(GIT_COMMAND_IN_PATH); | ||
} | ||
|
||
const commandPath = normalize(pathCommand); | ||
import { IVscodeGitExtension } from "../git.api.interface"; | ||
|
||
access(commandPath, FSConstant.X_OK, (err) => { | ||
if (err) { | ||
ErrorHandler.logError( | ||
new Error( | ||
`Can not execute "${ | ||
commandPath | ||
}" (your git.path property) falling back to "${ | ||
GIT_COMMAND_IN_PATH | ||
}"`, | ||
), | ||
); | ||
resolve(GIT_COMMAND_IN_PATH); | ||
} else { | ||
resolve(commandPath); | ||
} | ||
}); | ||
}); | ||
export function getGitCommand(): string { | ||
const vscodeGit = extensions.getExtension<IVscodeGitExtension>( | ||
"vscode.git", | ||
); | ||
|
||
return promise; | ||
if ( | ||
vscodeGit | ||
&& vscodeGit.exports | ||
&& vscodeGit.exports.git | ||
&& vscodeGit.exports.git.path | ||
) { | ||
return vscodeGit.exports.git.path; | ||
} else { | ||
return GIT_COMMAND_IN_PATH; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
const cache: Set<symbol> = new Set(); | ||
|
||
/** | ||
* Throttle a function. It will ignore any calls to it in the | ||
* timeout time since it was last called successfully. | ||
* | ||
* @param timeout in milliseconds | ||
*/ | ||
export function throttleFunction(timeout: number): ( | ||
target: any, | ||
propertyKey: string, | ||
descriptor: TypedPropertyDescriptor<any>, | ||
) => void { | ||
return ( | ||
target: any, | ||
propertyKey: string, | ||
descriptor: TypedPropertyDescriptor<any>, | ||
) => { | ||
const oldMethod = descriptor.value; | ||
const identifier = Symbol(); | ||
|
||
descriptor.value = function(...args: any[]): void { | ||
if (!cache.has(identifier)) { | ||
oldMethod.call(this, args); | ||
cache.add(identifier); | ||
setTimeout(() => { | ||
cache.delete(identifier); | ||
}, timeout); | ||
} | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters