diff --git a/libs/remix-ui/editor/src/lib/providers/definitionProvider.ts b/libs/remix-ui/editor/src/lib/providers/definitionProvider.ts index 5e62632219..7d059ed109 100644 --- a/libs/remix-ui/editor/src/lib/providers/definitionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/definitionProvider.ts @@ -13,15 +13,24 @@ export class RemixDefinitionProvider implements monaco.languages.DefinitionProvi // eslint-disable-next-line @typescript-eslint/no-unused-vars async provideDefinition(model: monaco.editor.ITextModel, position: monaco.Position, token: monaco.CancellationToken): Promise { const cursorPosition = this.props.editorAPI.getCursorPosition() - await this.jumpToDefinition(cursorPosition) - return null + const jumpLocation = await this.jumpToDefinition(cursorPosition) + + return [{ + uri: this.monaco.Uri.parse(jumpLocation.fileName), + range: { + startLineNumber: jumpLocation.startLineNumber, + startColumn: jumpLocation.startColumn, + endLineNumber: jumpLocation.endLineNumber, + endColumn: jumpLocation.endColumn + } + }] } async jumpToDefinition(position: any) { const node = await this.props.plugin.call('codeParser', 'definitionAtPosition', position) const sourcePosition = await this.props.plugin.call('codeParser', 'positionOfDefinition', node) if (sourcePosition) { - await this.jumpToPosition(sourcePosition) + return await this.jumpToPosition(sourcePosition) } } @@ -32,10 +41,17 @@ export class RemixDefinitionProvider implements monaco.languages.DefinitionProvi const jumpToLine = async (fileName: string, lineColumn: any) => { if (fileName !== await this.props.plugin.call('fileManager', 'file')) { await this.props.plugin.call('contentImport', 'resolveAndSave', fileName, null) - await this.props.plugin.call('fileManager', 'open', fileName) } + const fileTarget = await this.props.plugin.call('fileManager', 'getPathFromUrl', fileName) if (lineColumn.start && lineColumn.start.line >= 0 && lineColumn.start.column >= 0) { - this.props.plugin.call('editor', 'gotoLine', lineColumn.start.line, lineColumn.end.column + 1) + const pos = { + startLineNumber: lineColumn.start.line + 1, + startColumn: lineColumn.start.column + 1, + endColumn: lineColumn.end.column + 1, + endLineNumber: lineColumn.end.line + 1, + fileName: (fileTarget && fileTarget.file) || fileName + } + return pos } } const lastCompilationResult = await this.props.plugin.call('codeParser', 'getLastCompilationResult') // await this.props.plugin.call('compilerArtefacts', 'getLastCompilationResult') @@ -43,7 +59,7 @@ export class RemixDefinitionProvider implements monaco.languages.DefinitionProvi const lineColumn = await this.props.plugin.call('codeParser', 'getLineColumnOfPosition', position) const filename = lastCompilationResult.getSourceName(position.file) - jumpToLine(filename, lineColumn) + return await jumpToLine(filename, lineColumn) } } } \ No newline at end of file diff --git a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx index 6a2e1ac4bb..3425f1fb5a 100644 --- a/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx +++ b/libs/remix-ui/editor/src/lib/remix-ui-editor.tsx @@ -136,6 +136,7 @@ export const EditorUI = (props: EditorUIProps) => { const editorRef = useRef(null) const monacoRef = useRef(null) const currentFileRef = useRef('') + const definitionProvider = new RemixDefinitionProvider(props, monaco) // const currentDecorations = useRef({ sourceAnnotationsPerFile: {}, markerPerFile: {} }) // decorations that are currently in use by the editor // const registeredDecorations = useRef({}) // registered decorations @@ -569,14 +570,17 @@ export const EditorUI = (props: EditorUIProps) => { } editor.addAction(zoomOutAction) editor.addAction(zoominAction) - const editorService = editor._codeEditorService; const openEditorBase = editorService.openCodeEditor.bind(editorService); - editorService.openCodeEditor = async (input, source) => { + editorService.openCodeEditor = async (input , source) => { const result = await openEditorBase(input, source) if (input && input.resource && input.resource.path) { try { await props.plugin.call('fileManager', 'open', input.resource.path) + if (input.options && input.options.selection) { + editor.revealRange(input.options.selection) + editor.setPosition({ column: input.options.selection.startColumn, lineNumber: input.options.selection.startLineNumber }) + } } catch (e) { console.log(e) } @@ -608,6 +612,7 @@ export const EditorUI = (props: EditorUIProps) => { monacoRef.current.languages.registerHoverProvider('remix-solidity', new RemixHoverProvider(props, monaco)) monacoRef.current.languages.registerCompletionItemProvider('remix-solidity', new RemixCompletionProvider(props, monaco)) + loadTypes(monacoRef.current) }