Skip to content

Commit

Permalink
Made it so the error translator only translates errors, not low-prior…
Browse files Browse the repository at this point in the history
…ity messages like unused variables.
  • Loading branch information
mattpocock committed Aug 17, 2023
1 parent 1d09c62 commit 2279946
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 25 deletions.
5 changes: 5 additions & 0 deletions .changeset/slow-peaches-teach.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
'ts-error-translator': minor
---

Made it so the error translator only translates errors, not low-priority messages like unused variables.
18 changes: 9 additions & 9 deletions apps/vscode/src/bundleErrors.json
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@
"code": "2314"
},
"2322": {
"body": "I was expecting a type matching A, but instead you passed B.\n",
"body": "I was expecting a type matching '{1}', but instead you passed '{0}'.\n",
"code": "2322"
},
"2324": {
Expand All @@ -76,7 +76,7 @@
"code": "2327"
},
"2339": {
"body": "You're trying to access '{0}' on an object that doesn't contain it. [Learn more.](https://totaltypescript.com)\n",
"body": "You're trying to access '{0}' on an object that doesn't contain it. [Learn more](https://totaltypescript.com/concepts/property-does-not-exist-on-type).\n",
"code": "2339"
},
"2344": {
Expand All @@ -96,7 +96,7 @@
"code": "2352"
},
"2353": {
"body": "You can't pass property '{0}' to object '{1}'.\n",
"body": "You can't pass property '{0}' to type '{1}'.\n",
"code": "2353"
},
"2355": {
Expand All @@ -112,7 +112,7 @@
"code": "2414"
},
"2451": {
"body": "'{0}' has already been declared - you can't declare it again.\n",
"body": "'{0}' has already been declared - you can't declare it again. [Learn more](https://www.totaltypescript.com/cannot-redeclare-block-scoped-variable).\n",
"code": "2451"
},
"2551": {
Expand All @@ -128,15 +128,15 @@
"code": "2554"
},
"2571": {
"body": "I don't know what type this object is.\n",
"body": "I don't know what type this object is, so I've defaulted it to 'unknown'. [Learn more](https://www.totaltypescript.com/concepts/object-is-of-type-unknown).\n",
"code": "2571"
},
"2590": {
"body": "You've created a union type that's too complex for me to handle! 🤯 I can only represent 100,000 combinations in the same union, and you've gone over that limit.\n",
"code": "2590"
},
"2741": {
"body": "You haven't passed all the required properties to '{2}' - '{1}' is missing the '{0}' property\n",
"body": "You haven't passed all the required properties to '{2}' - '{1}' is missing the '{0}' property.\n",
"code": "2741"
},
"2749": {
Expand Down Expand Up @@ -164,7 +164,7 @@
"code": "6142"
},
"7006": {
"body": "I don't know what type '{0}' is supposed to be, so I've defaulted it to '{1}'. Your tsconfig file says I should throw an error here.\n",
"body": "I don't know what type '{0}' is supposed to be, so I've defaulted it to '{1}'. Your `tsconfig.json` file says I should throw an error here. [Learn more](https://www.totaltypescript.com/tutorials/beginners-typescript/beginner-s-typescript-section/implicit-any-type-error).\n",
"code": "7006"
},
"7057": {
Expand All @@ -176,11 +176,11 @@
"code": "7061"
},
"8016": {
"body": "You can't use type assertions because this isn't a TypeScript file\n",
"body": "You can't use type assertions because this isn't a TypeScript file.\n",
"code": "8016"
},
"17004": {
"body": "You can't use JSX yet because you haven't added `jsx` to your `tsconfig.json`.\n",
"body": "You can't use JSX yet because you haven't added `jsx` to your `tsconfig.json`. [Learn more](https://www.totaltypescript.com/cannot-use-jsx-unless-the-jsx-flag-is-provided).\n",
"code": "17004"
},
"18004": {
Expand Down
32 changes: 18 additions & 14 deletions apps/vscode/src/initDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ const languages = [
'astro',
];

type UriStoreMember = {
range: vscode.Range;
severity: vscode.DiagnosticSeverity;
contents: vscode.MarkdownString[];
};

export const initDiagnostics = (context: vscode.ExtensionContext) => {
const uriStore: Record<
vscode.Uri['path'],
{
range: vscode.Range;
contents: vscode.MarkdownString[];
}[]
> = {};
const uriStore: Record<vscode.Uri['path'], UriStoreMember[]> = {};

const hoverProvider: vscode.HoverProvider = {
provideHover: (document, position) => {
Expand All @@ -28,9 +28,13 @@ export const initDiagnostics = (context: vscode.ExtensionContext) => {
return null;
}

const itemsInRange = itemsInUriStore.filter((item) => {
return item.range.contains(position);
});
const itemsInRange = itemsInUriStore
// Only show errors
.filter((item) => item.severity === vscode.DiagnosticSeverity.Error)
.filter((item) => {
return item.range.contains(position);
});

return itemsInRange[0];
},
};
Expand All @@ -51,20 +55,20 @@ export const initDiagnostics = (context: vscode.ExtensionContext) => {
e.uris.forEach((uri) => {
const diagnostics = vscode.languages.getDiagnostics(uri);

const items: {
range: vscode.Range;
contents: vscode.MarkdownString[];
}[] = [];
const items: UriStoreMember[] = [];

diagnostics.forEach((diagnostic) => {
if (diagnostic.source !== 'ts') {
return;
}

const humanizedVersion = humaniseDiagnostic(diagnostic);

if (humanizedVersion) {
items.push({
range: diagnostic.range,
contents: humanizedVersion,
severity: diagnostic.severity,
});
}
});
Expand Down
2 changes: 0 additions & 2 deletions packages/engine/src/parseErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,6 @@ export interface ErrorInfo extends ErrorInfoWithoutImprovedError {
} | null;
}

export interface ParseErrorsOpts {}

export const parseErrorsWithDb = (db: TsErrorMessageDb, message: string) => {
const errorMessageByKey: Record<string, ErrorInfoWithoutImprovedError> = {};

Expand Down

0 comments on commit 2279946

Please sign in to comment.