Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow Setting Detection Delay #14

Merged
merged 9 commits into from
Jun 14, 2023
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,17 @@
"type": "string",
"default": null,
"markdownDescription": "A glob targeting some uncompressed sounds files (`.wav` etc.). Leave blank for built-in voice lines. \nRestart required."
}
},
"hotheadedVSCode.cooldownDurationMin": {
"type": "number",
"default": 0,
"description": "Minimum cooldown duration in milliseconds."
},
"hotheadedVSCode.cooldownDurationMax": {
"type": "number",
"default": 0,
"description": "Maximum cooldown duration in milliseconds."
}
}
}
},
Expand All @@ -54,4 +64,4 @@
"glob": "^7.1.6",
"speaker": "^0.5.2"
}
}
}
33 changes: 29 additions & 4 deletions src/ErrorTracker.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
import { DiagnosticChangeEvent, Uri, Diagnostic, window, languages, DiagnosticSeverity, Range, TextDocument, Position, TextEditor } from "vscode";
import { DiagnosticChangeEvent, Uri, Diagnostic, window, workspace, languages, DiagnosticSeverity, Range, TextDocument, Position, TextEditor } from "vscode";
import { bash } from "./Basher";

let cooldownTimer: NodeJS.Timeout | null = null;

export function OnDidChangeDiagnostics(e: DiagnosticChangeEvent): void {
const activeTextEditor = window.activeTextEditor;
if (
Expand All @@ -9,20 +11,43 @@ export function OnDidChangeDiagnostics(e: DiagnosticChangeEvent): void {
const errors = errorsForFile(activeTextEditor, activeTextEditor.document.uri);
if (errors.length > 0) {
if (errors.filter((d) => !sameAsPrevious(d)).length > 0) {
console.log(errors);
bash();
setPreviousError(errors[0]);
console.log("Error: ", errors);
if (cooldownTimer === null) {
bash();
setPreviousError(errors[0]);
const cooldownDuration = getRandomCooldownDuration();
console.log(cooldownDuration);
cooldownTimer = setTimeout(() => {
cooldownTimer = null;
}, cooldownDuration);
}
}
} else {
console.log("No errors");
clearPreviousError();
}
}
}

function getRandomCooldownDuration(): number {
const minDuration = workspace
.getConfiguration("hotheadedVSCode")
.get<number>("cooldownDurationMin") as number;
const maxDuration = workspace
.getConfiguration("hotheadedVSCode")
.get<number>("cooldownDurationMax") as number;

const randomDuration = Math.floor(
Math.random() * (maxDuration - minDuration + 1) + minDuration
);
return randomDuration;
}

function errorsForFile(editor: TextEditor, fileUri: Uri): Array<Diagnostic> {
return languages
.getDiagnostics(fileUri)
.filter(d => d.severity === DiagnosticSeverity.Error && isErrorCurrent(editor, d));

89netraM marked this conversation as resolved.
Show resolved Hide resolved
}

function textBetween(document: TextDocument, cursor: Position, error: Range): string {
Expand Down