-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* first working code * WIP: 10ba35b docs(changelog): update release notes * settings * tests * Merge branch 'vorpal-engine-extention' of https://github.com/Checkmarx/ast-vscode-extension into vorpal-engine-extention * delete problems when disabled vorpal * test * tests * tests * test * test * ignore log files * ignore settings.json windows * tests * fix tests * tests * onDidChangeActiveTextEditor * tests * log settings * fix tests * tests * fixes * fix * Update launch.json * Update package.json * ignore system files * tests * test name * try * revert * Update launch.json * try * fix * remove test * order * fix mock * vorpal tests * try import again * clear tests * fix test mock * setting name without space * timeout * fix the test * beezrat hashem * vorpal test * settings test * add test * test * test cases * code review * await * latest wrapper and settings descreption * formmater * change log.err to log.warn in scan vorpal * support Critical severities * Update extension.ts * Delete src/test/9.vorpal.test.ts * code review --------- Co-authored-by: AlvoBen <[email protected]>
- Loading branch information
1 parent
539bb51
commit 8005f82
Showing
13 changed files
with
366 additions
and
26 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,80 @@ | ||
import * as vscode from "vscode"; | ||
import { Logs } from "../models/logs"; | ||
import { | ||
clearVorpalProblems, | ||
installVorpal, | ||
scanVorpal, | ||
} from "../vorpal/vorpalService"; | ||
import { constants } from "../utils/common/constants"; | ||
|
||
let timeout = null; | ||
export class VorpalCommand { | ||
context: vscode.ExtensionContext; | ||
logs: Logs; | ||
onDidChangeTextDocument: vscode.Disposable; | ||
constructor(context: vscode.ExtensionContext, logs: Logs) { | ||
this.context = context; | ||
this.logs = logs; | ||
} | ||
public async registerVorpal() { | ||
try { | ||
const vorpalActive = vscode.workspace | ||
.getConfiguration(constants.CheckmarxVorpal) | ||
.get(constants.ActivateVorpalAutoScanning) as boolean; | ||
if (vorpalActive) { | ||
await this.installVorpal(); | ||
await this.registerVorpalScanOnChangeText(); | ||
this.logs.info(constants.vorpalStart); | ||
} else { | ||
await this.disposeVorpalScanOnChangeText(); | ||
await clearVorpalProblems(); | ||
this.logs.info(constants.vorpalDisabled); | ||
} | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
} | ||
public installVorpal() { | ||
installVorpal(this.logs); | ||
this.onDidChangeTextDocument = vscode.workspace.onDidChangeTextDocument( | ||
// Must be no less than 2000ms. Otherwise, the temporary file can be deleted before the vorpal scan is finished. | ||
this.debounce(this.onTextChange, 2000) | ||
); | ||
} | ||
|
||
public onTextChange(event) { | ||
try { | ||
scanVorpal(event.document, this.logs); | ||
} catch (error) { | ||
console.error(error); | ||
this.logs.warn("fail to scan vorpal"); | ||
} | ||
} | ||
// Debounce function | ||
public debounce(func, wait) { | ||
const context = this; | ||
console.log("onDidChangeTextDocument"); | ||
return function (...args) { | ||
try { | ||
const later = () => { | ||
clearTimeout(timeout); | ||
func.apply(context, args); | ||
}; | ||
clearTimeout(timeout); | ||
timeout = setTimeout(later, wait); | ||
} catch (error) { | ||
console.error(error); | ||
} | ||
}; | ||
} | ||
|
||
public registerVorpalScanOnChangeText() { | ||
this.context.subscriptions.push(this.onDidChangeTextDocument); | ||
} | ||
public disposeVorpalScanOnChangeText() { | ||
if (this.onDidChangeTextDocument) { | ||
this.onDidChangeTextDocument.dispose(); | ||
this.context.subscriptions.push(this.onDidChangeTextDocument); | ||
} | ||
} | ||
} |
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
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
Oops, something went wrong.