|
|
@ -358,7 +358,7 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
const model = editorModelsState[currentFileRef.current]?.model |
|
|
|
const model = editorModelsState[currentFileRef.current]?.model |
|
|
|
if (model) { |
|
|
|
if (model) { |
|
|
|
return model.getOffsetAt(position) |
|
|
|
return model.getOffsetAt(position) |
|
|
|
}else{ |
|
|
|
} else { |
|
|
|
return 0 |
|
|
|
return 0 |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
@ -427,35 +427,47 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
|
|
|
|
|
|
|
|
// register Definition Provider
|
|
|
|
// register Definition Provider
|
|
|
|
monacoRef.current.languages.registerDefinitionProvider('remix-solidity', { |
|
|
|
monacoRef.current.languages.registerDefinitionProvider('remix-solidity', { |
|
|
|
provideDefinition(model: monaco.editor.ITextModel, position: monaco.Position, token: monaco.CancellationToken){ |
|
|
|
provideDefinition(model: monaco.editor.ITextModel, position: monaco.Position, token: monaco.CancellationToken) { |
|
|
|
const cursorPosition = props.editorAPI.getCursorPosition() |
|
|
|
const cursorPosition = props.editorAPI.getCursorPosition() |
|
|
|
props.plugin.call('contextualListener', 'jumpToDefinition', cursorPosition) |
|
|
|
props.plugin.call('contextualListener', 'jumpToDefinition', cursorPosition) |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
|
monacoRef.current.languages.registerReferenceProvider('remix-solidity', { |
|
|
|
monacoRef.current.languages.registerReferenceProvider('remix-solidity', { |
|
|
|
provideReferences(model: monaco.editor.ITextModel, position: monaco.Position, context: any, token: monaco.CancellationToken){ |
|
|
|
async provideReferences(model: monaco.editor.ITextModel, position: monaco.Position, context: any, token: monaco.CancellationToken) { |
|
|
|
const cursorPosition = props.editorAPI.getCursorPosition() |
|
|
|
const cursorPosition = props.editorAPI.getCursorPosition() |
|
|
|
const references = props.plugin.call('contextualListener', 'referrencesAtPosition', cursorPosition) |
|
|
|
const nodes = await props.plugin.call('contextualListener', 'referrencesAtPosition', cursorPosition) |
|
|
|
console.log(references) |
|
|
|
const references = [] |
|
|
|
return [{ |
|
|
|
if (nodes && nodes.length) { |
|
|
|
range: new monaco.Range( |
|
|
|
const compilationResult = await props.plugin.call('compilerArtefacts', 'getLastCompilationResult') |
|
|
|
0,
|
|
|
|
const file = await props.plugin.call('fileManager', 'file') |
|
|
|
0, |
|
|
|
if (compilationResult && compilationResult.data && compilationResult.data.sources[file]) { |
|
|
|
0,
|
|
|
|
for (const node of nodes) { |
|
|
|
4 |
|
|
|
const position = sourceMappingDecoder.decode(node.src) |
|
|
|
), |
|
|
|
const fileInNode = compilationResult.getSourceName(position.file) |
|
|
|
uri: monaco.Uri.parse('test.sol'), |
|
|
|
let fileTarget = await props.plugin.call('fileManager', 'getPathFromUrl', fileInNode) |
|
|
|
}, |
|
|
|
fileTarget = fileTarget.file |
|
|
|
{ |
|
|
|
const fileContent = await props.plugin.call('fileManager', 'readFile', fileInNode) |
|
|
|
range: new monaco.Range( |
|
|
|
const lineColumn = await props.plugin.call('offsetToLineColumnConverter', 'offsetToLineColumn', |
|
|
|
0,
|
|
|
|
position, |
|
|
|
0, |
|
|
|
position.file, |
|
|
|
0,
|
|
|
|
compilationResult.getSourceCode().sources, |
|
|
|
4 |
|
|
|
compilationResult.getAsts()) |
|
|
|
), |
|
|
|
console.log(position, fileTarget, lineColumn) |
|
|
|
uri: monaco.Uri.parse('test2.sol'), |
|
|
|
try { |
|
|
|
}] |
|
|
|
props.plugin.call('editor', 'addModel', fileTarget, fileContent) |
|
|
|
|
|
|
|
} catch (e) { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
const range = new monaco.Range(lineColumn.start.line + 1, lineColumn.start.column + 1, lineColumn.end.line + 1, lineColumn.end.column + 1) |
|
|
|
|
|
|
|
references.push({ |
|
|
|
|
|
|
|
range, |
|
|
|
|
|
|
|
uri: monaco.Uri.parse(fileTarget) |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
return references |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|
|
|
|
|
|
|
|
@ -463,22 +475,39 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
|
|
|
|
|
|
|
|
monacoRef.current.languages.registerHoverProvider('remix-solidity', { |
|
|
|
monacoRef.current.languages.registerHoverProvider('remix-solidity', { |
|
|
|
provideHover: async function (model: any, position: monaco.Position) { |
|
|
|
provideHover: async function (model: any, position: monaco.Position) { |
|
|
|
//console.log(position)
|
|
|
|
console.log('--------------------') |
|
|
|
const cursorPosition = props.editorAPI.getHoverPosition(position) |
|
|
|
const cursorPosition = props.editorAPI.getHoverPosition(position) |
|
|
|
//console.log(cursorPosition)
|
|
|
|
const nodeDefinition = await props.plugin.call('contextualListener', 'definitionAtPosition', cursorPosition) |
|
|
|
const compilationResult = await props.plugin.call('compilerArtefacts', 'getLastCompilationResult') |
|
|
|
console.log(nodeDefinition) |
|
|
|
const file = await props.plugin.call('fileManager', 'file') |
|
|
|
const contents = [] |
|
|
|
if (compilationResult && compilationResult.data && compilationResult.data.sources[file]) { |
|
|
|
if (!nodeDefinition) return null |
|
|
|
const nodes = sourceMappingDecoder.nodesAtPosition(null, cursorPosition, compilationResult.data.sources[file]) |
|
|
|
if (nodeDefinition.absolutePath) { |
|
|
|
// console.log(cursorPosition, nodes)
|
|
|
|
const target = await props.plugin.call('fileManager', 'getPathFromUrl', nodeDefinition.absolutePath) |
|
|
|
// loop over nodes
|
|
|
|
if (target.file !== nodeDefinition.absolutePath) { |
|
|
|
if (nodes && nodes.length) { |
|
|
|
contents.push({ |
|
|
|
nodes.forEach((node) => { |
|
|
|
value: `${target.file}` |
|
|
|
const position = sourceMappingDecoder.decode(node.src) |
|
|
|
}) |
|
|
|
const fileTarget = compilationResult.getSourceName(position.file) |
|
|
|
} |
|
|
|
// console.log(position, fileTarget)
|
|
|
|
contents.push({ |
|
|
|
|
|
|
|
value: `${nodeDefinition.absolutePath}` |
|
|
|
}) |
|
|
|
}) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
if (nodeDefinition.typeDescriptions && nodeDefinition.nodeType === 'VariableDeclaration') { |
|
|
|
|
|
|
|
contents.push({ |
|
|
|
|
|
|
|
value: `${nodeDefinition.typeDescriptions.typeString} ${nodeDefinition.name}` |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
else if (nodeDefinition.typeDescriptions && nodeDefinition.nodeType === 'ElementaryTypeName') { |
|
|
|
|
|
|
|
contents.push({ |
|
|
|
|
|
|
|
value: `${nodeDefinition.typeDescriptions.typeString}` |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
contents.push({ |
|
|
|
|
|
|
|
value: `${nodeDefinition.nodeType}` |
|
|
|
|
|
|
|
}) |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
for (const key in contents) { |
|
|
|
|
|
|
|
contents[key].value = '```remix-solidity\n' + contents[key].value + '\n```' |
|
|
|
} |
|
|
|
} |
|
|
|
return { |
|
|
|
return { |
|
|
|
range: new monaco.Range( |
|
|
|
range: new monaco.Range( |
|
|
@ -487,9 +516,7 @@ export const EditorUI = (props: EditorUIProps) => { |
|
|
|
position.lineNumber, |
|
|
|
position.lineNumber, |
|
|
|
model.getLineMaxColumn(position.lineNumber) |
|
|
|
model.getLineMaxColumn(position.lineNumber) |
|
|
|
), |
|
|
|
), |
|
|
|
contents: [ |
|
|
|
contents: contents |
|
|
|
|
|
|
|
|
|
|
|
] |
|
|
|
|
|
|
|
}; |
|
|
|
}; |
|
|
|
} |
|
|
|
} |
|
|
|
}) |
|
|
|
}) |
|
|
|