mv ref class

pull/5370/head
filip mertens 3 years ago
parent 9903038b28
commit 10889e5684
  1. 3
      libs/remix-core-plugin/src/lib/editor-context-listener.ts
  2. 84
      libs/remix-ui/editor/src/lib/providers/hoverProvider.ts
  3. 47
      libs/remix-ui/editor/src/lib/providers/referenceProvider.ts
  4. 41
      libs/remix-ui/editor/src/lib/remix-ui-editor.tsx

@ -117,6 +117,7 @@ export class EditorContextListener extends Plugin {
async nodesAtEditorPosition(position: any) {
const lastCompilationResult = await this.call('compilerArtefacts', 'getLastCompilationResult')
if (!lastCompilationResult) return false
let urlFromPath = await this.call('fileManager', 'getUrlFromPath', this.currentFile)
if (lastCompilationResult && lastCompilationResult.languageversion.indexOf('soljson') === 0 && lastCompilationResult.data) {
const nodes = sourceMappingDecoder.nodesAtPosition(null, position, lastCompilationResult.data.sources[this.currentFile] || lastCompilationResult.data.sources[urlFromPath.file])
@ -164,7 +165,7 @@ export class EditorContextListener extends Plugin {
}
return nodeDefinition
}else{
console.log('no node found')
return false
}
}

@ -11,6 +11,7 @@ export class RemixHoverProvider {
provideHover = async function (model: any, position: any) {
const cursorPosition = this.props.editorAPI.getHoverPosition(position)
const nodeDefinition = await this.props.plugin.call('contextualListener', 'definitionAtPosition', cursorPosition)
console.log(nodeDefinition)
const contents = []
@ -48,6 +49,7 @@ export class RemixHoverProvider {
return `${node.typeDescriptions.typeString}${node.name && node.name.length ? ` ${node.name}` : ''}`
}
}
const getParamaters = async (parameters: any) => {
if (parameters && parameters.parameters) {
@ -84,54 +86,62 @@ export class RemixHoverProvider {
return ''
}
if (!nodeDefinition) return null
if (nodeDefinition.absolutePath) {
const target = await this.props.plugin.call('fileManager', 'getPathFromUrl', nodeDefinition.absolutePath)
if (target.file !== nodeDefinition.absolutePath) {
if (!nodeDefinition) {
contents.push({
value: 'No definition found. Please compile the source code.'
})
}
if (nodeDefinition) {
if (nodeDefinition.absolutePath) {
const target = await this.props.plugin.call('fileManager', 'getPathFromUrl', nodeDefinition.absolutePath)
if (target.file !== nodeDefinition.absolutePath) {
contents.push({
value: `${target.file}`
})
}
contents.push({
value: `${target.file}`
value: `${nodeDefinition.absolutePath}`
})
}
contents.push({
value: `${nodeDefinition.absolutePath}`
})
}
if (nodeDefinition.typeDescriptions && nodeDefinition.nodeType === 'VariableDeclaration') {
contents.push({
value: await getVariableDeclaration(nodeDefinition)
})
if (nodeDefinition.typeDescriptions && nodeDefinition.nodeType === 'VariableDeclaration') {
contents.push({
value: await getVariableDeclaration(nodeDefinition)
})
}
else if (nodeDefinition.typeDescriptions && nodeDefinition.nodeType === 'ElementaryTypeName') {
contents.push({
value: `${nodeDefinition.typeDescriptions.typeString}`
})
}
else if (nodeDefinition.typeDescriptions && nodeDefinition.nodeType === 'ElementaryTypeName') {
contents.push({
value: `${nodeDefinition.typeDescriptions.typeString}`
})
} else if (nodeDefinition.nodeType === 'FunctionDefinition') {
contents.push({
value: `function ${nodeDefinition.name} ${await getParamaters(nodeDefinition.parameters)} ${nodeDefinition.visibility} ${nodeDefinition.stateMutability}${await getOverrides(nodeDefinition)} returns ${await getParamaters(nodeDefinition.returnParameters)}`
})
} else if (nodeDefinition.nodeType === 'FunctionDefinition') {
contents.push({
value: `function ${nodeDefinition.name} ${await getParamaters(nodeDefinition.parameters)} ${nodeDefinition.visibility} ${nodeDefinition.stateMutability}${await getOverrides(nodeDefinition)} returns ${await getParamaters(nodeDefinition.returnParameters)}`
})
} else if (nodeDefinition.nodeType === 'ContractDefinition') {
contents.push({
value: `${nodeDefinition.contractKind} ${nodeDefinition.name} ${await getlinearizedBaseContracts(nodeDefinition)}`
})
} else if (nodeDefinition.nodeType === 'ContractDefinition') {
contents.push({
value: `${nodeDefinition.contractKind} ${nodeDefinition.name} ${await getlinearizedBaseContracts(nodeDefinition)}`
})
} else {
contents.push({
value: `${nodeDefinition.nodeType}`
})
}
} else {
contents.push({
value: `${nodeDefinition.nodeType}`
})
}
for (const key in contents) {
contents[key].value = '```remix-solidity\n' + contents[key].value + '\n```'
}
getLinks(nodeDefinition)
getDocs(nodeDefinition)
for (const key in contents) {
contents[key].value = '```remix-solidity\n' + contents[key].value + '\n```'
}
getLinks(nodeDefinition)
getDocs(nodeDefinition)
return {
range: new this.monaco.Range(

@ -0,0 +1,47 @@
import { sourceMappingDecoder } from "@remix-project/remix-debug"
export class RemixReferenceProvider {
props: any
monaco: any
constructor(props: any, monaco: any) {
this.props = props
this.monaco = monaco
}
async provideReferences(model: any, position: any, context: any, token: any) {
const cursorPosition = this.props.editorAPI.getCursorPosition()
const nodes = await this.props.plugin.call('contextualListener', 'referrencesAtPosition', cursorPosition)
const references = []
if (nodes && nodes.length) {
const compilationResult = await this.props.plugin.call('compilerArtefacts', 'getLastCompilationResult')
const file = await this.props.plugin.call('fileManager', 'file')
if (compilationResult && compilationResult.data && compilationResult.data.sources[file]) {
for (const node of nodes) {
const position = sourceMappingDecoder.decode(node.src)
const fileInNode = compilationResult.getSourceName(position.file)
let fileTarget = await this.props.plugin.call('fileManager', 'getPathFromUrl', fileInNode)
fileTarget = fileTarget.file
const fileContent = await this.props.plugin.call('fileManager', 'readFile', fileInNode)
const lineColumn = await this.props.plugin.call('offsetToLineColumnConverter', 'offsetToLineColumn',
position,
position.file,
compilationResult.getSourceCode().sources,
compilationResult.getAsts())
console.log(position, fileTarget, lineColumn)
try {
this.props.plugin.call('editor', 'addModel', fileTarget, fileContent)
} catch (e) {
}
const range = new this.monaco.Range(lineColumn.start.line + 1, lineColumn.start.column + 1, lineColumn.end.line + 1, lineColumn.end.column + 1)
references.push({
range,
uri: this.monaco.Uri.parse(fileTarget)
})
}
}
}
return references
}
}

@ -11,6 +11,7 @@ import monaco from '../types/monaco'
import { IPosition, languages } from 'monaco-editor'
import { sourceMappingDecoder } from '@remix-project/remix-debug'
import { RemixHoverProvider } from './providers/hoverProvider'
import { RemixReferenceProvider } from './providers/referenceProvider'
type cursorPosition = {
startLineNumber: number,
@ -434,45 +435,7 @@ export const EditorUI = (props: EditorUIProps) => {
}
})
monacoRef.current.languages.registerReferenceProvider('remix-solidity', {
async provideReferences(model: monaco.editor.ITextModel, position: monaco.Position, context: any, token: monaco.CancellationToken) {
const cursorPosition = props.editorAPI.getCursorPosition()
const nodes = await props.plugin.call('contextualListener', 'referrencesAtPosition', cursorPosition)
const references = []
if (nodes && nodes.length) {
const compilationResult = await props.plugin.call('compilerArtefacts', 'getLastCompilationResult')
const file = await props.plugin.call('fileManager', 'file')
if (compilationResult && compilationResult.data && compilationResult.data.sources[file]) {
for (const node of nodes) {
const position = sourceMappingDecoder.decode(node.src)
const fileInNode = compilationResult.getSourceName(position.file)
let fileTarget = await props.plugin.call('fileManager', 'getPathFromUrl', fileInNode)
fileTarget = fileTarget.file
const fileContent = await props.plugin.call('fileManager', 'readFile', fileInNode)
const lineColumn = await props.plugin.call('offsetToLineColumnConverter', 'offsetToLineColumn',
position,
position.file,
compilationResult.getSourceCode().sources,
compilationResult.getAsts())
console.log(position, fileTarget, lineColumn)
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
}
})
monacoRef.current.languages.registerReferenceProvider('remix-solidity', new RemixReferenceProvider(props, monaco))
monacoRef.current.languages.registerHoverProvider('remix-solidity', new RemixHoverProvider(props, monaco))
loadTypes(monacoRef.current)

Loading…
Cancel
Save