|
|
|
@ -8,15 +8,14 @@ import { cairoTokensProvider, cairoLanguageConfig } from './syntaxes/cairo' |
|
|
|
|
import { zokratesTokensProvider, zokratesLanguageConfig } from './syntaxes/zokrates' |
|
|
|
|
import { moveTokenProvider, moveLanguageConfig } from './syntaxes/move' |
|
|
|
|
import { monacoTypes } from '@remix-ui/editor'; |
|
|
|
|
|
|
|
|
|
import './remix-ui-editor.css' |
|
|
|
|
import { loadTypes } from './web-types' |
|
|
|
|
|
|
|
|
|
import { retrieveNodesAtPosition } from './helpers/retrieveNodesAtPosition' |
|
|
|
|
import { RemixHoverProvider } from './providers/hoverProvider' |
|
|
|
|
import { RemixReferenceProvider } from './providers/referenceProvider' |
|
|
|
|
import { RemixCompletionProvider } from './providers/completionProvider' |
|
|
|
|
import { RemixHighLightProvider } from './providers/highlightProvider' |
|
|
|
|
import { RemixDefinitionProvider } from './providers/definitionProvider' |
|
|
|
|
import './remix-ui-editor.css' |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
enum MarkerSeverity { |
|
|
|
@ -93,23 +92,12 @@ export type DecorationsReturn = { |
|
|
|
|
registeredDecorations?: Array<any> |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* eslint-disable-next-line */ |
|
|
|
|
export interface EditorUIProps { |
|
|
|
|
contextualListener: any |
|
|
|
|
activated: boolean |
|
|
|
|
themeType: string |
|
|
|
|
currentFile: string |
|
|
|
|
events: { |
|
|
|
|
onBreakPointAdded: (file: string, line: number) => void |
|
|
|
|
onBreakPointCleared: (file: string, line: number) => void |
|
|
|
|
onDidChangeContent: (file: string) => void |
|
|
|
|
onEditorMounted: () => void |
|
|
|
|
} |
|
|
|
|
plugin: { |
|
|
|
|
export type PluginType = { |
|
|
|
|
on: (plugin: string, event: string, listener: any) => void |
|
|
|
|
call: (plugin: string, method: string, arg1?: any, arg2?: any, arg3?: any, arg4?: any) => any |
|
|
|
|
} |
|
|
|
|
editorAPI: { |
|
|
|
|
|
|
|
|
|
export type EditorAPIType = { |
|
|
|
|
findMatches: (uri: string, value: string) => any |
|
|
|
|
getFontSize: () => number, |
|
|
|
|
getValue: (uri: string) => string |
|
|
|
@ -121,6 +109,21 @@ export interface EditorUIProps { |
|
|
|
|
addErrorMarker: (errors: errorMarker[], from: string) => void |
|
|
|
|
clearErrorMarkers: (sources: string[] | {[fileName: string]: any}, from: string) => void |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
/* eslint-disable-next-line */ |
|
|
|
|
export interface EditorUIProps { |
|
|
|
|
contextualListener: any |
|
|
|
|
activated: boolean |
|
|
|
|
themeType: string |
|
|
|
|
currentFile: string |
|
|
|
|
events: { |
|
|
|
|
onBreakPointAdded: (file: string, line: number) => void |
|
|
|
|
onBreakPointCleared: (file: string, line: number) => void |
|
|
|
|
onDidChangeContent: (file: string) => void |
|
|
|
|
onEditorMounted: () => void |
|
|
|
|
} |
|
|
|
|
plugin: PluginType |
|
|
|
|
editorAPI: EditorAPIType |
|
|
|
|
} |
|
|
|
|
export const EditorUI = (props: EditorUIProps) => { |
|
|
|
|
const [, setCurrentBreakpoints] = useState({}) |
|
|
|
@ -630,22 +633,16 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
|
await props.plugin.call('codeFormatter', 'format', file) |
|
|
|
|
}, |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
const freeFunctionCondition = editor.createContextKey('freeFunctionCondition', false); |
|
|
|
|
const executeFreeFunctionAction = { |
|
|
|
|
id: "executeFreeFunction", |
|
|
|
|
label: "Execute in Remix VM", |
|
|
|
|
label: "Execute free function in the Remix VM", |
|
|
|
|
contextMenuOrder: 0, // choose the order
|
|
|
|
|
contextMenuGroupId: "execute", // create a new grouping
|
|
|
|
|
precondition: 'freeFunctionCondition', |
|
|
|
|
run: async () => {
|
|
|
|
|
const cursorPosition = props.editorAPI.getCursorPosition() |
|
|
|
|
let nodesAtPosition = await props.plugin.call('codeParser', 'nodesAtPosition', cursorPosition) |
|
|
|
|
// if no nodes exits at position, try to get the block of which the position is in
|
|
|
|
|
const block = await props.plugin.call('codeParser', 'getANTLRBlockAtPosition', cursorPosition, null) |
|
|
|
|
|
|
|
|
|
if (!nodesAtPosition.length) { |
|
|
|
|
if (block) { |
|
|
|
|
nodesAtPosition = await props.plugin.call('codeParser', 'nodesAtPosition', block.start) |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
const { nodesAtPosition } = await retrieveNodesAtPosition(props.editorAPI, props.plugin)
|
|
|
|
|
// find the contract and get the nodes of the contract and the base contracts and imports
|
|
|
|
|
if (nodesAtPosition && isArray(nodesAtPosition) && nodesAtPosition.length) { |
|
|
|
|
console.log(nodesAtPosition) |
|
|
|
@ -664,6 +661,25 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
|
editor.addAction(formatAction) |
|
|
|
|
editor.addAction(zoomOutAction) |
|
|
|
|
editor.addAction(zoominAction) |
|
|
|
|
|
|
|
|
|
const contextmenu = editor.getContribution('editor.contrib.contextmenu') |
|
|
|
|
const orgContextMenuMethod = contextmenu._onContextMenu; |
|
|
|
|
const onContextMenuHandlerForFreeFunction = async () => { |
|
|
|
|
const file = await props.plugin.call('fileManager', 'getCurrentFile') |
|
|
|
|
if (!file.endsWith('.sol')) { |
|
|
|
|
freeFunctionCondition.set(false) |
|
|
|
|
return |
|
|
|
|
} |
|
|
|
|
const { nodesAtPosition } = await retrieveNodesAtPosition(props.editorAPI, props.plugin) |
|
|
|
|
const last = nodesAtPosition[nodesAtPosition.length - 1] |
|
|
|
|
freeFunctionCondition.set(last && last.kind === 'freeFunction') |
|
|
|
|
} |
|
|
|
|
contextmenu._onContextMenu = function () {
|
|
|
|
|
onContextMenuHandlerForFreeFunction() |
|
|
|
|
.then(() => orgContextMenuMethod.apply(contextmenu, arguments)) |
|
|
|
|
.catch(() => orgContextMenuMethod.apply(contextmenu, arguments)) |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
editor.addAction(executeFreeFunctionAction) |
|
|
|
|
const editorService = editor._codeEditorService; |
|
|
|
|
const openEditorBase = editorService.openCodeEditor.bind(editorService); |
|
|
|
|