Merge pull request #2967 from ethereum/autocompletetest

fix autocomplete test
pull/5370/head
bunsenstraat 2 years ago committed by GitHub
commit 3d7ce279ee
  1. 11
      libs/remix-ui/editor/src/lib/providers/completionProvider.ts

@ -258,6 +258,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
// if no nodes exits at position, try to get the block of which the position is in // if no nodes exits at position, try to get the block of which the position is in
const block = await this.props.plugin.call('codeParser', 'getANTLRBlockAtPosition', cursorPosition, null) const block = await this.props.plugin.call('codeParser', 'getANTLRBlockAtPosition', cursorPosition, null)
const fileNodes = await this.props.plugin.call('codeParser', 'getCurrentFileNodes') const fileNodes = await this.props.plugin.call('codeParser', 'getCurrentFileNodes')
if (!nodesAtPosition.length) { if (!nodesAtPosition.length) {
if (block) { if (block) {
nodesAtPosition = await this.props.plugin.call('codeParser', 'nodesAtPosition', block.start) nodesAtPosition = await this.props.plugin.call('codeParser', 'nodesAtPosition', block.start)
@ -274,7 +275,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
nodes = [...Object.values(contractNodes.baseNodesWithBaseContractScope), ...nodes] nodes = [...Object.values(contractNodes.baseNodesWithBaseContractScope), ...nodes]
nodes = [...Object.values(fileNodes.imports), ...nodes] nodes = [...Object.values(fileNodes.imports), ...nodes]
// add the nodes at the block itself // add the nodes at the block itself
if (node.nodeType === 'ContractDefinition' && block && block.name) { if (block && block.name) {
const contractNodes = fileNodes.contracts[node.name].contractNodes const contractNodes = fileNodes.contracts[node.name].contractNodes
for (const contractNode of Object.values(contractNodes)) { for (const contractNode of Object.values(contractNodes)) {
if (contractNode['name'] === block.name if (contractNode['name'] === block.name
@ -288,6 +289,14 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
} }
} }
} }
} else { // we use the block info from the nodesAtPosition
const contractNodes = fileNodes.contracts[node.name].contractNodes
for (const contractNode of Object.values(contractNodes)) {
if((contractNode as any).nodeType === 'Block'){
const nodeOfScope = await this.props.plugin.call('codeParser', 'getNodesWithScope', (contractNode as any).id)
nodes = [...nodes, ...nodeOfScope]
}
}
} }
// filter private nodes, only allow them when contract ID is the same as the current contract // filter private nodes, only allow them when contract ID is the same as the current contract
nodes = nodes.filter(node => { nodes = nodes.filter(node => {

Loading…
Cancel
Save