autcomplete testing

editorcontextDummy
filip mertens 2 years ago
parent e6409285b8
commit 759678afe3
  1. 73
      apps/remix-ide-e2e/src/tests/editorAutoComplete.test.ts
  2. 29
      libs/remix-ui/editor/src/lib/providers/completionProvider.ts

@ -2,21 +2,79 @@
import { NightwatchBrowser } from 'nightwatch'
import init from '../helpers/init'
const autoCompleteLineElement = (name: string) => {
return `//*[@class='editor-widget suggest-widget visible']//*[@class='contents' and contains(.,'${name}')]`
}
module.exports = {
before: function (browser: NightwatchBrowser, done: VoidFunction) {
init(browser, done, 'http://127.0.0.1:8080', false)
},
'Should load the test file': function (browser: NightwatchBrowser) {
browser
.openFile('contracts')
browser.openFile('contracts')
.openFile('contracts/3_Ballot.sol')
.waitForElementVisible('#editorView')
.setEditorValue(BallotWithARefToOwner)
.pause(4000) // wait for the compiler to finish
},
'Should put cursor at the end of a line': function (browser: NightwatchBrowser) {
const path = "//*[@class='view-line' and contains(.,'new') and contains(.,'owner')]//span//span[contains(.,';')]"
browser.waitForElementVisible('#editorView')
.useXpath()
.click(path).pause(1000)
.perform(function () {
const actions = this.actions({ async: true });
return actions.
// right arrow key
sendKeys(this.Keys.ARROW_RIGHT).
sendKeys(this.Keys.ARROW_RIGHT)
})
},
'Should type and get msg + sender': function (browser: NightwatchBrowser) {
browser.
perform(function () {
const actions = this.actions({ async: true });
return actions.
sendKeys(this.Keys.ENTER).
sendKeys('msg.')
})
.waitForElementVisible(autoCompleteLineElement('sender'))
.click(autoCompleteLineElement('sender'))
.perform(function () {
const actions = this.actions({ async: true });
return actions.
sendKeys(';').
sendKeys(this.Keys.ENTER)
})
},
'Should type and get completions in the context without this': function (browser: NightwatchBrowser) {
browser.perform(function () {
const actions = this.actions({ async: true });
return actions.
sendKeys(this.Keys.ENTER).
sendKeys('co')
})
.waitForElementVisible(autoCompleteLineElement('chairperson'))
.waitForElementVisible(autoCompleteLineElement('cowner'))
.waitForElementVisible(autoCompleteLineElement('constructor'))
.waitForElementVisible(autoCompleteLineElement('continue'))
.waitForElementVisible(autoCompleteLineElement('contract'))
.waitForElementVisible(autoCompleteLineElement('constant'))
.click(autoCompleteLineElement('cowner'))
},
'Should open local filesystem explorer': function (browser: NightwatchBrowser) {
browser.waitForElementVisible('*[data-id="filePanelFileExplorerTree"]')
.click('[data-id="remixUIWorkspaceExplorer"]')
.setValue('*[data-id="fileExplorerFileUpload"]', 'burnt-coffee.sol')
'Perform dot completion on cowner': function (browser: NightwatchBrowser) {
browser.perform(function () {
const actions = this.actions({ async: true });
return actions.
sendKeys('.')
})
// publicly available functions
.waitForElementVisible(autoCompleteLineElement('changeOwner'))
.waitForElementVisible(autoCompleteLineElement('getOwner'))
// do not show private vars, functions & modifiers & events
.waitForElementNotPresent(autoCompleteLineElement('private'))
.waitForElementNotPresent(autoCompleteLineElement('isOwner'))
.waitForElementNotPresent(autoCompleteLineElement('ownerSet'))
}
}
@ -59,7 +117,6 @@ contract BallotHoverTest {
*/
constructor(bytes32[] memory proposalNames) {
cowner = new Owner();
cowner.getOwner();
chairperson = msg.sender;
voters[chairperson].weight = 1;

@ -14,7 +14,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
this.props = props
this.monaco = monaco
}
triggerCharacters = ['.', '']
@ -32,11 +32,11 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
};
const line = model.getLineContent(position.lineNumber)
let nodes: AstNode[] = []
let nodes: AstNode[] = []
let suggestions: monaco.languages.CompletionItem[] = []
const cursorPosition: number = this.props.editorAPI.getCursorPosition()
if (context.triggerCharacter === '.') {
console.clear()
console.log('TEXT', line)
@ -53,6 +53,10 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
if (globalCompletion) {
dotCompleted = true
suggestions = [...suggestions, ...globalCompletion]
setTimeout(() => {
// eslint-disable-next-line no-debugger
// debugger
}, 2000)
}
if (lastNodeInExpression.name === 'this') {
dotCompleted = true
@ -63,12 +67,16 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
if (node.visibility && node.visibility === 'internal') {
return false
}
if(node.nodeType && node.nodeType === 'ContractDefinition') {
if (node.nodeType && node.nodeType === 'ContractDefinition') {
return false
}
return true
})
nodes = [...nodes, ...thisCompletionNodes]
setTimeout(() => {
// eslint-disable-next-line no-debugger
// debugger
}, 2000)
}
//}
if (expressionElements.length > 1 && !dotCompleted) {
@ -98,7 +106,7 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
if (nodeOfScope.name === last) {
console.log('FOUND NODE', nodeOfScope)
if (nodeOfScope.typeName && nodeOfScope.typeName.nodeType === 'UserDefinedTypeName') {
const declarationOf:AstNode = await this.props.plugin.call('codeParser', 'declarationOf', nodeOfScope.typeName)
const declarationOf: AstNode = await this.props.plugin.call('codeParser', 'declarationOf', nodeOfScope.typeName)
console.log('METHOD 1 HAS DECLARATION OF', declarationOf)
nodes = [...nodes, ...declarationOf.nodes || declarationOf.members]
const baseContracts = await this.getlinearizedBaseContracts(declarationOf)
@ -145,6 +153,17 @@ export class RemixCompletionProvider implements languages.CompletionItemProvider
}
}
}
const filterNodeTypes = ['ContractDefinition', 'ModifierDefinition', 'EventDefinition']
nodes = nodes.filter(node => {
if (node.visibility && node.visibility === 'private') {
return false
}
if (node.nodeType && filterNodeTypes.indexOf(node.nodeType) !== -1) {
return false
}
return true
})
}
} else {

Loading…
Cancel
Save