Skip to content

Commit

Permalink
feat: widen error node type
Browse files Browse the repository at this point in the history
  • Loading branch information
antfu committed Feb 4, 2024
1 parent f754d75 commit e39b4b2
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 6 deletions.
4 changes: 2 additions & 2 deletions packages/twoslash/src/legacy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -170,14 +170,14 @@ export function convertLegacyReturn(result: TwoslashReturn): TwoslashReturnLegac

errors: result.errors
.map((e): TwoslashReturnLegacy['errors'][0] => ({
id: e.id,
id: e.id ?? '',
code: e.code,
start: e.start,
length: e.length,
line: e.line,
character: e.character,
renderedMessage: e.text,
category: e.level,
category: e.level ?? 1,
})),

playgroundURL: '',
Expand Down
23 changes: 20 additions & 3 deletions packages/twoslash/src/types/nodes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,28 @@ export interface NodeCompletion extends NodeBase {

export interface NodeError extends NodeBase {
type: 'error'
id: string
level: 0 | 1 | 2 | 3
id?: string
/**
* Error level:
*
* Warning = 0
* Error = 1
* Suggestion = 2
* Message = 3
*/
level?: 0 | 1 | 2 | 3
/**
* Error code
*/
code: number
/**
* Error message
*/
text: string
filename: string
/**
* The filename of the file the error is in
*/
filename?: string
}

export interface NodeTag extends NodeBase {
Expand Down
2 changes: 1 addition & 1 deletion packages/twoslash/src/validation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export function validateCodeForErrors(
handbookOptions: { errors: number[] },
vfsRoot: string,
) {
const unspecifiedErrors = relevantErrors.filter(e => !handbookOptions.errors.includes(e.code))
const unspecifiedErrors = relevantErrors.filter(e => e.code && !handbookOptions.errors.includes(e.code as number))
const errorsFound = Array.from(new Set(unspecifiedErrors.map(e => e.code))).join(' ')

if (unspecifiedErrors.length) {
Expand Down

0 comments on commit e39b4b2

Please sign in to comment.