Commit 1a9582c0 authored by tom's avatar tom

change editor language for vyper contracts

parent a7264aeb
...@@ -10,6 +10,7 @@ export function monaco(): CspDev.DirectiveDescriptor { ...@@ -10,6 +10,7 @@ export function monaco(): CspDev.DirectiveDescriptor {
'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/editor/editor.main.js', 'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/editor/editor.main.js',
'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/editor/editor.main.nls.js', 'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/editor/editor.main.nls.js',
'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/basic-languages/solidity/solidity.js', 'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/basic-languages/solidity/solidity.js',
'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/basic-languages/elixir/elixir.js',
'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/base/worker/workerMain.js', 'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs/base/worker/workerMain.js',
], ],
'style-src': [ 'style-src': [
......
...@@ -142,11 +142,19 @@ const ContractSourceCode = ({ address, implementationAddress }: Props) => { ...@@ -142,11 +142,19 @@ const ContractSourceCode = ({ address, implementationAddress }: Props) => {
return ( return (
<> <>
<Box display={ sourceType === 'primary' ? 'block' : 'none' }> <Box display={ sourceType === 'primary' ? 'block' : 'none' }>
<CodeEditor data={ primaryEditorData } remappings={ primaryContractQuery.data?.compiler_settings?.remappings }/> <CodeEditor
data={ primaryEditorData }
remappings={ primaryContractQuery.data?.compiler_settings?.remappings }
language={ primaryContractQuery.data?.language ?? undefined }
/>
</Box> </Box>
{ secondaryEditorData && ( { secondaryEditorData && (
<Box display={ sourceType === 'secondary' ? 'block' : 'none' }> <Box display={ sourceType === 'secondary' ? 'block' : 'none' }>
<CodeEditor data={ secondaryEditorData } remappings={ secondaryContractQuery.data?.compiler_settings?.remappings }/> <CodeEditor
data={ secondaryEditorData }
remappings={ secondaryContractQuery.data?.compiler_settings?.remappings }
language={ secondaryContractQuery.data?.language ?? undefined }
/>
</Box> </Box>
) } ) }
</> </>
......
...@@ -36,9 +36,10 @@ const EDITOR_HEIGHT = 500; ...@@ -36,9 +36,10 @@ const EDITOR_HEIGHT = 500;
interface Props { interface Props {
data: Array<File>; data: Array<File>;
remappings?: Array<string>; remappings?: Array<string>;
language?: string;
} }
const CodeEditor = ({ data, remappings }: Props) => { const CodeEditor = ({ data, remappings, language }: Props) => {
const [ instance, setInstance ] = React.useState<Monaco | undefined>(); const [ instance, setInstance ] = React.useState<Monaco | undefined>();
const [ editor, setEditor ] = React.useState<monaco.editor.IStandaloneCodeEditor | undefined>(); const [ editor, setEditor ] = React.useState<monaco.editor.IStandaloneCodeEditor | undefined>();
const [ index, setIndex ] = React.useState(0); const [ index, setIndex ] = React.useState(0);
...@@ -53,6 +54,8 @@ const CodeEditor = ({ data, remappings }: Props) => { ...@@ -53,6 +54,8 @@ const CodeEditor = ({ data, remappings }: Props) => {
const editorWidth = containerRect ? containerRect.width - (isMobile ? 0 : SIDE_BAR_WIDTH) : 0; const editorWidth = containerRect ? containerRect.width - (isMobile ? 0 : SIDE_BAR_WIDTH) : 0;
const editorLanguage = language === 'vyper' ? 'elixir' : 'sol';
React.useEffect(() => { React.useEffect(() => {
instance?.editor.setTheme(colorMode === 'light' ? 'blockscout-light' : 'blockscout-dark'); instance?.editor.setTheme(colorMode === 'light' ? 'blockscout-light' : 'blockscout-dark');
}, [ colorMode, instance?.editor ]); }, [ colorMode, instance?.editor ]);
...@@ -69,7 +72,7 @@ const CodeEditor = ({ data, remappings }: Props) => { ...@@ -69,7 +72,7 @@ const CodeEditor = ({ data, remappings }: Props) => {
const loadedModelsPaths = loadedModels.map((model) => model.uri.path); const loadedModelsPaths = loadedModels.map((model) => model.uri.path);
const newModels = data.slice(1) const newModels = data.slice(1)
.filter((file) => !loadedModelsPaths.includes(file.file_path)) .filter((file) => !loadedModelsPaths.includes(file.file_path))
.map((file) => monaco.editor.createModel(file.source_code, 'sol', monaco.Uri.parse(file.file_path))); .map((file) => monaco.editor.createModel(file.source_code, editorLanguage, monaco.Uri.parse(file.file_path)));
loadedModels.concat(newModels).forEach(addFileImportDecorations); loadedModels.concat(newModels).forEach(addFileImportDecorations);
...@@ -185,7 +188,7 @@ const CodeEditor = ({ data, remappings }: Props) => { ...@@ -185,7 +188,7 @@ const CodeEditor = ({ data, remappings }: Props) => {
return ( return (
<Box overflow="hidden" borderRadius="md" height={ `${ EDITOR_HEIGHT }px` }> <Box overflow="hidden" borderRadius="md" height={ `${ EDITOR_HEIGHT }px` }>
<MonacoEditor <MonacoEditor
language="sol" language={ editorLanguage }
path={ data[index].file_path } path={ data[index].file_path }
defaultValue={ data[index].source_code } defaultValue={ data[index].source_code }
options={ EDITOR_OPTIONS } options={ EDITOR_OPTIONS }
...@@ -216,7 +219,7 @@ const CodeEditor = ({ data, remappings }: Props) => { ...@@ -216,7 +219,7 @@ const CodeEditor = ({ data, remappings }: Props) => {
<MonacoEditor <MonacoEditor
className="editor-container" className="editor-container"
height={ `${ EDITOR_HEIGHT }px` } height={ `${ EDITOR_HEIGHT }px` }
language="sol" language={ editorLanguage }
path={ data[index].file_path } path={ data[index].file_path }
defaultValue={ data[index].source_code } defaultValue={ data[index].source_code }
options={ EDITOR_OPTIONS } options={ EDITOR_OPTIONS }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment