-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0be8fb9
commit 593f1f1
Showing
4 changed files
with
135 additions
and
103 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,31 @@ | ||
import { useDeferredValue, useMemo } from "react"; | ||
import { Workspace, FileHandle } from "./red_knot_wasm"; | ||
import { ErrorMessage } from "../shared/ErrorMessage"; | ||
|
||
import { Theme } from "../shared/theme"; | ||
import PythonEditor from "./PythonEditor"; | ||
|
||
interface CheckResult { | ||
diagnostics: string[]; | ||
error: string | null; | ||
} | ||
|
||
type Props = { | ||
file: FileHandle; | ||
fileName: string; | ||
content: string; | ||
theme: Theme; | ||
workspace: Workspace; | ||
fileDiagnostics: string[]; | ||
|
||
onSourceChanged(source: string): void; | ||
}; | ||
|
||
export default function Editor({ | ||
content, | ||
file, | ||
workspace, | ||
fileName, | ||
fileDiagnostics, | ||
theme, | ||
onSourceChanged, | ||
}: Props) { | ||
// TODO: figure out how to do deferred | ||
const deferredContent = useDeferredValue(content); | ||
|
||
const checkResult: CheckResult = useMemo(() => { | ||
try { | ||
const diagnostics = workspace.checkFile(file); | ||
// There's an implicit dependency on deferredContent by what's stored | ||
// in the workspace | ||
// eslint-disable-next-line @typescript-eslint/no-unused-vars | ||
const _value = deferredContent; | ||
|
||
return { | ||
diagnostics, | ||
error: null, | ||
}; | ||
} catch (e) { | ||
console.error(e); | ||
return { | ||
diagnostics: [], | ||
error: (e as Error).message, | ||
}; | ||
} | ||
}, [deferredContent, file, workspace]); | ||
|
||
const filePath = file.toString(); | ||
const fileType = filePath.endsWith(".toml") ? "toml" : "py"; | ||
const fileType = fileName.endsWith(".toml") ? "toml" : "py"; | ||
|
||
return ( | ||
<> | ||
<PythonEditor | ||
visible={fileType === "py"} | ||
source={fileType === "py" ? content : ""} | ||
theme={theme} | ||
diagnostics={checkResult.diagnostics} | ||
onChange={onSourceChanged} | ||
/> | ||
|
||
{checkResult.error ? ( | ||
<div | ||
style={{ | ||
position: "fixed", | ||
left: "10%", | ||
right: "10%", | ||
bottom: "10%", | ||
}} | ||
> | ||
<ErrorMessage>{checkResult.error}</ErrorMessage> | ||
</div> | ||
) : null} | ||
</> | ||
<PythonEditor | ||
visible={fileType === "py"} | ||
source={fileType === "py" ? content : ""} | ||
theme={theme} | ||
diagnostics={fileDiagnostics} | ||
onChange={onSourceChanged} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.