Skip to content

Commit f20593c

Browse files
feat: add tsconfig error
1 parent 5c65c43 commit f20593c

File tree

5 files changed

+75
-38
lines changed

5 files changed

+75
-38
lines changed

Diff for: packages/website/src/components/ErrorsViewer.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import clsx from 'clsx';
66
import React, { useEffect, useState } from 'react';
77

88
import type { AlertBlockProps } from './layout/AlertBlock';
9-
import type { ErrorGroup, ErrorItem } from './types';
9+
import type { ErrorGroup, ErrorItem, TabType } from './types';
1010

1111
import styles from './ErrorsViewer.module.css';
1212
import AlertBlock from './layout/AlertBlock';

Diff for: packages/website/src/components/Playground.tsx

+12-5
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,11 @@ function Playground(): React.JSX.Element {
3333
const windowSize = useWindowSize();
3434
const [state, setState] = useHashState(defaultConfig);
3535
const [astModel, setAstModel] = useState<UpdateModel>();
36-
const [markers, setMarkers] = useState<ErrorGroup[]>();
36+
const [markers, setMarkers] = useState<Record<TabType, ErrorGroup[]>>({
37+
code: [],
38+
eslintrc: [],
39+
tsconfig: [],
40+
});
3741
const [ruleNames, setRuleNames] = useState<RuleDetails[]>([]);
3842
const [isLoading, setIsLoading] = useState(true);
3943
const [tsVersions, setTSVersion] = useState<readonly string[]>([]);
@@ -63,7 +67,6 @@ function Playground(): React.JSX.Element {
6367
[],
6468
);
6569

66-
console.log(markers);
6770
const ActiveVisualEditor =
6871
!isLoading &&
6972
{
@@ -88,6 +91,8 @@ function Playground(): React.JSX.Element {
8891
}
8992
}, [windowSize]);
9093

94+
console.log(activeTab, markers);
95+
9196
return (
9297
<div className={styles.codeContainer}>
9398
<PanelGroup
@@ -166,8 +171,10 @@ function Playground(): React.JSX.Element {
166171
active={state.showAST ?? false}
167172
additionalTabsInfo={{
168173
Errors:
169-
markers?.reduce((prev, cur) => prev + cur.items.length, 0) ||
170-
0,
174+
markers[activeTab].reduce(
175+
(prev, cur) => prev + cur.items.length,
176+
0,
177+
) || 0,
171178
}}
172179
change={showAST => setState({ showAST })}
173180
tabs={detailTabs}
@@ -217,7 +224,7 @@ function Playground(): React.JSX.Element {
217224
/>
218225
)
219226
) : (
220-
<ErrorsViewer value={markers} />
227+
<ErrorsViewer value={markers[activeTab]} />
221228
)}
222229
</div>
223230
</Panel>

Diff for: packages/website/src/components/editor/LoadedEditor.tsx

+20-4
Original file line numberDiff line numberDiff line change
@@ -84,11 +84,27 @@ export const LoadedEditor: React.FC<LoadedEditorProps> = ({
8484
resource: model.uri,
8585
});
8686

87-
const test = parseMarkers(markers, codeActions, editor);
87+
const errors = parseMarkers(markers, codeActions, editor);
88+
89+
onMarkersChange(prev => {
90+
const tsconfigError =
91+
activeTab === 'tsconfig' &&
92+
Object.fromEntries(prev[activeTab].map(error => [error.group, error]))
93+
.Typescript;
94+
95+
if (!errors.length && tsconfigError) {
96+
return {
97+
...prev,
98+
[activeTab]: [tsconfigError],
99+
};
100+
}
88101

89-
console.log(test);
90-
// onMarkersChange(parseMarkers(markers, codeActions, editor));
91-
}, [codeActions, onMarkersChange, editor, monaco.editor]);
102+
return {
103+
...prev,
104+
[activeTab]: errors,
105+
};
106+
});
107+
}, [activeTab, codeActions, onMarkersChange, editor, monaco.editor]);
92108

