Skip to content

Commit

Permalink
fix(core-dev): 优化编译校验性能,修正部分错误逻辑
Browse files Browse the repository at this point in the history
  • Loading branch information
chongqiangchen committed Mar 25, 2023
1 parent 05cfb9d commit 99edb65
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 27 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,5 @@ dist
npm-debug.log*
yarn-debug.log*
yarn-error.log*

pnpm-lock.yaml
35 changes: 23 additions & 12 deletions packages/core-dev/src/components/TopBar/Deploy.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const resolveConstructor = (abi: any) => {
}

const Deploy = () => {
const {state, vmProviderRef, actions} = useEditor();
const {state, vmProviderRef, actions, id} = useEditor();
const methods = useForm({mode: "onBlur"});

const [compiledContracts, setCompiledContracts] = useState<any>(null);
Expand All @@ -42,7 +42,7 @@ const Deploy = () => {

const preDeploy = async () => {
setCompileLoading(true);
methods.reset();
resetAll();
try {
const compileResult: any = await state.codeParser.compilerService.compile();
const hasError = compileResult.output.errors.filter((item: any) => item.severity === 'error').length > 0;
Expand Down Expand Up @@ -86,6 +86,12 @@ const Deploy = () => {
});
setDeployContractAddress(contract.address);
setDeployError(false);
actions.updateConsoleMessages([
{
type: "success",
message: selectedContract + " - 合约部署成功:" + contract.address
}
])
} catch (e: any) {
setDeployError(true);
actions.updateConsoleMessages([
Expand All @@ -99,38 +105,43 @@ const Deploy = () => {
setDeployLoading(false);
}

const resetAll = () => {
methods.reset();
setSelectedContract(undefined);
setCompiledContracts(null);
setCompiledContractKeys(null);
setDeployContractAddress(undefined);
}

useEffect(() => {
if (curModel) {
methods.reset();
setSelectedContract(undefined);
setCompiledContracts(null);
setCompiledContractKeys(null);
setDeployContractAddress(undefined);
resetAll();
}
}, [modelIndex])

console.log(compiledContractKeys);

return (
<Popover>
<Popover placement="bottom-end">
<PopoverHandler>
<PlayCircleIcon className="w-6 h-6 text-white cursor-pointer"/>
</PopoverHandler>
<PopoverContent>
<PopoverContent className="z-[10]">
<div className="mb-4 font-medium">当前部署合约:{curModel ? curModel.model.uri.path.substring(1) : '无'}</div>
<div className="flex gap-2 mb-4">
<Button color={error ? 'red' : 'blue'} size="sm" loading={compileLoading} onClick={preDeploy}>
<Button color={error ? 'red' : 'blue'} size="sm" onClick={preDeploy}>
编译合约
</Button>
<Button
color={deployError ? 'red' : 'blue'}
disabled={error}
size="sm"
onClick={methods.handleSubmit(startDeploy)}
loading={deployLoading}
>
部署
</Button>
</div>
{deployContractAddress && <div>部署成功:${deployContractAddress}</div>}
{deployContractAddress && <div className="mb-4">部署成功, 可查看日志</div>}
<div className="mb-4">
{compiledContractKeys && (
<Select
Expand Down
26 changes: 12 additions & 14 deletions packages/core-dev/src/editor/mountFunctions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Monaco } from '@monaco-editor/react';
import { IPosition } from 'monaco-editor';
import * as helper from 'solive-compiler';
import { ErrorMarker } from 'solive-compiler';
import debounce from "lodash/debounce";

import {
BaseMonacoEditor,
Expand Down Expand Up @@ -279,22 +280,19 @@ function registerListeners(
}
};

const throttledCompile = debounce(async () => {
console.log('11');
editorState.codeParser.compilerService
.compile()
.then((data: unknown) =>
transformCompileError(data as unknown as { output: any; input: any })
);
}, 1000, { leading: true, trailing: true });

const registerListenErrorMarkers = () => {
editor.onDidChangeModelContent(() => {
editorState.codeParser.compilerService
.compile()
.then((data: unknown) =>
transformCompileError(data as unknown as { output: any; input: any })
);
});
editor.onDidChangeModelContent(throttledCompile);

editor.onDidChangeModel(() => {
editorState.codeParser.compilerService
.compile()
.then((data: unknown) =>
transformCompileError(data as unknown as { output: any; input: any })
);
});
editor.onDidChangeModel(throttledCompile);
};

registerListenErrorMarkers();
Expand Down
3 changes: 2 additions & 1 deletion packages/core-dev/src/types/console.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import uniqueId from 'lodash/uniqueId';

export type TInputConsoleMessage = {
type: string; message: string
type: string;
message: string
};

export type TConsoleMessage = {
Expand Down

0 comments on commit 99edb65

Please sign in to comment.