Skip to content

Commit

Permalink
Merge pull request #134 from nick22985/advanced-probelm-config
Browse files Browse the repository at this point in the history
Advanced problem config
  • Loading branch information
xhayper authored Oct 31, 2022
2 parents 8e8748d + 5b3d06c commit fa6d701
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 12 deletions.
4 changes: 4 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,10 @@ The following variables will be replaced with the respective value in custom str
| `{lang}` \| `{Lang}` \| `{LANG}` | format of the lang string (css, Css, CSS) |
| `{problems}` | problems text defined in settings |
| `{problems_count}` | number of problems |
| `{problems_count_errors}` | number of problems that are errors |
| `{problems_count_warnings}` | number of problems that are warnings |
| `{problems_count_infos}` | number of problems that are infos |
| `{problems_count_hints}` | number of problems that are hints |
| `{line_count}` | number of lines |
| `{current_line}` | current line |
| `{current_column}` | current column |
Expand Down
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,11 @@
"default": "- {problems_count} problems found",
"description": "The text to show in the status when there are problems. {problems_count} will be replaced with the number of problems."
},
"vscord.status.problems.countedSeverities": {
"type": "array",
"default": ["error", "warnings"],
"description": "Choose the log level of problem_count if it should have errors, warnings, info or hints. Include all values you want to show in the array [\"error\", \"warnings\", \"infos\", \"hints\"]"
},
"vscord.status.idle.check": {
"type": "boolean",
"default": true,
Expand Down
67 changes: 56 additions & 11 deletions src/activity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,21 +16,38 @@ export enum CURRENT_STATUS {
VIEWING = "viewing"
}

// TODO: move this to data class
export let totalProblems = 0;

// TODO: make this configurable
const COUNTED_SEVERITIES = [DiagnosticSeverity.Error, DiagnosticSeverity.Warning];
interface PROBLEM_LEVELS {
errors: number;
warnings: number;
infos: number;
hints: number;
}

// TODO: move this to data class
const COUNTED_SEVERITIES: PROBLEM_LEVELS = {
errors: 0,
warnings: 0,
infos: 0,
hints: 0
}
export const onDiagnosticsChange = () => {
const diagnostics = languages.getDiagnostics();
const counted = 0;
let errors = 0;
let warnings = 0;
let infos = 0;
let hints = 0;

for (const diagnostic of diagnostics.values())
for (const diagnosticItem of diagnostic[1])
if (COUNTED_SEVERITIES.includes(diagnosticItem.severity)) totalProblems++;

totalProblems = counted;
for (const diagnosticItem of diagnostic[1]) {
if (diagnosticItem.severity == DiagnosticSeverity.Error) errors++;
if (diagnosticItem.severity == DiagnosticSeverity.Warning) warnings++;
if (diagnosticItem.severity == DiagnosticSeverity.Information) infos++;
if (diagnosticItem.severity == DiagnosticSeverity.Hint) hints++;
}
COUNTED_SEVERITIES.errors = errors;
COUNTED_SEVERITIES.warnings = warnings;
COUNTED_SEVERITIES.infos = infos;
COUNTED_SEVERITIES.hints = hints;
};

export const activity = async (
Expand Down Expand Up @@ -260,6 +277,18 @@ export const replaceGitInfo = (text: string, excluded = false): string => {
return text;
};

export const getTotalProblems = (countedSeverities: Array<string>): number => {
let totalProblems = 0;
countedSeverities.forEach(severity => {
const logLevel = severity.toLowerCase()
if (logLevel === 'errors') totalProblems += COUNTED_SEVERITIES.errors;
if (logLevel === 'warnings') totalProblems += COUNTED_SEVERITIES.warnings;
if (logLevel === 'infos') totalProblems += COUNTED_SEVERITIES.infos;
if (logLevel === 'hints') totalProblems += COUNTED_SEVERITIES.hints;
});
return totalProblems;
}

export const replaceFileInfo = async (
text: string,
excluded = false,
Expand Down Expand Up @@ -308,7 +337,23 @@ export const replaceFileInfo = async (
["{LANG}", toUpper(fileIcon)],
[
"{problems_count}",
config.get(CONFIG_KEYS.Status.Problems.Enabled) ? totalProblems.toLocaleString() : FAKE_EMPTY
config.get(CONFIG_KEYS.Status.Problems.Enabled) ? getTotalProblems(config.get(CONFIG_KEYS.Status.Problems.countedSeverities)).toLocaleString() : FAKE_EMPTY
],
[
"{problems_count_errors}",
COUNTED_SEVERITIES.errors.toLocaleString()
],
[
"{problems_count_warnings}",
COUNTED_SEVERITIES.warnings.toLocaleString()
],
[
"{problems_count_infos}",
COUNTED_SEVERITIES.infos.toLocaleString()
],
[
"{problems_count_hints}",
COUNTED_SEVERITIES.hints.toLocaleString()
],
["{line_count}", document?.lineCount.toLocaleString() ?? FAKE_EMPTY],
["{current_line}", selection ? (selection.active.line + 1).toLocaleString() : FAKE_EMPTY],
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ export interface ExtenstionConfigTyping {
"status.image.problems.text": string;
"status.problems.enabled": boolean;
"status.problems.text": string;
"status.problems.countedSeverities": Array<string>
"status.idle.check": boolean;
"status.idle.disconnectOnIdle": boolean;
"status.idle.resetElapsedTime": boolean;
Expand Down
3 changes: 2 additions & 1 deletion src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,8 @@ export const CONFIG_KEYS = {
} as const,
Problems: {
Enabled: "status.problems.enabled" as const,
Text: "status.problems.text" as const
Text: "status.problems.text" as const,
countedSeverities: "status.problems.countedSeverities" as const
} as const,
Idle: {
Check: "status.idle.check" as const,
Expand Down

0 comments on commit fa6d701

Please sign in to comment.