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. 12
      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) { async nodesAtEditorPosition(position: any) {
const lastCompilationResult = await this.call('compilerArtefacts', 'getLastCompilationResult') const lastCompilationResult = await this.call('compilerArtefacts', 'getLastCompilationResult')
if (!lastCompilationResult) return false
let urlFromPath = await this.call('fileManager', 'getUrlFromPath', this.currentFile) let urlFromPath = await this.call('fileManager', 'getUrlFromPath', this.currentFile)
if (lastCompilationResult && lastCompilationResult.languageversion.indexOf('soljson') === 0 && lastCompilationResult.data) { 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]) 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 return nodeDefinition
}else{ }else{
console.log('no node found') return false
} }
} }

@ -11,6 +11,7 @@ export class RemixHoverProvider {
provideHover = async function (model: any, position: any) { provideHover = async function (model: any, position: any) {
const cursorPosition = this.props.editorAPI.getHoverPosition(position) const cursorPosition = this.props.editorAPI.getHoverPosition(position)
const nodeDefinition = await this.props.plugin.call('contextualListener', 'definitionAtPosition', cursorPosition) const nodeDefinition = await this.props.plugin.call('contextualListener', 'definitionAtPosition', cursorPosition)
console.log(nodeDefinition) console.log(nodeDefinition)
const contents = [] const contents = []
@ -49,6 +50,7 @@ export class RemixHoverProvider {
} }
} }
const getParamaters = async (parameters: any) => { const getParamaters = async (parameters: any) => {
if (parameters && parameters.parameters) { if (parameters && parameters.parameters) {
let params = [] let params = []
@ -84,7 +86,13 @@ export class RemixHoverProvider {
return '' return ''
} }
if (!nodeDefinition) return null if (!nodeDefinition) {
contents.push({
value: 'No definition found. Please compile the source code.'
})
}
if (nodeDefinition) {
if (nodeDefinition.absolutePath) { if (nodeDefinition.absolutePath) {
const target = await this.props.plugin.call('fileManager', 'getPathFromUrl', nodeDefinition.absolutePath) const target = await this.props.plugin.call('fileManager', 'getPathFromUrl', nodeDefinition.absolutePath)
if (target.file !== nodeDefinition.absolutePath) { if (target.file !== nodeDefinition.absolutePath) {
@ -132,6 +140,8 @@ export class RemixHoverProvider {
getLinks(nodeDefinition) getLinks(nodeDefinition)
getDocs(nodeDefinition) getDocs(nodeDefinition)
}
return { return {
range: new this.monaco.Range( 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 { IPosition, languages } from 'monaco-editor'
import { sourceMappingDecoder } from '@remix-project/remix-debug' import { sourceMappingDecoder } from '@remix-project/remix-debug'
import { RemixHoverProvider } from './providers/hoverProvider' import { RemixHoverProvider } from './providers/hoverProvider'
import { RemixReferenceProvider } from './providers/referenceProvider'
type cursorPosition = { type cursorPosition = {
startLineNumber: number, startLineNumber: number,
@ -434,45 +435,7 @@ export const EditorUI = (props: EditorUIProps) => {
} }
}) })
monacoRef.current.languages.registerReferenceProvider('remix-solidity', { monacoRef.current.languages.registerReferenceProvider('remix-solidity', new RemixReferenceProvider(props, monaco))
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.registerHoverProvider('remix-solidity', new RemixHoverProvider(props, monaco)) monacoRef.current.languages.registerHoverProvider('remix-solidity', new RemixHoverProvider(props, monaco))
loadTypes(monacoRef.current) loadTypes(monacoRef.current)

Loading…
Cancel
Save