filter nodes

editorcontextDummy
filip mertens 2 years ago
parent 0d58c07136
commit 65b56cf9d6
  1. 34
      libs/remix-ui/editor/src/lib/providers/completionProvider.ts

@ -57,11 +57,15 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
if (lastNodeInExpression.name === 'this') { if (lastNodeInExpression.name === 'this') {
dotCompleted = true dotCompleted = true
let thisCompletionNodes = await this.getContractCompletions(nodes, position) let thisCompletionNodes = await this.getContractCompletions(nodes, position)
thisCompletionNodes = thisCompletionNodes.filter(node =>
{ // with this. you can't have internal nodes and no contractDefinitions
thisCompletionNodes = thisCompletionNodes.filter(node => {
if (node.visibility && node.visibility === 'internal') { if (node.visibility && node.visibility === 'internal') {
return false return false
} }
if(node.nodeType && node.nodeType === 'ContractDefinition') {
return false
}
return true return true
}) })
nodes = [...nodes, ...thisCompletionNodes] nodes = [...nodes, ...thisCompletionNodes]
@ -154,7 +158,15 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
...GetGlobalFunctions(range, this.monaco), ...GetGlobalFunctions(range, this.monaco),
...GeCompletionUnits(range, this.monaco), ...GeCompletionUnits(range, this.monaco),
] ]
nodes = [...nodes, ...await this.getContractCompletions(nodes, position)] let thisCompletionNodes = await this.getContractCompletions(nodes, position)
// we can't have external nodes without using this.
thisCompletionNodes = thisCompletionNodes.filter(node => {
if (node.visibility && node.visibility === 'external') {
return false
}
return true
})
nodes = [...nodes, ...thisCompletionNodes]
} }
@ -321,6 +333,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
if (isArray(nodesAtPosition) && nodesAtPosition.length) { if (isArray(nodesAtPosition) && nodesAtPosition.length) {
for (const node of nodesAtPosition) { for (const node of nodesAtPosition) {
const nodesOfScope = await this.props.plugin.call('codeParser', 'getNodesWithScope', node.id) const nodesOfScope = await this.props.plugin.call('codeParser', 'getNodesWithScope', node.id)
for (const nodeOfScope of nodesOfScope) { for (const nodeOfScope of nodesOfScope) {
const imports = await this.props.plugin.call('codeParser', 'resolveImports', nodeOfScope) const imports = await this.props.plugin.call('codeParser', 'resolveImports', nodeOfScope)
if (imports) { if (imports) {
@ -330,6 +343,12 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
} }
} }
} }
// if the node is a contract at this positio mark the nodes as the contractNodes
if (node.nodeType === 'ContractDefinition') {
for (const node of nodesOfScope) {
node.isInContract = true
}
}
nodes = [...nodes, ...nodesOfScope] nodes = [...nodes, ...nodesOfScope]
} }
// get the linearized base contracts // get the linearized base contracts
@ -344,6 +363,15 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
nodes = [...nodes, ...await this.props.plugin.call('codeParser', 'listAstNodes')] nodes = [...nodes, ...await this.props.plugin.call('codeParser', 'listAstNodes')]
} }
// filter private nodes, only allow them when isContract is true
nodes = nodes.filter(node => {
if (node.visibility) {
if (!node.isInContract) {
return node.visibility !== 'private'
}
}
return true
})
return nodes return nodes
} }

Loading…
Cancel
Save