From aeeb3d1cf19aec736c0a6dcef1f07bce105fbb6e Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 14 Sep 2022 18:43:51 +0200 Subject: [PATCH 01/12] add imports to autodcomplete --- .../providers/completion/completionGlobals.ts | 268 +++++++++++++++++- .../src/lib/providers/completionProvider.ts | 131 +++++---- 2 files changed, 337 insertions(+), 62 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts index a3dd0f05e8..de64477848 100644 --- a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts +++ b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts @@ -330,10 +330,10 @@ function CreateCompletionItem(label: string, kind: monaco.languages.CompletionIt export function GetCompletionKeywords(range: IRange, monaco): monaco.languages.CompletionItem[] { const completionItems = []; const keywords = ['modifier', 'mapping', 'break', 'continue', 'delete', 'else', 'for', - 'after', 'promise', 'alias', 'apply','auto', 'copyof', 'default', 'define', 'final', 'implements', + 'after', 'promise', 'alias', 'apply', 'auto', 'copyof', 'default', 'define', 'final', 'implements', 'inline', 'let', 'macro', 'match', 'mutable', 'null', 'of', 'partial', 'reference', 'relocatable', 'sealed', 'sizeof', 'static', 'supports', 'switch', 'typedef', - 'if', 'new', 'return', 'returns', 'while', 'using', 'emit', 'anonymous', 'indexed', + 'if', 'new', 'return', 'returns', 'while', 'using', 'emit', 'anonymous', 'indexed', 'private', 'public', 'external', 'internal', 'payable', 'nonpayable', 'view', 'pure', 'case', 'do', 'else', 'finally', 'in', 'instanceof', 'return', 'throw', 'try', 'catch', 'typeof', 'yield', 'void', 'virtual', 'override']; keywords.forEach(unit => { @@ -389,6 +389,268 @@ export function GeCompletionUnits(range: IRange, monaco): monaco.languages.Compl return completionItems; } +export function GetImports(range: IRange, monaco): monaco.languages.CompletionItem[] { + let list = [ + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC20/ERC20.sol', + label: 'OZ ERC20', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC721/ERC721.sol', + label: 'OZ ERC721', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/access/Ownable.sol', + label: 'OZ Ownable', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/Counters.sol', + label: 'OZ Counters', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/Address.sol', + label: 'OZ Address', + range + }, + { + detail: '@openzeppelin/contracts/utils/Context.sol', + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/Context.sol', + label: 'OZ Context', + range + }, + { + detail: '@openzeppelin/contracts/utils/EnumerableSet.sol', + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/EnumerableSet.sol', + label: 'OZ EnumerableSet', + range + }, + { + detail: '@openzeppelin/contracts/utils/EnumerableMap.sol', + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/EnumerableMap.sol', + label: 'OZ EnumerableMap', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/Strings.sol', + label: 'OZ Strings', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/ReentrancyGuard.sol', + label: 'OZ ReentrancyGuard', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/Pausable.sol', + label: 'OZ Pausable', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/structs/EnumerableSet.sol', + label: 'OZ EnumerableSet', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/structs/EnumerableMap.sol', + label: 'OZ EnumerableMap', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/math/SafeMath.sol', + label: 'OZ SafeMath', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/math/SafeCast.sol', + label: 'OZ SafeCast', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/math/Math.sol', + label: 'OZ Math', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/math/SignedSafeMath.sol', + label: 'OZ SignedSafeMath', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/math/SafeMath.sol', + label: 'OZ SafeMath', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/utils/math/SafeCast.sol', + label: 'OZ SafeCast', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol', + label: 'OZ ERC20Burnable', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol', + label: 'OZ ERC20Pausable', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol', + label: 'OZ ERC20Snapshot', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol', + label: 'OZ ERC20Permit', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Votes.sol', + label: 'OZ ERC20Votes', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC1155/ERC1155.sol', + label: 'OZ ERC1155', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC20/IERC20.sol', + label: 'OZ IERC20', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC721/IERC721.sol', + label: 'OZ IERC721', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC1155/IERC1155.sol', + label: 'OZ IERC1155', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC20/IERC20Metadata.sol', + label: 'OZ IERC20Metadata', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol', + label: 'OZ IERC721Metadata', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC1155/IERC1155MetadataURI.sol', + label: 'OZ IERC1155MetadataURI', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol', + label: 'OZ IERC1155Receiver', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol', + label: 'OZ IERC721Receiver', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol', + label: 'OZ SafeERC20', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/governance/Governor.sol', + label: 'OZ Governor', + range + }, + { + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol', + label: 'OZ GovernorCountingSimple', + range + + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/governance/extensions/GovernorVotes.sol', + label: 'OZ GovernorVotes', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol', + label: 'OZ GovernorVotesQuorumFraction', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/governance/extensions/GovernorTimelockCompound.sol', + label: 'OZ GovernorTimelockCompound', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol', + label: 'OZ GovernorTimelockControl', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol', + label: 'OZ GovernorCountingSimple', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/governance/extensions/GovernorSettings.sol', + label: 'OZ GovernorSettings', + range + },{ + kind: monaco.languages.CompletionItemKind.Module, + insertText: '@openzeppelin/contracts/governance/extensions/GovernorCompatibilityBravo.sol', + label: 'OZ GovernorCompatibilityBravo', + range + } + ] + list = list.map((item) => { + return { + ...item, + label: `${item.label}: ${item.insertText}`, + } + }) + console.log(list) + return list; +}; export function GetGlobalVariable(range: IRange, monaco): monaco.languages.CompletionItem[] { return [ @@ -668,7 +930,7 @@ export function getAddressCompletionItems(range: IRange, monaco): monaco.languag ] } - + export function getContextualAutoCompleteBTypeName(word: string, range: IRange, monaco): monaco.languages.CompletionItem[] { if (word === 'ArrayTypeName') { return getArrayCompletionItems(range, monaco); diff --git a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts index 745c5e395b..c9b88c9805 100644 --- a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts @@ -4,7 +4,7 @@ import { isArray } from "lodash" import { editor, languages, Position } from "monaco-editor" import monaco from "../../types/monaco" import { EditorUIProps } from "../remix-ui-editor" -import { GeCompletionUnits, GetCompletionKeywords, getCompletionSnippets, GetCompletionTypes, getContextualAutoCompleteBTypeName, getContextualAutoCompleteByGlobalVariable, GetGlobalFunctions, GetGlobalVariable } from "./completion/completionGlobals" +import { GeCompletionUnits, GetCompletionKeywords, getCompletionSnippets, GetCompletionTypes, getContextualAutoCompleteBTypeName, getContextualAutoCompleteByGlobalVariable, GetGlobalFunctions, GetGlobalVariable, GetImports } from "./completion/completionGlobals" export class RemixCompletionProvider implements languages.CompletionItemProvider { @@ -16,11 +16,11 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider this.monaco = monaco } - triggerCharacters = ['.', ''] + triggerCharacters = ['.', '', '"'] async provideCompletionItems(model: editor.ITextModel, position: Position, context: monaco.languages.CompletionContext): Promise { const completionSettings = await this.props.plugin.call('config', 'getAppParameter', 'settings/auto-completion') - if(!completionSettings) return + if (!completionSettings) return const word = model.getWordUntilPosition(position); const range = { startLineNumber: position.lineNumber, @@ -33,62 +33,75 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider let nodes: AstNode[] = [] let suggestions: monaco.languages.CompletionItem[] = [] - if (context.triggerCharacter === '.') { - const lineTextBeforeCursor: string = line.substring(0, position.column - 1) - const lastNodeInExpression = await this.getLastNodeInExpression(lineTextBeforeCursor) - const expressionElements = lineTextBeforeCursor.split('.') + if (context.triggerCharacter === '"') { - let dotCompleted = false + const ast = await this.props.plugin.call('codeParser', 'parseSolidity', line) + if (ast && ast.children && ast.children[0] && ast.children[0].type === "ImportDirective") { + suggestions = [...suggestions, + ...GetImports(range, this.monaco), + ] - // handles completion from for builtin types - if(lastNodeInExpression.memberName === 'sender') { // exception for this member - lastNodeInExpression.name = 'sender' + }else{ + return } - const globalCompletion = getContextualAutoCompleteByGlobalVariable(lastNodeInExpression.name, range, this.monaco) - if (globalCompletion) { - dotCompleted = true - suggestions = [...suggestions, ...globalCompletion] - setTimeout(() => { - // eslint-disable-next-line no-debugger - // debugger - }, 2000) - } - // handle completion for global THIS. - if (lastNodeInExpression.name === 'this') { - dotCompleted = true - nodes = [...nodes, ...await this.getThisCompletions(position)] - } - // handle completion for other dot completions - if (expressionElements.length > 1 && !dotCompleted) { + } else - const nameOfLastTypedExpression = lastNodeInExpression.name || lastNodeInExpression.memberName - const dotCompletions = await this.getDotCompletions(position, nameOfLastTypedExpression, range) - nodes = [...nodes, ...dotCompletions.nodes] - suggestions = [...suggestions, ...dotCompletions.suggestions] - } - } else { + if (context.triggerCharacter === '.') { + const lineTextBeforeCursor: string = line.substring(0, position.column - 1) + const lastNodeInExpression = await this.getLastNodeInExpression(lineTextBeforeCursor) + const expressionElements = lineTextBeforeCursor.split('.') - // handles contract completions and other suggestions - suggestions = [...suggestions, - ...GetGlobalVariable(range, this.monaco), - ...getCompletionSnippets(range, this.monaco), - ...GetCompletionTypes(range, this.monaco), - ...GetCompletionKeywords(range, this.monaco), - ...GetGlobalFunctions(range, this.monaco), - ...GeCompletionUnits(range, this.monaco), - ] - let contractCompletions = await this.getContractCompletions(position) + let dotCompleted = false - // we can't have external nodes without using this. - contractCompletions = contractCompletions.filter(node => { - if (node.visibility && node.visibility === 'external') { - return false + // handles completion from for builtin types + if (lastNodeInExpression.memberName === 'sender') { // exception for this member + lastNodeInExpression.name = 'sender' } - return true - }) - nodes = [...nodes, ...contractCompletions] + const globalCompletion = getContextualAutoCompleteByGlobalVariable(lastNodeInExpression.name, range, this.monaco) + if (globalCompletion) { + dotCompleted = true + suggestions = [...suggestions, ...globalCompletion] + setTimeout(() => { + // eslint-disable-next-line no-debugger + // debugger + }, 2000) + } + // handle completion for global THIS. + if (lastNodeInExpression.name === 'this') { + dotCompleted = true + nodes = [...nodes, ...await this.getThisCompletions(position)] + } + // handle completion for other dot completions + if (expressionElements.length > 1 && !dotCompleted) { - } + const nameOfLastTypedExpression = lastNodeInExpression.name || lastNodeInExpression.memberName + const dotCompletions = await this.getDotCompletions(position, nameOfLastTypedExpression, range) + nodes = [...nodes, ...dotCompletions.nodes] + suggestions = [...suggestions, ...dotCompletions.suggestions] + } + } else { + + // handles contract completions and other suggestions + suggestions = [...suggestions, + ...GetGlobalVariable(range, this.monaco), + ...getCompletionSnippets(range, this.monaco), + ...GetCompletionTypes(range, this.monaco), + ...GetCompletionKeywords(range, this.monaco), + ...GetGlobalFunctions(range, this.monaco), + ...GeCompletionUnits(range, this.monaco), + ] + let contractCompletions = await this.getContractCompletions(position) + + // we can't have external nodes without using this. + contractCompletions = contractCompletions.filter(node => { + if (node.visibility && node.visibility === 'external') { + return false + } + return true + }) + nodes = [...nodes, ...contractCompletions] + + } // remove duplicates const nodeIds = {}; @@ -220,7 +233,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider } suggestions.push(completion) - } + } } return { @@ -242,9 +255,9 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider // try to find the real block in the AST and get the nodes in that scope if (node.nodeType === 'ContractDefinition') { const contractNodes = fileNodes.contracts[node.name].contractNodes - for (const contractNode of Object.values(contractNodes)) { - if (contractNode['name'] === ANTLRBlock.name - || (contractNode['kind'] === 'constructor' && ANTLRBlock.name === null ) + for (const contractNode of Object.values(contractNodes)) { + if (contractNode['name'] === ANTLRBlock.name + || (contractNode['kind'] === 'constructor' && ANTLRBlock.name === null) ) { let nodeOfScope = await this.props.plugin.call('codeParser', 'getNodesWithScope', (contractNode as any).id) nodes = [...nodes, ...nodeOfScope] @@ -270,7 +283,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider */ } } - + // we are only interested in nodes that are in the same block as the cursor nodes = nodes.filter(node => { if (node.src) { @@ -279,7 +292,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider return true } } - if(node.outSideBlock){ return true } + if (node.outSideBlock) { return true } return false }) @@ -387,9 +400,9 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider nodes = [...nodes, ...filterNodes(nodeOfScope.members, nodeOfScope)] } else if (nodeOfScope.typeName && nodeOfScope.typeName.nodeType === 'ArrayTypeName') { suggestions = [...suggestions, ...getContextualAutoCompleteBTypeName('ArrayTypeName', range, this.monaco)] - } else if(nodeOfScope.typeName && nodeOfScope.typeName.nodeType === 'ElementaryTypeName' && nodeOfScope.typeName.name === 'bytes') { + } else if (nodeOfScope.typeName && nodeOfScope.typeName.nodeType === 'ElementaryTypeName' && nodeOfScope.typeName.name === 'bytes') { suggestions = [...suggestions, ...getContextualAutoCompleteBTypeName('bytes', range, this.monaco)] - } else if(nodeOfScope.typeName && nodeOfScope.typeName.nodeType === 'ElementaryTypeName' && nodeOfScope.typeName.name === 'address') { + } else if (nodeOfScope.typeName && nodeOfScope.typeName.nodeType === 'ElementaryTypeName' && nodeOfScope.typeName.name === 'address') { suggestions = [...suggestions, ...getContextualAutoCompleteBTypeName('address', range, this.monaco)] } } From ae41e0803fd83f493d4042be9bb9b1b9a2d78e49 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 14 Sep 2022 19:37:27 +0200 Subject: [PATCH 02/12] use generated list --- .../providers/completion/completionGlobals.ts | 275 ++--------------- .../contracts/OpenZeppelinContracts.txt | 278 ++++++++++++++++++ 2 files changed, 298 insertions(+), 255 deletions(-) create mode 100644 libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt diff --git a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts index de64477848..88c2369f5a 100644 --- a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts +++ b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts @@ -1,5 +1,16 @@ import { IRange } from "monaco-editor"; import monaco from "../../../types/monaco"; +import path from "path"; +let OZContracts; + +// @ts-ignore +import('raw-loader!libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt').then( + (txt) => { + // eslint-disable-next-line @typescript-eslint/no-unused-vars + OZContracts = txt.default.split('\n').filter(x => !x.includes('mock')) + } +) + export function getStringCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { return [ @@ -390,262 +401,16 @@ export function GeCompletionUnits(range: IRange, monaco): monaco.languages.Compl return completionItems; } export function GetImports(range: IRange, monaco): monaco.languages.CompletionItem[] { - let list = [ - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC20/ERC20.sol', - label: 'OZ ERC20', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC721/ERC721.sol', - label: 'OZ ERC721', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/access/Ownable.sol', - label: 'OZ Ownable', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/Counters.sol', - label: 'OZ Counters', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/Address.sol', - label: 'OZ Address', - range - }, - { - detail: '@openzeppelin/contracts/utils/Context.sol', - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/Context.sol', - label: 'OZ Context', - range - }, - { - detail: '@openzeppelin/contracts/utils/EnumerableSet.sol', - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/EnumerableSet.sol', - label: 'OZ EnumerableSet', - range - }, - { - detail: '@openzeppelin/contracts/utils/EnumerableMap.sol', - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/EnumerableMap.sol', - label: 'OZ EnumerableMap', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/Strings.sol', - label: 'OZ Strings', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/ReentrancyGuard.sol', - label: 'OZ ReentrancyGuard', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/Pausable.sol', - label: 'OZ Pausable', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/structs/EnumerableSet.sol', - label: 'OZ EnumerableSet', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/structs/EnumerableMap.sol', - label: 'OZ EnumerableMap', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/math/SafeMath.sol', - label: 'OZ SafeMath', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/math/SafeCast.sol', - label: 'OZ SafeCast', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/math/Math.sol', - label: 'OZ Math', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/math/SignedSafeMath.sol', - label: 'OZ SignedSafeMath', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/math/SafeMath.sol', - label: 'OZ SafeMath', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/utils/math/SafeCast.sol', - label: 'OZ SafeCast', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol', - label: 'OZ ERC20Burnable', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol', - label: 'OZ ERC20Pausable', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol', - label: 'OZ ERC20Snapshot', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol', - label: 'OZ ERC20Permit', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Votes.sol', - label: 'OZ ERC20Votes', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC1155/ERC1155.sol', - label: 'OZ ERC1155', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC20/IERC20.sol', - label: 'OZ IERC20', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC721/IERC721.sol', - label: 'OZ IERC721', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC1155/IERC1155.sol', - label: 'OZ IERC1155', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC20/IERC20Metadata.sol', - label: 'OZ IERC20Metadata', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC721/IERC721Metadata.sol', - label: 'OZ IERC721Metadata', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC1155/IERC1155MetadataURI.sol', - label: 'OZ IERC1155MetadataURI', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol', - label: 'OZ IERC1155Receiver', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol', - label: 'OZ IERC721Receiver', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol', - label: 'OZ SafeERC20', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/governance/Governor.sol', - label: 'OZ Governor', - range - }, - { - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol', - label: 'OZ GovernorCountingSimple', - range - - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/governance/extensions/GovernorVotes.sol', - label: 'OZ GovernorVotes', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol', - label: 'OZ GovernorVotesQuorumFraction', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/governance/extensions/GovernorTimelockCompound.sol', - label: 'OZ GovernorTimelockCompound', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol', - label: 'OZ GovernorTimelockControl', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol', - label: 'OZ GovernorCountingSimple', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/governance/extensions/GovernorSettings.sol', - label: 'OZ GovernorSettings', - range - },{ - kind: monaco.languages.CompletionItemKind.Module, - insertText: '@openzeppelin/contracts/governance/extensions/GovernorCompatibilityBravo.sol', - label: 'OZ GovernorCompatibilityBravo', - range - } - ] - list = list.map((item) => { + let list = [] + list.filter + list = OZContracts + .map((item) => { + const filename = path.basename(item) return { - ...item, - label: `${item.label}: ${item.insertText}`, + kind: monaco.languages.CompletionItemKind.Module, + range: range, + label: `OZ ${filename}: ${item}`, + insertText: `@openzeppelin${item}`, } }) console.log(list) diff --git a/libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt b/libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt new file mode 100644 index 0000000000..cffe37a8a7 --- /dev/null +++ b/libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt @@ -0,0 +1,278 @@ +/contracts/access/AccessControl.sol +/contracts/access/AccessControlCrossChain.sol +/contracts/access/AccessControlEnumerable.sol +/contracts/access/IAccessControl.sol +/contracts/access/IAccessControlEnumerable.sol +/contracts/access/Ownable.sol +/contracts/access/Ownable2Step.sol +/contracts/crosschain/amb/CrossChainEnabledAMB.sol +/contracts/crosschain/amb/LibAMB.sol +/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL1.sol +/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL2.sol +/contracts/crosschain/arbitrum/LibArbitrumL1.sol +/contracts/crosschain/arbitrum/LibArbitrumL2.sol +/contracts/crosschain/CrossChainEnabled.sol +/contracts/crosschain/errors.sol +/contracts/crosschain/optimism/CrossChainEnabledOptimism.sol +/contracts/crosschain/optimism/LibOptimism.sol +/contracts/crosschain/polygon/CrossChainEnabledPolygonChild.sol +/contracts/finance/PaymentSplitter.sol +/contracts/finance/VestingWallet.sol +/contracts/governance/compatibility/GovernorCompatibilityBravo.sol +/contracts/governance/compatibility/IGovernorCompatibilityBravo.sol +/contracts/governance/extensions/GovernorCountingSimple.sol +/contracts/governance/extensions/GovernorPreventLateQuorum.sol +/contracts/governance/extensions/GovernorProposalThreshold.sol +/contracts/governance/extensions/GovernorSettings.sol +/contracts/governance/extensions/GovernorTimelockCompound.sol +/contracts/governance/extensions/GovernorTimelockControl.sol +/contracts/governance/extensions/GovernorVotes.sol +/contracts/governance/extensions/GovernorVotesComp.sol +/contracts/governance/extensions/GovernorVotesQuorumFraction.sol +/contracts/governance/extensions/IGovernorTimelock.sol +/contracts/governance/Governor.sol +/contracts/governance/IGovernor.sol +/contracts/governance/TimelockController.sol +/contracts/governance/utils/IVotes.sol +/contracts/governance/utils/Votes.sol +/contracts/interfaces/draft-IERC1822.sol +/contracts/interfaces/draft-IERC2612.sol +/contracts/interfaces/IERC1155.sol +/contracts/interfaces/IERC1155MetadataURI.sol +/contracts/interfaces/IERC1155Receiver.sol +/contracts/interfaces/IERC1271.sol +/contracts/interfaces/IERC1363.sol +/contracts/interfaces/IERC1363Receiver.sol +/contracts/interfaces/IERC1363Spender.sol +/contracts/interfaces/IERC165.sol +/contracts/interfaces/IERC1820Implementer.sol +/contracts/interfaces/IERC1820Registry.sol +/contracts/interfaces/IERC20.sol +/contracts/interfaces/IERC20Metadata.sol +/contracts/interfaces/IERC2309.sol +/contracts/interfaces/IERC2981.sol +/contracts/interfaces/IERC3156.sol +/contracts/interfaces/IERC3156FlashBorrower.sol +/contracts/interfaces/IERC3156FlashLender.sol +/contracts/interfaces/IERC4626.sol +/contracts/interfaces/IERC721.sol +/contracts/interfaces/IERC721Enumerable.sol +/contracts/interfaces/IERC721Metadata.sol +/contracts/interfaces/IERC721Receiver.sol +/contracts/interfaces/IERC777.sol +/contracts/interfaces/IERC777Recipient.sol +/contracts/interfaces/IERC777Sender.sol +/contracts/metatx/ERC2771Context.sol +/contracts/metatx/MinimalForwarder.sol +/contracts/mocks/AccessControlCrossChainMock.sol +/contracts/mocks/AccessControlEnumerableMock.sol +/contracts/mocks/AccessControlMock.sol +/contracts/mocks/AddressImpl.sol +/contracts/mocks/ArraysMock.sol +/contracts/mocks/BadBeacon.sol +/contracts/mocks/Base64Mock.sol +/contracts/mocks/BitmapMock.sol +/contracts/mocks/CallReceiverMock.sol +/contracts/mocks/CheckpointsMock.sol +/contracts/mocks/ClashingImplementation.sol +/contracts/mocks/ClonesMock.sol +/contracts/mocks/compound/CompTimelock.sol +/contracts/mocks/ConditionalEscrowMock.sol +/contracts/mocks/ContextMock.sol +/contracts/mocks/CountersImpl.sol +/contracts/mocks/Create2Impl.sol +/contracts/mocks/crosschain/bridges.sol +/contracts/mocks/crosschain/receivers.sol +/contracts/mocks/DoubleEndedQueueMock.sol +/contracts/mocks/DummyImplementation.sol +/contracts/mocks/ECDSAMock.sol +/contracts/mocks/EIP712External.sol +/contracts/mocks/EnumerableMapMock.sol +/contracts/mocks/EnumerableSetMock.sol +/contracts/mocks/ERC1155BurnableMock.sol +/contracts/mocks/ERC1155Mock.sol +/contracts/mocks/ERC1155PausableMock.sol +/contracts/mocks/ERC1155ReceiverMock.sol +/contracts/mocks/ERC1155SupplyMock.sol +/contracts/mocks/ERC1155URIStorageMock.sol +/contracts/mocks/ERC1271WalletMock.sol +/contracts/mocks/ERC165/ERC165InterfacesSupported.sol +/contracts/mocks/ERC165/ERC165MaliciousData.sol +/contracts/mocks/ERC165/ERC165MissingData.sol +/contracts/mocks/ERC165/ERC165NotSupported.sol +/contracts/mocks/ERC165/ERC165ReturnBomb.sol +/contracts/mocks/ERC165CheckerMock.sol +/contracts/mocks/ERC165Mock.sol +/contracts/mocks/ERC165StorageMock.sol +/contracts/mocks/ERC1820ImplementerMock.sol +/contracts/mocks/ERC20BurnableMock.sol +/contracts/mocks/ERC20CappedMock.sol +/contracts/mocks/ERC20DecimalsMock.sol +/contracts/mocks/ERC20FlashMintMock.sol +/contracts/mocks/ERC20Mock.sol +/contracts/mocks/ERC20PausableMock.sol +/contracts/mocks/ERC20PermitMock.sol +/contracts/mocks/ERC20SnapshotMock.sol +/contracts/mocks/ERC20VotesCompMock.sol +/contracts/mocks/ERC20VotesMock.sol +/contracts/mocks/ERC20WrapperMock.sol +/contracts/mocks/ERC2771ContextMock.sol +/contracts/mocks/ERC3156FlashBorrowerMock.sol +/contracts/mocks/ERC4626Mock.sol +/contracts/mocks/ERC721BurnableMock.sol +/contracts/mocks/ERC721ConsecutiveMock.sol +/contracts/mocks/ERC721EnumerableMock.sol +/contracts/mocks/ERC721Mock.sol +/contracts/mocks/ERC721PausableMock.sol +/contracts/mocks/ERC721ReceiverMock.sol +/contracts/mocks/ERC721RoyaltyMock.sol +/contracts/mocks/ERC721URIStorageMock.sol +/contracts/mocks/ERC721VotesMock.sol +/contracts/mocks/ERC777Mock.sol +/contracts/mocks/ERC777SenderRecipientMock.sol +/contracts/mocks/EtherReceiverMock.sol +/contracts/mocks/GovernorCompatibilityBravoMock.sol +/contracts/mocks/GovernorCompMock.sol +/contracts/mocks/GovernorMock.sol +/contracts/mocks/GovernorPreventLateQuorumMock.sol +/contracts/mocks/GovernorTimelockCompoundMock.sol +/contracts/mocks/GovernorTimelockControlMock.sol +/contracts/mocks/GovernorVoteMock.sol +/contracts/mocks/GovernorWithParamsMock.sol +/contracts/mocks/InitializableMock.sol +/contracts/mocks/MathMock.sol +/contracts/mocks/MerkleProofWrapper.sol +/contracts/mocks/MulticallTest.sol +/contracts/mocks/MulticallTokenMock.sol +/contracts/mocks/MultipleInheritanceInitializableMocks.sol +/contracts/mocks/Ownable2StepMock.sol +/contracts/mocks/OwnableMock.sol +/contracts/mocks/PausableMock.sol +/contracts/mocks/PullPaymentMock.sol +/contracts/mocks/ReentrancyAttack.sol +/contracts/mocks/ReentrancyMock.sol +/contracts/mocks/RegressionImplementation.sol +/contracts/mocks/SafeCastMock.sol +/contracts/mocks/SafeERC20Helper.sol +/contracts/mocks/SafeMathMock.sol +/contracts/mocks/SignatureCheckerMock.sol +/contracts/mocks/SignedMathMock.sol +/contracts/mocks/SignedSafeMathMock.sol +/contracts/mocks/SingleInheritanceInitializableMocks.sol +/contracts/mocks/StorageSlotMock.sol +/contracts/mocks/StringsMock.sol +/contracts/mocks/TimersBlockNumberImpl.sol +/contracts/mocks/TimersTimestampImpl.sol +/contracts/mocks/UUPS/UUPSLegacy.sol +/contracts/mocks/UUPS/UUPSUpgradeableMock.sol +/contracts/mocks/VotesMock.sol +/contracts/mocks/wizard/MyGovernor1.sol +/contracts/mocks/wizard/MyGovernor2.sol +/contracts/mocks/wizard/MyGovernor3.sol +/contracts/proxy/beacon/BeaconProxy.sol +/contracts/proxy/beacon/IBeacon.sol +/contracts/proxy/beacon/UpgradeableBeacon.sol +/contracts/proxy/Clones.sol +/contracts/proxy/ERC1967/ERC1967Proxy.sol +/contracts/proxy/ERC1967/ERC1967Upgrade.sol +/contracts/proxy/Proxy.sol +/contracts/proxy/transparent/ProxyAdmin.sol +/contracts/proxy/transparent/TransparentUpgradeableProxy.sol +/contracts/proxy/utils/Initializable.sol +/contracts/proxy/utils/UUPSUpgradeable.sol +/contracts/security/Pausable.sol +/contracts/security/PullPayment.sol +/contracts/security/ReentrancyGuard.sol +/contracts/token/common/ERC2981.sol +/contracts/token/ERC1155/ERC1155.sol +/contracts/token/ERC1155/extensions/ERC1155Burnable.sol +/contracts/token/ERC1155/extensions/ERC1155Pausable.sol +/contracts/token/ERC1155/extensions/ERC1155Supply.sol +/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol +/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol +/contracts/token/ERC1155/IERC1155.sol +/contracts/token/ERC1155/IERC1155Receiver.sol +/contracts/token/ERC1155/presets/ERC1155PresetMinterPauser.sol +/contracts/token/ERC1155/utils/ERC1155Holder.sol +/contracts/token/ERC1155/utils/ERC1155Receiver.sol +/contracts/token/ERC20/ERC20.sol +/contracts/token/ERC20/extensions/draft-ERC20Permit.sol +/contracts/token/ERC20/extensions/draft-IERC20Permit.sol +/contracts/token/ERC20/extensions/ERC20Burnable.sol +/contracts/token/ERC20/extensions/ERC20Capped.sol +/contracts/token/ERC20/extensions/ERC20FlashMint.sol +/contracts/token/ERC20/extensions/ERC20Pausable.sol +/contracts/token/ERC20/extensions/ERC20Snapshot.sol +/contracts/token/ERC20/extensions/ERC20Votes.sol +/contracts/token/ERC20/extensions/ERC20VotesComp.sol +/contracts/token/ERC20/extensions/ERC20Wrapper.sol +/contracts/token/ERC20/extensions/ERC4626.sol +/contracts/token/ERC20/extensions/IERC20Metadata.sol +/contracts/token/ERC20/IERC20.sol +/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol +/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol +/contracts/token/ERC20/utils/SafeERC20.sol +/contracts/token/ERC20/utils/TokenTimelock.sol +/contracts/token/ERC721/ERC721.sol +/contracts/token/ERC721/extensions/draft-ERC721Votes.sol +/contracts/token/ERC721/extensions/ERC721Burnable.sol +/contracts/token/ERC721/extensions/ERC721Consecutive.sol +/contracts/token/ERC721/extensions/ERC721Enumerable.sol +/contracts/token/ERC721/extensions/ERC721Pausable.sol +/contracts/token/ERC721/extensions/ERC721Royalty.sol +/contracts/token/ERC721/extensions/ERC721URIStorage.sol +/contracts/token/ERC721/extensions/IERC721Enumerable.sol +/contracts/token/ERC721/extensions/IERC721Metadata.sol +/contracts/token/ERC721/IERC721.sol +/contracts/token/ERC721/IERC721Receiver.sol +/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol +/contracts/token/ERC721/utils/ERC721Holder.sol +/contracts/token/ERC777/ERC777.sol +/contracts/token/ERC777/IERC777.sol +/contracts/token/ERC777/IERC777Recipient.sol +/contracts/token/ERC777/IERC777Sender.sol +/contracts/token/ERC777/presets/ERC777PresetFixedSupply.sol +/contracts/utils/Address.sol +/contracts/utils/Arrays.sol +/contracts/utils/Base64.sol +/contracts/utils/Checkpoints.sol +/contracts/utils/Context.sol +/contracts/utils/Counters.sol +/contracts/utils/Create2.sol +/contracts/utils/cryptography/draft-EIP712.sol +/contracts/utils/cryptography/ECDSA.sol +/contracts/utils/cryptography/EIP712.sol +/contracts/utils/cryptography/MerkleProof.sol +/contracts/utils/cryptography/SignatureChecker.sol +/contracts/utils/escrow/ConditionalEscrow.sol +/contracts/utils/escrow/Escrow.sol +/contracts/utils/escrow/RefundEscrow.sol +/contracts/utils/introspection/ERC165.sol +/contracts/utils/introspection/ERC165Checker.sol +/contracts/utils/introspection/ERC165Storage.sol +/contracts/utils/introspection/ERC1820Implementer.sol +/contracts/utils/introspection/IERC165.sol +/contracts/utils/introspection/IERC1820Implementer.sol +/contracts/utils/introspection/IERC1820Registry.sol +/contracts/utils/math/Math.sol +/contracts/utils/math/SafeCast.sol +/contracts/utils/math/SafeMath.sol +/contracts/utils/math/SignedMath.sol +/contracts/utils/math/SignedSafeMath.sol +/contracts/utils/Multicall.sol +/contracts/utils/StorageSlot.sol +/contracts/utils/Strings.sol +/contracts/utils/structs/BitMaps.sol +/contracts/utils/structs/DoubleEndedQueue.sol +/contracts/utils/structs/EnumerableMap.sol +/contracts/utils/structs/EnumerableSet.sol +/contracts/utils/Timers.sol +/contracts/vendor/amb/IAMB.sol +/contracts/vendor/arbitrum/IArbSys.sol +/contracts/vendor/arbitrum/IBridge.sol +/contracts/vendor/arbitrum/IInbox.sol +/contracts/vendor/arbitrum/IMessageProvider.sol +/contracts/vendor/arbitrum/IOutbox.sol +/contracts/vendor/compound/ICompoundTimelock.sol +/contracts/vendor/optimism/ICrossDomainMessenger.sol +/contracts/vendor/polygon/IFxMessageProcessor.sol \ No newline at end of file From 6f9e76b42d4a5a22a4cace780a4585a80dfb22b0 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Wed, 14 Sep 2022 19:40:43 +0200 Subject: [PATCH 03/12] berlin --- .../src/app/plugins/parser/services/code-parser-compiler.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts b/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts index 4a31356052..3f669a8814 100644 --- a/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts +++ b/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts @@ -131,7 +131,7 @@ export default class CodeParserCompiler { "*": ["evm.gasEstimates"] } }, - "evmVersion": state.evmVersion && state.evmVersion.toString() || "byzantium", + "evmVersion": state.evmVersion && state.evmVersion.toString() || "berlin", } } From 83369e9784518a0e2e152ef3dc1474773471b302 Mon Sep 17 00:00:00 2001 From: bunsenstraat Date: Wed, 14 Sep 2022 20:02:25 +0200 Subject: [PATCH 04/12] Update completionGlobals.ts --- .../editor/src/lib/providers/completion/completionGlobals.ts | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts index 88c2369f5a..68345eab8a 100644 --- a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts +++ b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts @@ -402,7 +402,6 @@ export function GeCompletionUnits(range: IRange, monaco): monaco.languages.Compl } export function GetImports(range: IRange, monaco): monaco.languages.CompletionItem[] { let list = [] - list.filter list = OZContracts .map((item) => { const filename = path.basename(item) @@ -413,7 +412,6 @@ export function GetImports(range: IRange, monaco): monaco.languages.CompletionIt insertText: `@openzeppelin${item}`, } }) - console.log(list) return list; }; @@ -707,4 +705,4 @@ export function getContextualAutoCompleteBTypeName(word: string, range: IRange, return getAddressCompletionItems(range, monaco); } return []; -} \ No newline at end of file +} From e9d44346f761e979717ed6f392fd6891152500f8 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 15 Sep 2022 00:48:46 +0200 Subject: [PATCH 05/12] refactor --- .../src/app/plugins/parser/code-parser.tsx | 18 +- .../parser/services/code-parser-compiler.ts | 4 +- .../parser/services/code-parser-imports.ts | 86 ++++++++ .../providers/completion/completionGlobals.ts | 107 ++++++++-- .../completion/contracts/contracts.txt | 198 ++++++++++++++++++ .../src/lib/providers/completionProvider.ts | 40 ++-- package.json | 6 +- yarn.lock | 15 ++ 8 files changed, 426 insertions(+), 48 deletions(-) create mode 100644 apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts create mode 100644 libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt diff --git a/apps/remix-ide/src/app/plugins/parser/code-parser.tsx b/apps/remix-ide/src/app/plugins/parser/code-parser.tsx index b763f81a3c..9b51e42a4e 100644 --- a/apps/remix-ide/src/app/plugins/parser/code-parser.tsx +++ b/apps/remix-ide/src/app/plugins/parser/code-parser.tsx @@ -6,6 +6,7 @@ import { CompilationResult } from '@remix-project/remix-solidity' import CodeParserGasService from './services/code-parser-gas-service' import CodeParserCompiler from './services/code-parser-compiler' import CodeParserAntlrService from './services/code-parser-antlr-service' +import CodeParserImports, { CodeParserImportsData } from './services/code-parser-imports' import React from 'react' import { Profile } from '@remixproject/plugin-utils' import { ContractDefinitionAstNode, EventDefinitionAstNode, FunctionCallAstNode, FunctionDefinitionAstNode, IdentifierAstNode, ImportDirectiveAstNode, ModifierDefinitionAstNode, SourceUnitAstNode, StructDefinitionAstNode, VariableDeclarationAstNode } from 'dist/libs/remix-analyzer/src/types' @@ -15,7 +16,7 @@ import { ParseResult } from './types/antlr-types' const profile: Profile = { name: 'codeParser', - methods: ['nodesAtPosition', 'getContractNodes', 'getCurrentFileNodes', 'getLineColumnOfNode', 'getLineColumnOfPosition', 'getFunctionParamaters', 'getDeclaration', 'getFunctionReturnParameters', 'getVariableDeclaration', 'getNodeDocumentation', 'getNodeLink', 'listAstNodes', 'getANTLRBlockAtPosition', 'getLastNodeInLine', 'resolveImports', 'parseSolidity', 'getNodesWithScope', 'getNodesWithName', 'getNodes', 'compile', 'getNodeById', 'getLastCompilationResult', 'positionOfDefinition', 'definitionAtPosition', 'jumpToDefinition', 'referrencesAtPosition', 'referencesOf', 'getActiveHighlights', 'gasEstimation', 'declarationOf', 'getGasEstimates'], + methods: ['nodesAtPosition', 'getContractNodes', 'getCurrentFileNodes', 'getLineColumnOfNode', 'getLineColumnOfPosition', 'getFunctionParamaters', 'getDeclaration', 'getFunctionReturnParameters', 'getVariableDeclaration', 'getNodeDocumentation', 'getNodeLink', 'listAstNodes', 'getANTLRBlockAtPosition', 'getLastNodeInLine', 'resolveImports', 'parseSolidity', 'getNodesWithScope', 'getNodesWithName', 'getNodes', 'compile', 'getNodeById', 'getLastCompilationResult', 'positionOfDefinition', 'definitionAtPosition', 'jumpToDefinition', 'referrencesAtPosition', 'referencesOf', 'getActiveHighlights', 'gasEstimation', 'declarationOf', 'getGasEstimates', 'getImports'], events: [], version: '0.0.1' } @@ -70,12 +71,15 @@ export class CodeParser extends Plugin { gasService: CodeParserGasService compilerService: CodeParserCompiler antlrService: CodeParserAntlrService + importService: CodeParserImports parseSolidity: (text: string) => Promise getLastNodeInLine: (ast: string) => Promise listAstNodes: () => Promise getANTLRBlockAtPosition: (position: any, text?: string) => Promise getCurrentFileAST: (text?: string) => Promise + getImports: () => Promise + constructor(astWalker: any) { super(profile) @@ -94,7 +98,7 @@ export class CodeParser extends Plugin { } const showGasSettings = await this.call('config', 'getAppParameter', 'show-gas') const showErrorSettings = await this.call('config', 'getAppParameter', 'display-errors') - if(showGasSettings || showErrorSettings || completionSettings) { + if (showGasSettings || showErrorSettings || completionSettings) { await this.compilerService.compile() } } @@ -104,13 +108,14 @@ export class CodeParser extends Plugin { this.gasService = new CodeParserGasService(this) this.compilerService = new CodeParserCompiler(this) this.antlrService = new CodeParserAntlrService(this) + this.importService = new CodeParserImports(this) this.parseSolidity = this.antlrService.parseSolidity.bind(this.antlrService) this.getLastNodeInLine = this.antlrService.getLastNodeInLine.bind(this.antlrService) this.listAstNodes = this.antlrService.listAstNodes.bind(this.antlrService) this.getANTLRBlockAtPosition = this.antlrService.getANTLRBlockAtPosition.bind(this.antlrService) this.getCurrentFileAST = this.antlrService.getCurrentFileAST.bind(this.antlrService) - + this.getImports = this.importService.getImports.bind(this.importService) this.on('editor', 'didChangeFile', async (file) => { await this.call('editor', 'discardLineTexts') @@ -119,6 +124,7 @@ export class CodeParser extends Plugin { this.on('filePanel', 'setWorkspace', async () => { await this.call('fileDecorator', 'clearFileDecorators') + await this.importService.setFileTree() }) @@ -135,8 +141,6 @@ export class CodeParser extends Plugin { } - - /** * * @returns @@ -145,10 +149,6 @@ export class CodeParser extends Plugin { return this.compilerAbstract } - - - - getSubNodes(node: T): number[] { return node.nodeType == "ContractDefinition" && node.contractDependencies; } diff --git a/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts b/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts index 3f669a8814..9acd434728 100644 --- a/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts +++ b/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts @@ -39,6 +39,7 @@ export default class CodeParserCompiler { init() { this.onAstFinished = async (success, data: CompilationResult, source: CompilationSource, input: any, version) => { + //console.log('onAstFinished', success, data, source, input, version) this.plugin.call('editor', 'clearAnnotations') this.errorState = true const result = new CompilerAbstract('soljson', data, source, input) @@ -46,7 +47,7 @@ export default class CodeParserCompiler { if (data.errors) { const sources = result.getSourceCode().sources for (const error of data.errors) { - + //console.log(error) const lineBreaks = sourceMappingDecoder.getLinebreakPositions(sources[error.sourceLocation.file].content) const lineColumn = sourceMappingDecoder.convertOffsetToLineColumn({ start: error.sourceLocation.start, @@ -213,6 +214,7 @@ export default class CodeParserCompiler { async clearDecorators(sources: any) { const decorators: fileDecoration[] = [] + if(!sources) return for (const fileName of Object.keys(sources)) { const decorator: fileDecoration = { path: fileName, diff --git a/apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts b/apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts new file mode 100644 index 0000000000..d2261c3154 --- /dev/null +++ b/apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts @@ -0,0 +1,86 @@ +'use strict' +import { CodeParser } from "../code-parser"; + +export type CodeParserImportsData= { + files?: string[], + modules?: string[], + packages?: string[], +} + +export default class CodeParserImports { + plugin: CodeParser + + data: CodeParserImportsData = {} + constructor(plugin: CodeParser) { + this.plugin = plugin + this.init() + } + + async getImports(){ + return this.data + } + + async init() { + // @ts-ignore + const txt = await import('raw-loader!libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt') + + // eslint-disable-next-line @typescript-eslint/no-unused-vars + this.data.modules = txt.default.split('\n') + .filter(x => x !== '') + .map(x => x.replace('./node_modules/', '')) + .filter(x => { + if(x.includes('@openzeppelin')) { + return !x.includes('mock') + }else{ + return true + } + }) + + // get unique first words of the values in the array + this.data.packages = [...new Set(this.data.modules.map(x => x.split('/')[0]))] + console.log(this.data) + } + + setFileTree = async () => { + this.data.files = await this.getDirectory('/') + this.data.files = this.data.files.filter(x => x.endsWith('.sol') && !x.startsWith('.deps')) + console.log(this.data) + } + + getDirectory = async (dir: string) => { + let result = [] + const files = await this.plugin.call('fileManager', 'readdir', dir) + const fileArray = this.normalize(files) + for (const fi of fileArray) { + if (fi) { + const type = fi.data.isDirectory + if (type === true) { + result = [...result, ...(await this.getDirectory(`${fi.filename}`))] + } else { + result = [...result, fi.filename] + } + } + } + return result + } + + normalize = filesList => { + const folders = [] + const files = [] + Object.keys(filesList || {}).forEach(key => { + if (filesList[key].isDirectory) { + folders.push({ + filename: key, + data: filesList[key] + }) + } else { + files.push({ + filename: key, + data: filesList[key] + }) + } + }) + return [...folders, ...files] + } + +} \ No newline at end of file diff --git a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts index 88c2369f5a..2209aa8c61 100644 --- a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts +++ b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts @@ -1,16 +1,12 @@ import { IRange } from "monaco-editor"; import monaco from "../../../types/monaco"; import path from "path"; -let OZContracts; - -// @ts-ignore -import('raw-loader!libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt').then( - (txt) => { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - OZContracts = txt.default.split('\n').filter(x => !x.includes('mock')) - } -) +type CodeParserImportsData = { + files?: string[], + modules?: string[], + packages?: string[], +} export function getStringCompletionItems(range: IRange, monaco): monaco.languages.CompletionItem[] { return [ @@ -400,20 +396,87 @@ export function GeCompletionUnits(range: IRange, monaco): monaco.languages.Compl return completionItems; } -export function GetImports(range: IRange, monaco): monaco.languages.CompletionItem[] { + +export function GetImports(range: IRange + , monaco, data: CodeParserImportsData + , word: string +): monaco.languages.CompletionItem[] { let list = [] - list.filter - list = OZContracts - .map((item) => { - const filename = path.basename(item) - return { - kind: monaco.languages.CompletionItemKind.Module, - range: range, - label: `OZ ${filename}: ${item}`, - insertText: `@openzeppelin${item}`, - } - }) - console.log(list) + if (!word.startsWith('@')) { + word = word.replace('"', ''); + const nextPaths = [...new Set(data.files + .filter((item) => item.startsWith(word)) + .map((item) => item.replace(word, '').split('/')[0]))] + + list = [...list, ...nextPaths + .filter((item) => !item.endsWith('.sol')) + .map((item) => { + return { + kind: monaco.languages.CompletionItemKind.Folder, + range: range, + label: `${item}`, + insertText: `${item}`, + } + })] + + + list = [...list, + ...data.files + .filter((item) => item.startsWith(word)) + .map((item) => { + return { + kind: monaco.languages.CompletionItemKind.File, + range: range, + label: `${item}`, + insertText: `${item.replace(word, '')}`, + } + })] + } + if (word === '@' || word === '') { + list = [...list, ...data.packages.map((item) => { + return { + kind: monaco.languages.CompletionItemKind.Module, + range: range, + label: `${item}`, + insertText: word === '@' ? `${item.replace('@', '')}` : `${item}`, + } + })] + } + if (word.startsWith('@') && word.length > 1) { + const nextPaths = [...new Set(data.modules + .filter((item) => item.startsWith(word)) + .map((item) => item.replace(word, '').split('/')[0]))] + + list = [...list, ...nextPaths + .filter((item) => !item.endsWith('.sol')) + .map((item) => { + return { + kind: monaco.languages.CompletionItemKind.Folder, + range: range, + label: `${item}`, + insertText: `${item}`, + } + })] + + list = [...list + , ...data.modules + .filter((item) => item.startsWith(word)) + .map((item) => { + // remove the first part if it starts with @ + let label = item; + if (label.startsWith('@')) { + label = label.substring(label.indexOf('/') + 1); + } + const filename = path.basename(label) + return { + kind: monaco.languages.CompletionItemKind.Reference, + range: range, + label: `${filename}: ${label}`, + insertText: `${item.replace(word, '')}`, + } + }) + ] + } return list; }; diff --git a/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt b/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt new file mode 100644 index 0000000000..94615103e0 --- /dev/null +++ b/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt @@ -0,0 +1,198 @@ +./node_modules/@openzeppelin/contracts/access/AccessControl.sol +./node_modules/@openzeppelin/contracts/access/AccessControlCrossChain.sol +./node_modules/@openzeppelin/contracts/access/AccessControlEnumerable.sol +./node_modules/@openzeppelin/contracts/access/IAccessControl.sol +./node_modules/@openzeppelin/contracts/access/IAccessControlEnumerable.sol +./node_modules/@openzeppelin/contracts/access/Ownable.sol +./node_modules/@openzeppelin/contracts/crosschain/amb/CrossChainEnabledAMB.sol +./node_modules/@openzeppelin/contracts/crosschain/amb/LibAMB.sol +./node_modules/@openzeppelin/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL1.sol +./node_modules/@openzeppelin/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL2.sol +./node_modules/@openzeppelin/contracts/crosschain/arbitrum/LibArbitrumL1.sol +./node_modules/@openzeppelin/contracts/crosschain/arbitrum/LibArbitrumL2.sol +./node_modules/@openzeppelin/contracts/crosschain/CrossChainEnabled.sol +./node_modules/@openzeppelin/contracts/crosschain/errors.sol +./node_modules/@openzeppelin/contracts/crosschain/optimism/CrossChainEnabledOptimism.sol +./node_modules/@openzeppelin/contracts/crosschain/optimism/LibOptimism.sol +./node_modules/@openzeppelin/contracts/crosschain/polygon/CrossChainEnabledPolygonChild.sol +./node_modules/@openzeppelin/contracts/finance/PaymentSplitter.sol +./node_modules/@openzeppelin/contracts/finance/VestingWallet.sol +./node_modules/@openzeppelin/contracts/governance/compatibility/GovernorCompatibilityBravo.sol +./node_modules/@openzeppelin/contracts/governance/compatibility/IGovernorCompatibilityBravo.sol +./node_modules/@openzeppelin/contracts/governance/extensions/GovernorCountingSimple.sol +./node_modules/@openzeppelin/contracts/governance/extensions/GovernorPreventLateQuorum.sol +./node_modules/@openzeppelin/contracts/governance/extensions/GovernorProposalThreshold.sol +./node_modules/@openzeppelin/contracts/governance/extensions/GovernorSettings.sol +./node_modules/@openzeppelin/contracts/governance/extensions/GovernorTimelockCompound.sol +./node_modules/@openzeppelin/contracts/governance/extensions/GovernorTimelockControl.sol +./node_modules/@openzeppelin/contracts/governance/extensions/GovernorVotes.sol +./node_modules/@openzeppelin/contracts/governance/extensions/GovernorVotesComp.sol +./node_modules/@openzeppelin/contracts/governance/extensions/GovernorVotesQuorumFraction.sol +./node_modules/@openzeppelin/contracts/governance/extensions/IGovernorTimelock.sol +./node_modules/@openzeppelin/contracts/governance/Governor.sol +./node_modules/@openzeppelin/contracts/governance/IGovernor.sol +./node_modules/@openzeppelin/contracts/governance/TimelockController.sol +./node_modules/@openzeppelin/contracts/governance/utils/IVotes.sol +./node_modules/@openzeppelin/contracts/governance/utils/Votes.sol +./node_modules/@openzeppelin/contracts/interfaces/draft-IERC1822.sol +./node_modules/@openzeppelin/contracts/interfaces/draft-IERC2612.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC1155.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC1155MetadataURI.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC1155Receiver.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC1271.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC1363.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC1363Receiver.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC1363Spender.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC165.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC1820Implementer.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC1820Registry.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC20.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC20Metadata.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC2981.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC3156.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC3156FlashBorrower.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC3156FlashLender.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC4626.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC721.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC721Enumerable.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC721Metadata.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC721Receiver.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC777.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC777Recipient.sol +./node_modules/@openzeppelin/contracts/interfaces/IERC777Sender.sol +./node_modules/@openzeppelin/contracts/metatx/ERC2771Context.sol +./node_modules/@openzeppelin/contracts/metatx/MinimalForwarder.sol +./node_modules/@openzeppelin/contracts/proxy/beacon/BeaconProxy.sol +./node_modules/@openzeppelin/contracts/proxy/beacon/IBeacon.sol +./node_modules/@openzeppelin/contracts/proxy/beacon/UpgradeableBeacon.sol +./node_modules/@openzeppelin/contracts/proxy/Clones.sol +./node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Proxy.sol +./node_modules/@openzeppelin/contracts/proxy/ERC1967/ERC1967Upgrade.sol +./node_modules/@openzeppelin/contracts/proxy/Proxy.sol +./node_modules/@openzeppelin/contracts/proxy/transparent/ProxyAdmin.sol +./node_modules/@openzeppelin/contracts/proxy/transparent/TransparentUpgradeableProxy.sol +./node_modules/@openzeppelin/contracts/proxy/utils/Initializable.sol +./node_modules/@openzeppelin/contracts/proxy/utils/UUPSUpgradeable.sol +./node_modules/@openzeppelin/contracts/security/Pausable.sol +./node_modules/@openzeppelin/contracts/security/PullPayment.sol +./node_modules/@openzeppelin/contracts/security/ReentrancyGuard.sol +./node_modules/@openzeppelin/contracts/token/common/ERC2981.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/ERC1155.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Burnable.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Pausable.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/extensions/ERC1155Supply.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/IERC1155.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/IERC1155Receiver.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/presets/ERC1155PresetMinterPauser.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/utils/ERC1155Holder.sol +./node_modules/@openzeppelin/contracts/token/ERC1155/utils/ERC1155Receiver.sol +./node_modules/@openzeppelin/contracts/token/ERC20/ERC20.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/draft-ERC20Permit.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/draft-IERC20Permit.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Burnable.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Capped.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20FlashMint.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Pausable.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Snapshot.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Votes.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20VotesComp.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC20Wrapper.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/ERC4626.sol +./node_modules/@openzeppelin/contracts/token/ERC20/extensions/IERC20Metadata.sol +./node_modules/@openzeppelin/contracts/token/ERC20/IERC20.sol +./node_modules/@openzeppelin/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol +./node_modules/@openzeppelin/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol +./node_modules/@openzeppelin/contracts/token/ERC20/utils/SafeERC20.sol +./node_modules/@openzeppelin/contracts/token/ERC20/utils/TokenTimelock.sol +./node_modules/@openzeppelin/contracts/token/ERC721/ERC721.sol +./node_modules/@openzeppelin/contracts/token/ERC721/extensions/draft-ERC721Votes.sol +./node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721Burnable.sol +./node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721Enumerable.sol +./node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721Pausable.sol +./node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721Royalty.sol +./node_modules/@openzeppelin/contracts/token/ERC721/extensions/ERC721URIStorage.sol +./node_modules/@openzeppelin/contracts/token/ERC721/extensions/IERC721Enumerable.sol +./node_modules/@openzeppelin/contracts/token/ERC721/extensions/IERC721Metadata.sol +./node_modules/@openzeppelin/contracts/token/ERC721/IERC721.sol +./node_modules/@openzeppelin/contracts/token/ERC721/IERC721Receiver.sol +./node_modules/@openzeppelin/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol +./node_modules/@openzeppelin/contracts/token/ERC721/utils/ERC721Holder.sol +./node_modules/@openzeppelin/contracts/token/ERC777/ERC777.sol +./node_modules/@openzeppelin/contracts/token/ERC777/IERC777.sol +./node_modules/@openzeppelin/contracts/token/ERC777/IERC777Recipient.sol +./node_modules/@openzeppelin/contracts/token/ERC777/IERC777Sender.sol +./node_modules/@openzeppelin/contracts/token/ERC777/presets/ERC777PresetFixedSupply.sol +./node_modules/@openzeppelin/contracts/utils/Address.sol +./node_modules/@openzeppelin/contracts/utils/Arrays.sol +./node_modules/@openzeppelin/contracts/utils/Base64.sol +./node_modules/@openzeppelin/contracts/utils/Checkpoints.sol +./node_modules/@openzeppelin/contracts/utils/Context.sol +./node_modules/@openzeppelin/contracts/utils/Counters.sol +./node_modules/@openzeppelin/contracts/utils/Create2.sol +./node_modules/@openzeppelin/contracts/utils/cryptography/draft-EIP712.sol +./node_modules/@openzeppelin/contracts/utils/cryptography/ECDSA.sol +./node_modules/@openzeppelin/contracts/utils/cryptography/MerkleProof.sol +./node_modules/@openzeppelin/contracts/utils/cryptography/SignatureChecker.sol +./node_modules/@openzeppelin/contracts/utils/escrow/ConditionalEscrow.sol +./node_modules/@openzeppelin/contracts/utils/escrow/Escrow.sol +./node_modules/@openzeppelin/contracts/utils/escrow/RefundEscrow.sol +./node_modules/@openzeppelin/contracts/utils/introspection/ERC165.sol +./node_modules/@openzeppelin/contracts/utils/introspection/ERC165Checker.sol +./node_modules/@openzeppelin/contracts/utils/introspection/ERC165Storage.sol +./node_modules/@openzeppelin/contracts/utils/introspection/ERC1820Implementer.sol +./node_modules/@openzeppelin/contracts/utils/introspection/IERC165.sol +./node_modules/@openzeppelin/contracts/utils/introspection/IERC1820Implementer.sol +./node_modules/@openzeppelin/contracts/utils/introspection/IERC1820Registry.sol +./node_modules/@openzeppelin/contracts/utils/math/Math.sol +./node_modules/@openzeppelin/contracts/utils/math/SafeCast.sol +./node_modules/@openzeppelin/contracts/utils/math/SafeMath.sol +./node_modules/@openzeppelin/contracts/utils/math/SignedMath.sol +./node_modules/@openzeppelin/contracts/utils/math/SignedSafeMath.sol +./node_modules/@openzeppelin/contracts/utils/Multicall.sol +./node_modules/@openzeppelin/contracts/utils/StorageSlot.sol +./node_modules/@openzeppelin/contracts/utils/Strings.sol +./node_modules/@openzeppelin/contracts/utils/structs/BitMaps.sol +./node_modules/@openzeppelin/contracts/utils/structs/DoubleEndedQueue.sol +./node_modules/@openzeppelin/contracts/utils/structs/EnumerableMap.sol +./node_modules/@openzeppelin/contracts/utils/structs/EnumerableSet.sol +./node_modules/@openzeppelin/contracts/utils/Timers.sol +./node_modules/@openzeppelin/contracts/vendor/amb/IAMB.sol +./node_modules/@openzeppelin/contracts/vendor/arbitrum/IArbSys.sol +./node_modules/@openzeppelin/contracts/vendor/arbitrum/IBridge.sol +./node_modules/@openzeppelin/contracts/vendor/arbitrum/IInbox.sol +./node_modules/@openzeppelin/contracts/vendor/arbitrum/IMessageProvider.sol +./node_modules/@openzeppelin/contracts/vendor/arbitrum/IOutbox.sol +./node_modules/@openzeppelin/contracts/vendor/compound/ICompoundTimelock.sol +./node_modules/@openzeppelin/contracts/vendor/optimism/ICrossDomainMessenger.sol +./node_modules/@openzeppelin/contracts/vendor/polygon/IFxMessageProcessor.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3FlashCallback.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3MintCallback.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/callback/IUniswapV3SwapCallback.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/IERC20Minimal.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/IUniswapV3Factory.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/IUniswapV3Pool.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/IUniswapV3PoolDeployer.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolActions.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolDerivedState.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolEvents.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolImmutables.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolOwnerActions.sol +./node_modules/@uniswap/v3-core/contracts/interfaces/pool/IUniswapV3PoolState.sol +./node_modules/@uniswap/v3-core/contracts/libraries/BitMath.sol +./node_modules/@uniswap/v3-core/contracts/libraries/FixedPoint128.sol +./node_modules/@uniswap/v3-core/contracts/libraries/FixedPoint96.sol +./node_modules/@uniswap/v3-core/contracts/libraries/FullMath.sol +./node_modules/@uniswap/v3-core/contracts/libraries/LiquidityMath.sol +./node_modules/@uniswap/v3-core/contracts/libraries/LowGasSafeMath.sol +./node_modules/@uniswap/v3-core/contracts/libraries/Oracle.sol +./node_modules/@uniswap/v3-core/contracts/libraries/Position.sol +./node_modules/@uniswap/v3-core/contracts/libraries/SafeCast.sol +./node_modules/@uniswap/v3-core/contracts/libraries/SqrtPriceMath.sol +./node_modules/@uniswap/v3-core/contracts/libraries/SwapMath.sol +./node_modules/@uniswap/v3-core/contracts/libraries/Tick.sol +./node_modules/@uniswap/v3-core/contracts/libraries/TickBitmap.sol +./node_modules/@uniswap/v3-core/contracts/libraries/TickMath.sol +./node_modules/@uniswap/v3-core/contracts/libraries/TransferHelper.sol +./node_modules/@uniswap/v3-core/contracts/libraries/UnsafeMath.sol diff --git a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts index c9b88c9805..6e09dc1914 100644 --- a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts @@ -1,10 +1,10 @@ import { sourceMappingDecoder } from "@remix-project/remix-debug" import { AstNode } from "@remix-project/remix-solidity-ts" -import { isArray } from "lodash" +import { isArray, last } from "lodash" import { editor, languages, Position } from "monaco-editor" import monaco from "../../types/monaco" import { EditorUIProps } from "../remix-ui-editor" -import { GeCompletionUnits, GetCompletionKeywords, getCompletionSnippets, GetCompletionTypes, getContextualAutoCompleteBTypeName, getContextualAutoCompleteByGlobalVariable, GetGlobalFunctions, GetGlobalVariable, GetImports } from "./completion/completionGlobals" +import { GeCompletionUnits, GetCompletionKeywords, getCompletionSnippets, GetCompletionTypes, getContextualAutoCompleteBTypeName, getContextualAutoCompleteByGlobalVariable, GetContractRepositories, GetGlobalFunctions, GetGlobalVariable, GetImports } from "./completion/completionGlobals" export class RemixCompletionProvider implements languages.CompletionItemProvider { @@ -16,7 +16,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider this.monaco = monaco } - triggerCharacters = ['.', '', '"'] + triggerCharacters = ['.', '', '"', '@', '/'] async provideCompletionItems(model: editor.ITextModel, position: Position, context: monaco.languages.CompletionContext): Promise { const completionSettings = await this.props.plugin.call('config', 'getAppParameter', 'settings/auto-completion') @@ -28,21 +28,31 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider startColumn: word.startColumn, endColumn: word.endColumn }; - + console.log(word) const line = model.getLineContent(position.lineNumber) let nodes: AstNode[] = [] let suggestions: monaco.languages.CompletionItem[] = [] - - if (context.triggerCharacter === '"') { - - const ast = await this.props.plugin.call('codeParser', 'parseSolidity', line) - if (ast && ast.children && ast.children[0] && ast.children[0].type === "ImportDirective") { - suggestions = [...suggestions, - ...GetImports(range, this.monaco), - ] - - }else{ - return + console.log('context', context.triggerCharacter) + + if (context.triggerCharacter === '"' || context.triggerCharacter === '@' || context.triggerCharacter === '/') { + + const lastpart = line.substring(0, position.column - 1).split(';').pop() + console.log('lastpart', lastpart) + if (lastpart.startsWith('import')) { + const imports = await this.props.plugin.call('codeParser', 'getImports') + if (context.triggerCharacter === '"' || context.triggerCharacter === '@') { + suggestions = [...suggestions, + ...GetImports(range, this.monaco, imports, context.triggerCharacter), + ] + } else if (context.triggerCharacter === '/') { + const word = line.split('"')[1] + console.log(word) + suggestions = [...suggestions, + ...GetImports(range, this.monaco, imports, word), + ] + } else { + return + } } } else diff --git a/package.json b/package.json index 8399c040bc..e73b61e6ee 100644 --- a/package.json +++ b/package.json @@ -108,7 +108,8 @@ "test-browser": "npm-run-all -lpr selenium make-mock-compiler serve browsertest", "watch": "watchify apps/remix-ide/src/index.js -dv -p browserify-reload -o apps/remix-ide/build/app.js --exclude solc", "reinstall": "rm ./node-modules/ -rf && rm yarn.lock && rm ./build/ -rf && yarn install & yarn run build", - "ganache-cli": "npx ganache-cli" + "ganache-cli": "npx ganache-cli", + "build-contracts": "find ./node_modules/@openzeppelin/contracts | grep -i '.sol' > libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt && find ./node_modules/@uniswap/v3-core/contracts | grep -i '.sol' >> libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt" }, "browserify": { "transform": [ @@ -234,6 +235,7 @@ "@babel/preset-typescript": "7.9.0", "@babel/register": "^7.4.4", "@fortawesome/fontawesome-free": "^5.8.1", + "@hq20/contracts": "^0.0.6", "@nrwl/cli": "12.3.6", "@nrwl/eslint-plugin-nx": "12.3.6", "@nrwl/jest": "12.3.6", @@ -261,6 +263,8 @@ "@types/ws": "^7.2.4", "@typescript-eslint/eslint-plugin": "^4.32.0", "@typescript-eslint/parser": "^4.32.0", + "@uniswap/v2-core": "^1.0.1", + "@uniswap/v3-core": "^1.0.1", "ace-mode-lexon": "^1.*.*", "ace-mode-move": "0.0.1", "ace-mode-solidity": "^0.1.0", diff --git a/yarn.lock b/yarn.lock index 3809c46cb6..d5e5cff8a1 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2475,6 +2475,11 @@ resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.2.tgz#30aa825f11d438671d585bd44e7fd564535fc210" integrity sha512-82cpyJyKRoQoRi+14ibCeGPu0CwypgtBAdBhq1WfvagpCZNKqwXbKwXllYSMG91DhmG4jt9gN8eP6lGOtozuaw== +"@hq20/contracts@^0.0.6": + version "0.0.6" + resolved "https://registry.yarnpkg.com/@hq20/contracts/-/contracts-0.0.6.tgz#fc0a05884294da8757c4187f8567638982b74b6a" + integrity sha512-l94ARK0LfcRY7Y5EiInA+0vdXh8lnkTRAw9unli7UC75DY7aBMJl4OqTT5SMdm/n4N1dVVhCnyCM1W84UAx2Vw== + "@isomorphic-git/idb-keyval@3.3.2": version "3.3.2" resolved "https://registry.yarnpkg.com/@isomorphic-git/idb-keyval/-/idb-keyval-3.3.2.tgz#c0509a6c5987d8a62efb3e47f2815bcc5eda2489" @@ -4806,6 +4811,16 @@ resolved "https://registry.yarnpkg.com/@ungap/promise-all-settled/-/promise-all-settled-1.1.2.tgz#aa58042711d6e3275dd37dc597e5d31e8c290a44" integrity sha512-sL/cEvJWAnClXw0wHk85/2L0G6Sj8UB0Ctc1TEMbKSsmpRosqhwj9gWgFRZSrBr2f9tiXISwNhCPmlfqUqyb9Q== +"@uniswap/v2-core@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@uniswap/v2-core/-/v2-core-1.0.1.tgz#af8f508bf183204779938969e2e54043e147d425" + integrity sha512-MtybtkUPSyysqLY2U210NBDeCHX+ltHt3oADGdjqoThZaFRDKwM6k1Nb3F0A3hk5hwuQvytFWhrWHOEq6nVJ8Q== + +"@uniswap/v3-core@^1.0.1": + version "1.0.1" + resolved "https://registry.yarnpkg.com/@uniswap/v3-core/-/v3-core-1.0.1.tgz#b6d2bdc6ba3c3fbd610bdc502395d86cd35264a0" + integrity sha512-7pVk4hEm00j9tc71Y9+ssYpO6ytkeI0y7WE9P6UcmNzhxPePwyAxImuhVsTqWK9YFvzgtvzJHi64pBl4jUzKMQ== + "@webassemblyjs/ast@1.8.5": version "1.8.5" resolved "https://registry.yarnpkg.com/@webassemblyjs/ast/-/ast-1.8.5.tgz#51b1c5fe6576a34953bf4b253df9f0d490d9e359" From ea4ca046c7a39cab2eac4ef15dff1abee81aef19 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 15 Sep 2022 00:50:45 +0200 Subject: [PATCH 06/12] rm file --- .../contracts/OpenZeppelinContracts.txt | 278 ------------------ 1 file changed, 278 deletions(-) delete mode 100644 libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt diff --git a/libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt b/libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt deleted file mode 100644 index cffe37a8a7..0000000000 --- a/libs/remix-ui/editor/src/lib/providers/completion/contracts/OpenZeppelinContracts.txt +++ /dev/null @@ -1,278 +0,0 @@ -/contracts/access/AccessControl.sol -/contracts/access/AccessControlCrossChain.sol -/contracts/access/AccessControlEnumerable.sol -/contracts/access/IAccessControl.sol -/contracts/access/IAccessControlEnumerable.sol -/contracts/access/Ownable.sol -/contracts/access/Ownable2Step.sol -/contracts/crosschain/amb/CrossChainEnabledAMB.sol -/contracts/crosschain/amb/LibAMB.sol -/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL1.sol -/contracts/crosschain/arbitrum/CrossChainEnabledArbitrumL2.sol -/contracts/crosschain/arbitrum/LibArbitrumL1.sol -/contracts/crosschain/arbitrum/LibArbitrumL2.sol -/contracts/crosschain/CrossChainEnabled.sol -/contracts/crosschain/errors.sol -/contracts/crosschain/optimism/CrossChainEnabledOptimism.sol -/contracts/crosschain/optimism/LibOptimism.sol -/contracts/crosschain/polygon/CrossChainEnabledPolygonChild.sol -/contracts/finance/PaymentSplitter.sol -/contracts/finance/VestingWallet.sol -/contracts/governance/compatibility/GovernorCompatibilityBravo.sol -/contracts/governance/compatibility/IGovernorCompatibilityBravo.sol -/contracts/governance/extensions/GovernorCountingSimple.sol -/contracts/governance/extensions/GovernorPreventLateQuorum.sol -/contracts/governance/extensions/GovernorProposalThreshold.sol -/contracts/governance/extensions/GovernorSettings.sol -/contracts/governance/extensions/GovernorTimelockCompound.sol -/contracts/governance/extensions/GovernorTimelockControl.sol -/contracts/governance/extensions/GovernorVotes.sol -/contracts/governance/extensions/GovernorVotesComp.sol -/contracts/governance/extensions/GovernorVotesQuorumFraction.sol -/contracts/governance/extensions/IGovernorTimelock.sol -/contracts/governance/Governor.sol -/contracts/governance/IGovernor.sol -/contracts/governance/TimelockController.sol -/contracts/governance/utils/IVotes.sol -/contracts/governance/utils/Votes.sol -/contracts/interfaces/draft-IERC1822.sol -/contracts/interfaces/draft-IERC2612.sol -/contracts/interfaces/IERC1155.sol -/contracts/interfaces/IERC1155MetadataURI.sol -/contracts/interfaces/IERC1155Receiver.sol -/contracts/interfaces/IERC1271.sol -/contracts/interfaces/IERC1363.sol -/contracts/interfaces/IERC1363Receiver.sol -/contracts/interfaces/IERC1363Spender.sol -/contracts/interfaces/IERC165.sol -/contracts/interfaces/IERC1820Implementer.sol -/contracts/interfaces/IERC1820Registry.sol -/contracts/interfaces/IERC20.sol -/contracts/interfaces/IERC20Metadata.sol -/contracts/interfaces/IERC2309.sol -/contracts/interfaces/IERC2981.sol -/contracts/interfaces/IERC3156.sol -/contracts/interfaces/IERC3156FlashBorrower.sol -/contracts/interfaces/IERC3156FlashLender.sol -/contracts/interfaces/IERC4626.sol -/contracts/interfaces/IERC721.sol -/contracts/interfaces/IERC721Enumerable.sol -/contracts/interfaces/IERC721Metadata.sol -/contracts/interfaces/IERC721Receiver.sol -/contracts/interfaces/IERC777.sol -/contracts/interfaces/IERC777Recipient.sol -/contracts/interfaces/IERC777Sender.sol -/contracts/metatx/ERC2771Context.sol -/contracts/metatx/MinimalForwarder.sol -/contracts/mocks/AccessControlCrossChainMock.sol -/contracts/mocks/AccessControlEnumerableMock.sol -/contracts/mocks/AccessControlMock.sol -/contracts/mocks/AddressImpl.sol -/contracts/mocks/ArraysMock.sol -/contracts/mocks/BadBeacon.sol -/contracts/mocks/Base64Mock.sol -/contracts/mocks/BitmapMock.sol -/contracts/mocks/CallReceiverMock.sol -/contracts/mocks/CheckpointsMock.sol -/contracts/mocks/ClashingImplementation.sol -/contracts/mocks/ClonesMock.sol -/contracts/mocks/compound/CompTimelock.sol -/contracts/mocks/ConditionalEscrowMock.sol -/contracts/mocks/ContextMock.sol -/contracts/mocks/CountersImpl.sol -/contracts/mocks/Create2Impl.sol -/contracts/mocks/crosschain/bridges.sol -/contracts/mocks/crosschain/receivers.sol -/contracts/mocks/DoubleEndedQueueMock.sol -/contracts/mocks/DummyImplementation.sol -/contracts/mocks/ECDSAMock.sol -/contracts/mocks/EIP712External.sol -/contracts/mocks/EnumerableMapMock.sol -/contracts/mocks/EnumerableSetMock.sol -/contracts/mocks/ERC1155BurnableMock.sol -/contracts/mocks/ERC1155Mock.sol -/contracts/mocks/ERC1155PausableMock.sol -/contracts/mocks/ERC1155ReceiverMock.sol -/contracts/mocks/ERC1155SupplyMock.sol -/contracts/mocks/ERC1155URIStorageMock.sol -/contracts/mocks/ERC1271WalletMock.sol -/contracts/mocks/ERC165/ERC165InterfacesSupported.sol -/contracts/mocks/ERC165/ERC165MaliciousData.sol -/contracts/mocks/ERC165/ERC165MissingData.sol -/contracts/mocks/ERC165/ERC165NotSupported.sol -/contracts/mocks/ERC165/ERC165ReturnBomb.sol -/contracts/mocks/ERC165CheckerMock.sol -/contracts/mocks/ERC165Mock.sol -/contracts/mocks/ERC165StorageMock.sol -/contracts/mocks/ERC1820ImplementerMock.sol -/contracts/mocks/ERC20BurnableMock.sol -/contracts/mocks/ERC20CappedMock.sol -/contracts/mocks/ERC20DecimalsMock.sol -/contracts/mocks/ERC20FlashMintMock.sol -/contracts/mocks/ERC20Mock.sol -/contracts/mocks/ERC20PausableMock.sol -/contracts/mocks/ERC20PermitMock.sol -/contracts/mocks/ERC20SnapshotMock.sol -/contracts/mocks/ERC20VotesCompMock.sol -/contracts/mocks/ERC20VotesMock.sol -/contracts/mocks/ERC20WrapperMock.sol -/contracts/mocks/ERC2771ContextMock.sol -/contracts/mocks/ERC3156FlashBorrowerMock.sol -/contracts/mocks/ERC4626Mock.sol -/contracts/mocks/ERC721BurnableMock.sol -/contracts/mocks/ERC721ConsecutiveMock.sol -/contracts/mocks/ERC721EnumerableMock.sol -/contracts/mocks/ERC721Mock.sol -/contracts/mocks/ERC721PausableMock.sol -/contracts/mocks/ERC721ReceiverMock.sol -/contracts/mocks/ERC721RoyaltyMock.sol -/contracts/mocks/ERC721URIStorageMock.sol -/contracts/mocks/ERC721VotesMock.sol -/contracts/mocks/ERC777Mock.sol -/contracts/mocks/ERC777SenderRecipientMock.sol -/contracts/mocks/EtherReceiverMock.sol -/contracts/mocks/GovernorCompatibilityBravoMock.sol -/contracts/mocks/GovernorCompMock.sol -/contracts/mocks/GovernorMock.sol -/contracts/mocks/GovernorPreventLateQuorumMock.sol -/contracts/mocks/GovernorTimelockCompoundMock.sol -/contracts/mocks/GovernorTimelockControlMock.sol -/contracts/mocks/GovernorVoteMock.sol -/contracts/mocks/GovernorWithParamsMock.sol -/contracts/mocks/InitializableMock.sol -/contracts/mocks/MathMock.sol -/contracts/mocks/MerkleProofWrapper.sol -/contracts/mocks/MulticallTest.sol -/contracts/mocks/MulticallTokenMock.sol -/contracts/mocks/MultipleInheritanceInitializableMocks.sol -/contracts/mocks/Ownable2StepMock.sol -/contracts/mocks/OwnableMock.sol -/contracts/mocks/PausableMock.sol -/contracts/mocks/PullPaymentMock.sol -/contracts/mocks/ReentrancyAttack.sol -/contracts/mocks/ReentrancyMock.sol -/contracts/mocks/RegressionImplementation.sol -/contracts/mocks/SafeCastMock.sol -/contracts/mocks/SafeERC20Helper.sol -/contracts/mocks/SafeMathMock.sol -/contracts/mocks/SignatureCheckerMock.sol -/contracts/mocks/SignedMathMock.sol -/contracts/mocks/SignedSafeMathMock.sol -/contracts/mocks/SingleInheritanceInitializableMocks.sol -/contracts/mocks/StorageSlotMock.sol -/contracts/mocks/StringsMock.sol -/contracts/mocks/TimersBlockNumberImpl.sol -/contracts/mocks/TimersTimestampImpl.sol -/contracts/mocks/UUPS/UUPSLegacy.sol -/contracts/mocks/UUPS/UUPSUpgradeableMock.sol -/contracts/mocks/VotesMock.sol -/contracts/mocks/wizard/MyGovernor1.sol -/contracts/mocks/wizard/MyGovernor2.sol -/contracts/mocks/wizard/MyGovernor3.sol -/contracts/proxy/beacon/BeaconProxy.sol -/contracts/proxy/beacon/IBeacon.sol -/contracts/proxy/beacon/UpgradeableBeacon.sol -/contracts/proxy/Clones.sol -/contracts/proxy/ERC1967/ERC1967Proxy.sol -/contracts/proxy/ERC1967/ERC1967Upgrade.sol -/contracts/proxy/Proxy.sol -/contracts/proxy/transparent/ProxyAdmin.sol -/contracts/proxy/transparent/TransparentUpgradeableProxy.sol -/contracts/proxy/utils/Initializable.sol -/contracts/proxy/utils/UUPSUpgradeable.sol -/contracts/security/Pausable.sol -/contracts/security/PullPayment.sol -/contracts/security/ReentrancyGuard.sol -/contracts/token/common/ERC2981.sol -/contracts/token/ERC1155/ERC1155.sol -/contracts/token/ERC1155/extensions/ERC1155Burnable.sol -/contracts/token/ERC1155/extensions/ERC1155Pausable.sol -/contracts/token/ERC1155/extensions/ERC1155Supply.sol -/contracts/token/ERC1155/extensions/ERC1155URIStorage.sol -/contracts/token/ERC1155/extensions/IERC1155MetadataURI.sol -/contracts/token/ERC1155/IERC1155.sol -/contracts/token/ERC1155/IERC1155Receiver.sol -/contracts/token/ERC1155/presets/ERC1155PresetMinterPauser.sol -/contracts/token/ERC1155/utils/ERC1155Holder.sol -/contracts/token/ERC1155/utils/ERC1155Receiver.sol -/contracts/token/ERC20/ERC20.sol -/contracts/token/ERC20/extensions/draft-ERC20Permit.sol -/contracts/token/ERC20/extensions/draft-IERC20Permit.sol -/contracts/token/ERC20/extensions/ERC20Burnable.sol -/contracts/token/ERC20/extensions/ERC20Capped.sol -/contracts/token/ERC20/extensions/ERC20FlashMint.sol -/contracts/token/ERC20/extensions/ERC20Pausable.sol -/contracts/token/ERC20/extensions/ERC20Snapshot.sol -/contracts/token/ERC20/extensions/ERC20Votes.sol -/contracts/token/ERC20/extensions/ERC20VotesComp.sol -/contracts/token/ERC20/extensions/ERC20Wrapper.sol -/contracts/token/ERC20/extensions/ERC4626.sol -/contracts/token/ERC20/extensions/IERC20Metadata.sol -/contracts/token/ERC20/IERC20.sol -/contracts/token/ERC20/presets/ERC20PresetFixedSupply.sol -/contracts/token/ERC20/presets/ERC20PresetMinterPauser.sol -/contracts/token/ERC20/utils/SafeERC20.sol -/contracts/token/ERC20/utils/TokenTimelock.sol -/contracts/token/ERC721/ERC721.sol -/contracts/token/ERC721/extensions/draft-ERC721Votes.sol -/contracts/token/ERC721/extensions/ERC721Burnable.sol -/contracts/token/ERC721/extensions/ERC721Consecutive.sol -/contracts/token/ERC721/extensions/ERC721Enumerable.sol -/contracts/token/ERC721/extensions/ERC721Pausable.sol -/contracts/token/ERC721/extensions/ERC721Royalty.sol -/contracts/token/ERC721/extensions/ERC721URIStorage.sol -/contracts/token/ERC721/extensions/IERC721Enumerable.sol -/contracts/token/ERC721/extensions/IERC721Metadata.sol -/contracts/token/ERC721/IERC721.sol -/contracts/token/ERC721/IERC721Receiver.sol -/contracts/token/ERC721/presets/ERC721PresetMinterPauserAutoId.sol -/contracts/token/ERC721/utils/ERC721Holder.sol -/contracts/token/ERC777/ERC777.sol -/contracts/token/ERC777/IERC777.sol -/contracts/token/ERC777/IERC777Recipient.sol -/contracts/token/ERC777/IERC777Sender.sol -/contracts/token/ERC777/presets/ERC777PresetFixedSupply.sol -/contracts/utils/Address.sol -/contracts/utils/Arrays.sol -/contracts/utils/Base64.sol -/contracts/utils/Checkpoints.sol -/contracts/utils/Context.sol -/contracts/utils/Counters.sol -/contracts/utils/Create2.sol -/contracts/utils/cryptography/draft-EIP712.sol -/contracts/utils/cryptography/ECDSA.sol -/contracts/utils/cryptography/EIP712.sol -/contracts/utils/cryptography/MerkleProof.sol -/contracts/utils/cryptography/SignatureChecker.sol -/contracts/utils/escrow/ConditionalEscrow.sol -/contracts/utils/escrow/Escrow.sol -/contracts/utils/escrow/RefundEscrow.sol -/contracts/utils/introspection/ERC165.sol -/contracts/utils/introspection/ERC165Checker.sol -/contracts/utils/introspection/ERC165Storage.sol -/contracts/utils/introspection/ERC1820Implementer.sol -/contracts/utils/introspection/IERC165.sol -/contracts/utils/introspection/IERC1820Implementer.sol -/contracts/utils/introspection/IERC1820Registry.sol -/contracts/utils/math/Math.sol -/contracts/utils/math/SafeCast.sol -/contracts/utils/math/SafeMath.sol -/contracts/utils/math/SignedMath.sol -/contracts/utils/math/SignedSafeMath.sol -/contracts/utils/Multicall.sol -/contracts/utils/StorageSlot.sol -/contracts/utils/Strings.sol -/contracts/utils/structs/BitMaps.sol -/contracts/utils/structs/DoubleEndedQueue.sol -/contracts/utils/structs/EnumerableMap.sol -/contracts/utils/structs/EnumerableSet.sol -/contracts/utils/Timers.sol -/contracts/vendor/amb/IAMB.sol -/contracts/vendor/arbitrum/IArbSys.sol -/contracts/vendor/arbitrum/IBridge.sol -/contracts/vendor/arbitrum/IInbox.sol -/contracts/vendor/arbitrum/IMessageProvider.sol -/contracts/vendor/arbitrum/IOutbox.sol -/contracts/vendor/compound/ICompoundTimelock.sol -/contracts/vendor/optimism/ICrossDomainMessenger.sol -/contracts/vendor/polygon/IFxMessageProcessor.sol \ No newline at end of file From 58390a8a497ccf41efb6c7463d01bab26809bf8b Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 15 Sep 2022 00:55:57 +0200 Subject: [PATCH 07/12] rm undefined --- libs/remix-ui/editor/src/lib/providers/completionProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts index 6e09dc1914..78455fbe22 100644 --- a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts @@ -4,7 +4,7 @@ import { isArray, last } from "lodash" import { editor, languages, Position } from "monaco-editor" import monaco from "../../types/monaco" import { EditorUIProps } from "../remix-ui-editor" -import { GeCompletionUnits, GetCompletionKeywords, getCompletionSnippets, GetCompletionTypes, getContextualAutoCompleteBTypeName, getContextualAutoCompleteByGlobalVariable, GetContractRepositories, GetGlobalFunctions, GetGlobalVariable, GetImports } from "./completion/completionGlobals" +import { GeCompletionUnits, GetCompletionKeywords, getCompletionSnippets, GetCompletionTypes, getContextualAutoCompleteBTypeName, getContextualAutoCompleteByGlobalVariable, GetGlobalFunctions, GetGlobalVariable, GetImports } from "./completion/completionGlobals" export class RemixCompletionProvider implements languages.CompletionItemProvider { From 6b115f555064d751c31075dc28a89ce521e16328 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 15 Sep 2022 10:37:57 +0200 Subject: [PATCH 08/12] more error handling --- .../parser/services/code-parser-compiler.ts | 128 ++++++++++++------ .../parser/services/code-parser-imports.ts | 6 +- .../providers/completion/completionGlobals.ts | 7 - .../completion/contracts/contracts.txt | 31 +++++ .../src/lib/providers/completionProvider.ts | 7 +- .../src/lib/providers/definitionProvider.ts | 18 ++- libs/remix-ui/search/src/index.ts | 4 +- package.json | 2 +- 8 files changed, 139 insertions(+), 64 deletions(-) diff --git a/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts b/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts index 9acd434728..96daa42f4a 100644 --- a/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts +++ b/apps/remix-ide/src/app/plugins/parser/services/code-parser-compiler.ts @@ -8,22 +8,23 @@ import { fileDecoration, fileDecorationType } from '@remix-ui/file-decorators' import { sourceMappingDecoder } from '@remix-project/remix-debug' import { CompilerRetriggerMode } from '@remix-project/remix-solidity-ts'; import { MarkerSeverity } from 'monaco-editor'; +import { findLinesInStringWithMatch, SearchResultLine } from '@remix-ui/search' type errorMarker = { message: string severity: MarkerSeverity position: { - start: { - line: number - column: number - }, - end: { - line: number - column: number - } + start: { + line: number + column: number + }, + end: { + line: number + column: number + } }, file: string - } +} export default class CodeParserCompiler { plugin: CodeParser compiler: any // used to compile the current file seperately from the main compiler @@ -39,41 +40,51 @@ export default class CodeParserCompiler { init() { this.onAstFinished = async (success, data: CompilationResult, source: CompilationSource, input: any, version) => { - //console.log('onAstFinished', success, data, source, input, version) this.plugin.call('editor', 'clearAnnotations') this.errorState = true const result = new CompilerAbstract('soljson', data, source, input) let allErrors: errorMarker[] = [] - if (data.errors) { - const sources = result.getSourceCode().sources - for (const error of data.errors) { - //console.log(error) - const lineBreaks = sourceMappingDecoder.getLinebreakPositions(sources[error.sourceLocation.file].content) - const lineColumn = sourceMappingDecoder.convertOffsetToLineColumn({ - start: error.sourceLocation.start, - length: error.sourceLocation.end - error.sourceLocation.start - }, lineBreaks) - - const filePath = error.sourceLocation.file - - allErrors = [...allErrors, { - message: error.formattedMessage, - severity: error.severity === 'error' ? MarkerSeverity.Error : MarkerSeverity.Warning, - position: { - start: { - line: ((lineColumn.start && lineColumn.start.line) || 0) + 1, - column: ((lineColumn.start && lineColumn.start.column) || 0) + 1 - }, - end: { - line: ((lineColumn.end && lineColumn.end.line) || 0) + 1, - column: ((lineColumn.end && lineColumn.end.column) || 0) + 1 + if (data.errors || data.error) { + const file = await this.plugin.call('fileManager', 'getCurrentFile') + const currentFileContent = await this.plugin.call('fileManager', 'readFile', file) + const sources = result.getSourceCode().sources || [] + if (data.error) { + if (data.error.formattedMessage) { + // mark this file as error + const errorMarker = await this.createErrorMarker(data.error, file, { start: { line: 0, column: 0 }, end: { line: 0, column: 100 } }) + allErrors = [...allErrors, errorMarker] + } + } else { + for (const error of data.errors) { + if (!error.sourceLocation) { + // mark this file as error + const errorMarker = await this.createErrorMarker(error, file, { start: { line: 0, column: 0 }, end: { line: 0, column: 100 } }) + allErrors = [...allErrors, errorMarker] + } else { + const lineBreaks = sourceMappingDecoder.getLinebreakPositions(sources[error.sourceLocation.file].content) + const lineColumn = sourceMappingDecoder.convertOffsetToLineColumn({ + start: error.sourceLocation.start, + length: error.sourceLocation.end - error.sourceLocation.start + }, lineBreaks) + + + const filePath = error.sourceLocation.file + const fileTarget = await this.plugin.call('fileManager', 'getUrlFromPath', filePath) + + const importFilePositions = await this.getPositionForImportErrors(fileTarget.file, currentFileContent) + for (const importFilePosition of importFilePositions) { + for (const line of importFilePosition.lines) { + allErrors = [...allErrors, await this.createErrorMarker(error, file, line.position)] + } } + + allErrors = [...allErrors, await this.createErrorMarker(error, filePath, lineColumn)] } - , file: filePath - }] + } } + const displayErrors = await this.plugin.call('config', 'getAppParameter', 'display-errors') - if(displayErrors) await this.plugin.call('editor', 'addErrorMarker', allErrors) + if (displayErrors) await this.plugin.call('editor', 'addErrorMarker', allErrors) this.addDecorators(allErrors, sources) } else { await this.plugin.call('editor', 'clearErrorMarkers', result.getSourceCode().sources) @@ -144,14 +155,14 @@ export default class CodeParserCompiler { this.compiler.compile(sources, this.plugin.currentFile) } } catch (e) { - // do nothing + // do nothing } } async addDecorators(allErrors: errorMarker[], sources: any) { const displayErrors = await this.plugin.call('config', 'getAppParameter', 'display-errors') - if(!displayErrors) return - const errorsPerFiles: {[fileName: string]: errorMarker[]} = {} + if (!displayErrors) return + const errorsPerFiles: { [fileName: string]: errorMarker[] } = {} for (const error of allErrors) { if (!errorsPerFiles[error.file]) { errorsPerFiles[error.file] = [] @@ -165,7 +176,7 @@ export default class CodeParserCompiler { } // sort errorPerFiles by error priority - const sortedErrorsPerFiles: {[fileName: string]: errorMarker[]} = {} + const sortedErrorsPerFiles: { [fileName: string]: errorMarker[] } = {} for (const fileName in errorsPerFiles) { const errors = errorsPerFiles[fileName] errors.sort((a, b) => { @@ -179,10 +190,11 @@ export default class CodeParserCompiler { const decorators: fileDecoration[] = [] for (const fileName in sortedErrorsPerFiles) { const errors = sortedErrorsPerFiles[fileName] + const fileTarget = await this.plugin.call('fileManager', 'getPathFromUrl', fileName) const decorator: fileDecoration = { - path: fileName, + path: fileTarget.file, isDirectory: false, - fileStateType: errors[0].severity == MarkerSeverity.Error? fileDecorationType.Error : fileDecorationType.Warning, + fileStateType: errors[0].severity == MarkerSeverity.Error ? fileDecorationType.Error : fileDecorationType.Warning, fileStateLabelClass: errors[0].severity == MarkerSeverity.Error ? 'text-danger' : 'text-warning', fileStateIconClass: '', fileStateIcon: '', @@ -194,8 +206,9 @@ export default class CodeParserCompiler { decorators.push(decorator) } for (const fileName of filesWithOutErrors) { + const fileTarget = await this.plugin.call('fileManager', 'getPathFromUrl', fileName) const decorator: fileDecoration = { - path: fileName, + path: fileTarget.file, isDirectory: false, fileStateType: fileDecorationType.None, fileStateLabelClass: '', @@ -212,9 +225,27 @@ export default class CodeParserCompiler { } + async createErrorMarker(error: any, filePath: string, lineColumn): Promise { + return { + message: error.formattedMessage, + severity: error.severity === 'error' ? MarkerSeverity.Error : MarkerSeverity.Warning, + position: { + start: { + line: ((lineColumn.start && lineColumn.start.line) || 0) + 1, + column: ((lineColumn.start && lineColumn.start.column) || 0) + 1 + }, + end: { + line: ((lineColumn.end && lineColumn.end.line) || 0) + 1, + column: ((lineColumn.end && lineColumn.end.column) || 0) + 1 + } + } + , file: filePath + } + } + async clearDecorators(sources: any) { const decorators: fileDecoration[] = [] - if(!sources) return + if (!sources) return for (const fileName of Object.keys(sources)) { const decorator: fileDecoration = { path: fileName, @@ -234,4 +265,13 @@ export default class CodeParserCompiler { await this.plugin.call('fileDecorator', 'setFileDecorators', decorators) } + async getPositionForImportErrors(importedFileName: string, text: string) { + const re = new RegExp(importedFileName, 'gi') + const result: SearchResultLine[] = findLinesInStringWithMatch( + text, + re + ) + return result + } + } \ No newline at end of file diff --git a/apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts b/apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts index d2261c3154..9eaef92dd9 100644 --- a/apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts +++ b/apps/remix-ide/src/app/plugins/parser/services/code-parser-imports.ts @@ -23,8 +23,6 @@ export default class CodeParserImports { async init() { // @ts-ignore const txt = await import('raw-loader!libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt') - - // eslint-disable-next-line @typescript-eslint/no-unused-vars this.data.modules = txt.default.split('\n') .filter(x => x !== '') .map(x => x.replace('./node_modules/', '')) @@ -38,13 +36,11 @@ export default class CodeParserImports { // get unique first words of the values in the array this.data.packages = [...new Set(this.data.modules.map(x => x.split('/')[0]))] - console.log(this.data) } setFileTree = async () => { this.data.files = await this.getDirectory('/') - this.data.files = this.data.files.filter(x => x.endsWith('.sol') && !x.startsWith('.deps')) - console.log(this.data) + this.data.files = this.data.files.filter(x => x.endsWith('.sol') && !x.startsWith('.deps') && !x.startsWith('.git')) } getDirectory = async (dir: string) => { diff --git a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts index ac8e3b9a61..4d69093b1c 100644 --- a/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts +++ b/libs/remix-ui/editor/src/lib/providers/completion/completionGlobals.ts @@ -183,13 +183,6 @@ export function getCompletionSnippets(range: IRange, monaco): monaco.languages.C insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, range }, - { - label: 'import', - kind: monaco.languages.CompletionItemKind.Snippet, - insertText: 'import "${1:library}";', - insertTextRules: monaco.languages.CompletionItemInsertTextRule.InsertAsSnippet, - range - }, { label: 'SPDX-License-Identifier', kind: monaco.languages.CompletionItemKind.Snippet, diff --git a/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt b/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt index 94615103e0..8342638bf6 100644 --- a/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt +++ b/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt @@ -1,3 +1,34 @@ +./node_modules/@hq20/contracts/contracts/access/AccessControlBasic.sol +./node_modules/@hq20/contracts/contracts/access/Administered.sol +./node_modules/@hq20/contracts/contracts/access/AuthorizedAccess.sol +./node_modules/@hq20/contracts/contracts/access/Community.sol +./node_modules/@hq20/contracts/contracts/access/Democracy.sol +./node_modules/@hq20/contracts/contracts/access/Hierarchy.sol +./node_modules/@hq20/contracts/contracts/classifieds/Classifieds.sol +./node_modules/@hq20/contracts/contracts/dao/DAO.sol +./node_modules/@hq20/contracts/contracts/dao/VentureEth.sol +./node_modules/@hq20/contracts/contracts/energy/EnergyMarket.sol +./node_modules/@hq20/contracts/contracts/exchange/UniswapExchange.sol +./node_modules/@hq20/contracts/contracts/exchange/UniswapFactory.sol +./node_modules/@hq20/contracts/contracts/introspection/erc165/ERC20Whitelisted.sol +./node_modules/@hq20/contracts/contracts/introspection/erc165/IWhitelist.sol +./node_modules/@hq20/contracts/contracts/introspection/erc165/WhitelistERC165.sol +./node_modules/@hq20/contracts/contracts/introspection/erc165/WhitelistInterfaceId.sol +./node_modules/@hq20/contracts/contracts/issuance/Issuance.sol +./node_modules/@hq20/contracts/contracts/issuance/IssuanceEth.sol +./node_modules/@hq20/contracts/contracts/lists/DoubleLinkedList.sol +./node_modules/@hq20/contracts/contracts/lists/LinkedList.sol +./node_modules/@hq20/contracts/contracts/math/DecimalMath.sol +./node_modules/@hq20/contracts/contracts/state/StateMachine.sol +./node_modules/@hq20/contracts/contracts/token/ERC20DividendableEth.sol +./node_modules/@hq20/contracts/contracts/token/ERC20Mintable.sol +./node_modules/@hq20/contracts/contracts/token/ERC721Mintable.sol +./node_modules/@hq20/contracts/contracts/token/IERC20Detailed.sol +./node_modules/@hq20/contracts/contracts/token/IERC20Mintable.sol +./node_modules/@hq20/contracts/contracts/utils/SafeCast.sol +./node_modules/@hq20/contracts/contracts/voting/Democratic.sol +./node_modules/@hq20/contracts/contracts/voting/OneManOneVote.sol +./node_modules/@hq20/contracts/contracts/voting/OneTokenOneVote.sol ./node_modules/@openzeppelin/contracts/access/AccessControl.sol ./node_modules/@openzeppelin/contracts/access/AccessControlCrossChain.sol ./node_modules/@openzeppelin/contracts/access/AccessControlEnumerable.sol diff --git a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts index 78455fbe22..dafcd10011 100644 --- a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts @@ -28,16 +28,16 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider startColumn: word.startColumn, endColumn: word.endColumn }; - console.log(word) + const line = model.getLineContent(position.lineNumber) let nodes: AstNode[] = [] let suggestions: monaco.languages.CompletionItem[] = [] - console.log('context', context.triggerCharacter) + if (context.triggerCharacter === '"' || context.triggerCharacter === '@' || context.triggerCharacter === '/') { const lastpart = line.substring(0, position.column - 1).split(';').pop() - console.log('lastpart', lastpart) + if (lastpart.startsWith('import')) { const imports = await this.props.plugin.call('codeParser', 'getImports') if (context.triggerCharacter === '"' || context.triggerCharacter === '@') { @@ -46,7 +46,6 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider ] } else if (context.triggerCharacter === '/') { const word = line.split('"')[1] - console.log(word) suggestions = [...suggestions, ...GetImports(range, this.monaco, imports, word), ] diff --git a/libs/remix-ui/editor/src/lib/providers/definitionProvider.ts b/libs/remix-ui/editor/src/lib/providers/definitionProvider.ts index d6236cb5e3..9d6daee730 100644 --- a/libs/remix-ui/editor/src/lib/providers/definitionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/definitionProvider.ts @@ -13,8 +13,22 @@ export class RemixDefinitionProvider implements monaco.languages.DefinitionProvi // eslint-disable-next-line @typescript-eslint/no-unused-vars async provideDefinition(model: monaco.editor.ITextModel, position: monaco.Position, token: monaco.CancellationToken): Promise { const cursorPosition = this.props.editorAPI.getCursorPosition() - const jumpLocation = await this.jumpToDefinition(cursorPosition) - + let jumpLocation = await this.jumpToDefinition(cursorPosition) + if (!jumpLocation || !jumpLocation.fileName) { + const line = model.getLineContent(position.lineNumber) + const lastpart = line.substring(0, position.column - 1).split(';').pop() + if (lastpart.startsWith('import')) { + const importPath = line.substring(lastpart.indexOf('"') + 1) + const importPath2 = importPath.substring(0, importPath.indexOf('"')) + jumpLocation = { + startLineNumber: 1, + startColumn: 1, + endColumn: 1, + endLineNumber: 1, + fileName: importPath2 + } + } + } return [{ uri: this.monaco.Uri.parse(jumpLocation.fileName), range: { diff --git a/libs/remix-ui/search/src/index.ts b/libs/remix-ui/search/src/index.ts index 8617e2ddff..72588397c4 100644 --- a/libs/remix-ui/search/src/index.ts +++ b/libs/remix-ui/search/src/index.ts @@ -1 +1,3 @@ -export { SearchTab } from './lib/components/Search'; \ No newline at end of file +export { SearchTab } from './lib/components/Search'; +export * from './lib/components/results/SearchHelper'; +export * from './lib/types'; \ No newline at end of file diff --git a/package.json b/package.json index e73b61e6ee..e41139dd69 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ "watch": "watchify apps/remix-ide/src/index.js -dv -p browserify-reload -o apps/remix-ide/build/app.js --exclude solc", "reinstall": "rm ./node-modules/ -rf && rm yarn.lock && rm ./build/ -rf && yarn install & yarn run build", "ganache-cli": "npx ganache-cli", - "build-contracts": "find ./node_modules/@openzeppelin/contracts | grep -i '.sol' > libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt && find ./node_modules/@uniswap/v3-core/contracts | grep -i '.sol' >> libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt" + "build-contracts": "find ./node_modules/@hq20/contracts | grep -i '.sol' > libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt && find ./node_modules/@openzeppelin/contracts | grep -i '.sol' >> libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt && find ./node_modules/@uniswap/v3-core/contracts | grep -i '.sol' >> libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt" }, "browserify": { "transform": [ From 02acc06a03efbdcf2f856db046812074b05388d7 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 15 Sep 2022 10:42:40 +0200 Subject: [PATCH 09/12] lint --- libs/remix-ui/editor/src/lib/providers/completionProvider.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts index dafcd10011..7202b1076a 100644 --- a/libs/remix-ui/editor/src/lib/providers/completionProvider.ts +++ b/libs/remix-ui/editor/src/lib/providers/completionProvider.ts @@ -1,6 +1,6 @@ import { sourceMappingDecoder } from "@remix-project/remix-debug" import { AstNode } from "@remix-project/remix-solidity-ts" -import { isArray, last } from "lodash" +import { isArray } from "lodash" import { editor, languages, Position } from "monaco-editor" import monaco from "../../types/monaco" import { EditorUIProps } from "../remix-ui-editor" From e3901cb1c121d83947704b696bc6e704f7fd8baa Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 15 Sep 2022 10:58:46 +0200 Subject: [PATCH 10/12] events --- apps/remix-ide/src/app/plugins/parser/code-parser.tsx | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/apps/remix-ide/src/app/plugins/parser/code-parser.tsx b/apps/remix-ide/src/app/plugins/parser/code-parser.tsx index 9b51e42a4e..4e8db57d56 100644 --- a/apps/remix-ide/src/app/plugins/parser/code-parser.tsx +++ b/apps/remix-ide/src/app/plugins/parser/code-parser.tsx @@ -127,6 +127,14 @@ export class CodeParser extends Plugin { await this.importService.setFileTree() }) + this.on('fileManager', 'fileAdded', async () => { + await this.importService.setFileTree() + }) + this.on('fileManager', 'fileRemoved', async () => { + await this.importService.setFileTree() + }) + + this.on('fileManager', 'currentFileChanged', async () => { await this.call('editor', 'discardLineTexts') From 724df06a12d7d93483230fd612a6e4db07568846 Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 15 Sep 2022 11:02:32 +0200 Subject: [PATCH 11/12] rm module --- .../completion/contracts/contracts.txt | 31 ------------------- package.json | 3 +- yarn.lock | 5 --- 3 files changed, 1 insertion(+), 38 deletions(-) diff --git a/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt b/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt index 8342638bf6..94615103e0 100644 --- a/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt +++ b/libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt @@ -1,34 +1,3 @@ -./node_modules/@hq20/contracts/contracts/access/AccessControlBasic.sol -./node_modules/@hq20/contracts/contracts/access/Administered.sol -./node_modules/@hq20/contracts/contracts/access/AuthorizedAccess.sol -./node_modules/@hq20/contracts/contracts/access/Community.sol -./node_modules/@hq20/contracts/contracts/access/Democracy.sol -./node_modules/@hq20/contracts/contracts/access/Hierarchy.sol -./node_modules/@hq20/contracts/contracts/classifieds/Classifieds.sol -./node_modules/@hq20/contracts/contracts/dao/DAO.sol -./node_modules/@hq20/contracts/contracts/dao/VentureEth.sol -./node_modules/@hq20/contracts/contracts/energy/EnergyMarket.sol -./node_modules/@hq20/contracts/contracts/exchange/UniswapExchange.sol -./node_modules/@hq20/contracts/contracts/exchange/UniswapFactory.sol -./node_modules/@hq20/contracts/contracts/introspection/erc165/ERC20Whitelisted.sol -./node_modules/@hq20/contracts/contracts/introspection/erc165/IWhitelist.sol -./node_modules/@hq20/contracts/contracts/introspection/erc165/WhitelistERC165.sol -./node_modules/@hq20/contracts/contracts/introspection/erc165/WhitelistInterfaceId.sol -./node_modules/@hq20/contracts/contracts/issuance/Issuance.sol -./node_modules/@hq20/contracts/contracts/issuance/IssuanceEth.sol -./node_modules/@hq20/contracts/contracts/lists/DoubleLinkedList.sol -./node_modules/@hq20/contracts/contracts/lists/LinkedList.sol -./node_modules/@hq20/contracts/contracts/math/DecimalMath.sol -./node_modules/@hq20/contracts/contracts/state/StateMachine.sol -./node_modules/@hq20/contracts/contracts/token/ERC20DividendableEth.sol -./node_modules/@hq20/contracts/contracts/token/ERC20Mintable.sol -./node_modules/@hq20/contracts/contracts/token/ERC721Mintable.sol -./node_modules/@hq20/contracts/contracts/token/IERC20Detailed.sol -./node_modules/@hq20/contracts/contracts/token/IERC20Mintable.sol -./node_modules/@hq20/contracts/contracts/utils/SafeCast.sol -./node_modules/@hq20/contracts/contracts/voting/Democratic.sol -./node_modules/@hq20/contracts/contracts/voting/OneManOneVote.sol -./node_modules/@hq20/contracts/contracts/voting/OneTokenOneVote.sol ./node_modules/@openzeppelin/contracts/access/AccessControl.sol ./node_modules/@openzeppelin/contracts/access/AccessControlCrossChain.sol ./node_modules/@openzeppelin/contracts/access/AccessControlEnumerable.sol diff --git a/package.json b/package.json index e41139dd69..d3dd0f493e 100644 --- a/package.json +++ b/package.json @@ -109,7 +109,7 @@ "watch": "watchify apps/remix-ide/src/index.js -dv -p browserify-reload -o apps/remix-ide/build/app.js --exclude solc", "reinstall": "rm ./node-modules/ -rf && rm yarn.lock && rm ./build/ -rf && yarn install & yarn run build", "ganache-cli": "npx ganache-cli", - "build-contracts": "find ./node_modules/@hq20/contracts | grep -i '.sol' > libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt && find ./node_modules/@openzeppelin/contracts | grep -i '.sol' >> libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt && find ./node_modules/@uniswap/v3-core/contracts | grep -i '.sol' >> libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt" + "build-contracts": "find ./node_modules/@openzeppelin/contracts | grep -i '.sol' > libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt && find ./node_modules/@uniswap/v3-core/contracts | grep -i '.sol' >> libs/remix-ui/editor/src/lib/providers/completion/contracts/contracts.txt" }, "browserify": { "transform": [ @@ -235,7 +235,6 @@ "@babel/preset-typescript": "7.9.0", "@babel/register": "^7.4.4", "@fortawesome/fontawesome-free": "^5.8.1", - "@hq20/contracts": "^0.0.6", "@nrwl/cli": "12.3.6", "@nrwl/eslint-plugin-nx": "12.3.6", "@nrwl/jest": "12.3.6", diff --git a/yarn.lock b/yarn.lock index d5e5cff8a1..70481bf105 100644 --- a/yarn.lock +++ b/yarn.lock @@ -2475,11 +2475,6 @@ resolved "https://registry.yarnpkg.com/@gar/promisify/-/promisify-1.1.2.tgz#30aa825f11d438671d585bd44e7fd564535fc210" integrity sha512-82cpyJyKRoQoRi+14ibCeGPu0CwypgtBAdBhq1WfvagpCZNKqwXbKwXllYSMG91DhmG4jt9gN8eP6lGOtozuaw== -"@hq20/contracts@^0.0.6": - version "0.0.6" - resolved "https://registry.yarnpkg.com/@hq20/contracts/-/contracts-0.0.6.tgz#fc0a05884294da8757c4187f8567638982b74b6a" - integrity sha512-l94ARK0LfcRY7Y5EiInA+0vdXh8lnkTRAw9unli7UC75DY7aBMJl4OqTT5SMdm/n4N1dVVhCnyCM1W84UAx2Vw== - "@isomorphic-git/idb-keyval@3.3.2": version "3.3.2" resolved "https://registry.yarnpkg.com/@isomorphic-git/idb-keyval/-/idb-keyval-3.3.2.tgz#c0509a6c5987d8a62efb3e47f2815bcc5eda2489" From 8d0f783b41d6c188efda524ec91fcc1bbf2725ae Mon Sep 17 00:00:00 2001 From: filip mertens Date: Thu, 15 Sep 2022 16:08:44 +0200 Subject: [PATCH 12/12] add file --- apps/remix-ide-e2e/src/commands/addFile.ts | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/apps/remix-ide-e2e/src/commands/addFile.ts b/apps/remix-ide-e2e/src/commands/addFile.ts index f9536bb259..a1aa1a5948 100644 --- a/apps/remix-ide-e2e/src/commands/addFile.ts +++ b/apps/remix-ide-e2e/src/commands/addFile.ts @@ -2,7 +2,7 @@ import { NightwatchBrowser, NightwatchContractContent } from 'nightwatch' import EventEmitter from 'events' class AddFile extends EventEmitter { - command (this: NightwatchBrowser, name: string, content: NightwatchContractContent): NightwatchBrowser { + command(this: NightwatchBrowser, name: string, content: NightwatchContractContent): NightwatchBrowser { this.api.perform((done) => { addFile(this.api, name, content, () => { done() @@ -13,9 +13,18 @@ class AddFile extends EventEmitter { } } -function addFile (browser: NightwatchBrowser, name: string, content: NightwatchContractContent, done: VoidFunction) { - browser.clickLaunchIcon('udapp') - .clickLaunchIcon('filePanel') +function addFile(browser: NightwatchBrowser, name: string, content: NightwatchContractContent, done: VoidFunction) { + browser + .isVisible({ + selector: "//*[@data-id='sidePanelSwapitTitle' and contains(.,'File explorer')]", + locateStrategy: 'xpath', + suppressNotFoundErrors: true, + timeout: 1000 + }, (okVisible) => { + if (!okVisible.value) { + browser.clickLaunchIcon('filePanel') + } + }) .waitForElementVisible('li[data-id="treeViewLitreeViewItemREADME.txt"]') .click('li[data-id="treeViewLitreeViewItemREADME.txt"]').pause(1000) // focus on root directory .elements('css selector', `li[data-id="treeViewLitreeViewItem${name}"]`, (res) => {