93109
useEffect(() => {
94110
webLinter.updateParserOptions(sourceType);

Diff for: packages/website/src/components/editor/types.ts

+3-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@ export interface CommonEditorProps extends ConfigModel {
55
readonly activeTab: TabType;
66
readonly onASTChange: (value: UpdateModel | undefined) => void;
77
readonly onChange: (cfg: Partial<ConfigModel>) => void;
8-
readonly onMarkersChange: (value: ErrorGroup[]) => void;
8+
readonly onMarkersChange: React.Dispatch<
9+
React.SetStateAction<Record<TabType, ErrorGroup[]>>
10+
>;
911
readonly onSelect: (position?: number) => void;
1012
readonly selectedRange?: SelectedRange;
1113
}

Diff for: packages/website/src/components/linter/createLinter.ts

+39-27
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ import type {
77
} from '@typescript-eslint/utils/ts-eslint';
88
import type * as ts from 'typescript';
99

10+
import type {
11+
ErrorGroup,
12+
TabType,
13+
} from '../../../../website/src/components/types';
1014
import type {
1115
LinterOnLint,
1216
LinterOnParse,
@@ -19,7 +23,7 @@ import { createEventsBinder } from '../lib/createEventsBinder';
1923
import { parseESLintRC, parseTSConfig } from '../lib/parseConfig';
2024
import { defaultEslintConfig, PARSER_NAME } from './config';
2125
import { createParser } from './createParser';
22-
import { ErrorGroup } from '../../../../website/src/components/types';
26+
2327
export interface CreateLinter {
2428
configs: string[];
2529
onLint(cb: LinterOnLint): () => void;
@@ -42,7 +46,9 @@ export function createLinter(
4246
system: PlaygroundSystem,
4347
webLinterModule: WebLinterModule,
4448
vfs: typeof tsvfs,
45-
onMarkersChange: (value: ErrorGroup[]) => void,
49+
onMarkersChange: React.Dispatch<
50+
React.SetStateAction<Record<TabType, ErrorGroup[]>>
51+
>,
4652
): CreateLinter {
4753
const rules: CreateLinter['rules'] = new Map();
4854
const configs = new Map(Object.entries(webLinterModule.configs));
@@ -161,31 +167,37 @@ export function createLinter(
161167
console.log('[Editor] Updating', fileName, compilerOptions);
162168
parser.updateConfig(compilerOptions);
163169
} catch (e) {
164-
const errors = {
165-
group: 'Typescript',
166-
items: e.message
167-
.trim()
168-
.split('\n')
169-
.map((message: string) => {
170-
return {
171-
fixer: undefined,
172-
location: '',
173-
message,
174-
severity: 8,
175-
suggestions: [],
176-
};
177-
}),
178-
uri: undefined,
179-
};
180-
181-
console.log(onMarkersChange);
182-
console.log(errors);
183-
184-
onMarkersChange([errors]);
185-
186-
// const marker =
187-
188-
// console.error("asdf",e);
170+
if (e instanceof Error) {
171+
const error = {
172+
group: 'Typescript',
173+
items: e.message
174+
.trim()
175+
.split('\n')
176+
.map((message: string) => {
177+
return {
178+
fixer: undefined,
179+
location: '',
180+
message,
181+
severity: 8,
182+
suggestions: [],
183+
};
184+
}),
185+
uri: undefined,
186+
};
187+
188+
onMarkersChange(prev => {
189+
const activeTabErrors = Object.fromEntries(
190+
prev.tsconfig.map(error => [error.group, error]),
191+
);
192+
193+
activeTabErrors.Typescript = error;
194+
195+
return {
196+
...prev,
197+
tsconfig: Object.values(activeTabErrors),
198+
};
199+
});
200+
}
189201
}
190202
};
191203

0 commit comments

Comments
 (0)