Merge branch 'master' into intl

pull/2581/head
drafish 2 years ago
commit 0e9707aab3
  1. 20
      apps/remix-ide-e2e/src/tests/homeTab.test.ts
  2. 3
      apps/remix-ide/src/app/editor/editor.js
  3. 2
      apps/remix-ide/src/app/files/fileManager.ts
  4. 10
      apps/remix-ide/src/app/panels/file-panel.js
  5. 15
      apps/remix-ide/src/app/plugins/parser/services/code-parser-antlr-service.ts
  6. 2
      libs/remix-ui/home-tab/src/lib/remix-ui-home-tab.tsx

@ -0,0 +1,20 @@
'use strict'
import { NightwatchBrowser } from 'nightwatch'
import init from '../helpers/init'
module.exports = {
before: function (browser: NightwatchBrowser, done: VoidFunction) {
init(browser, done)
},
'Should create new file': function (browser: NightwatchBrowser) {
browser
.waitForElementVisible('*[data-id="homeTabNewFile"]')
.click('*[data-id="homeTabNewFile"]')
.waitForElementContainsText('*[data-id$="/blank"]', '', 60000)
.sendKeys('*[data-id$="/blank"] .remixui_items', 'newTestFile')
.sendKeys('*[data-id$="/blank"] .remixui_items', browser.Keys.ENTER)
.waitForElementVisible('li[data-id="treeViewLitreeViewItemnewTestFile.sol"]')
}
}

@ -5,7 +5,6 @@ import { EditorUI } from '@remix-ui/editor' // eslint-disable-line
import { Plugin } from '@remixproject/engine'
import * as packageJson from '../../../../../package.json'
import { PluginViewWrapper } from '@remix-ui/helper'
import { exists } from 'fs'
const EventManager = require('../../lib/events')
@ -199,7 +198,7 @@ class Editor extends Plugin {
return ext && this.modes[ext] ? this.modes[ext] : this.modes.txt
}
async handleTypeScriptDependenciesOf (path, content, readFile) {
async handleTypeScriptDependenciesOf (path, content, readFile, exists) {
if (path.endsWith('.ts')) {
// extract the import, resolve their content
// and add the imported files to Monaco through the `addModel`

@ -635,7 +635,7 @@ class FileManager extends Plugin {
try {
// This make sure dependencies are loaded in the editor context.
// This ensure monaco is aware of deps artifacts, so it can provide basic features like "go to" symbols.
await this.editor.handleTypeScriptDependenciesOf(file, content, path => this.readFile(path))
await this.editor.handleTypeScriptDependenciesOf(file, content, path => this.readFile(path), path => this.exists(path))
} catch (e) {
console.log('unable to handle TypeScript dependencies of', file)
}

@ -102,10 +102,7 @@ module.exports = class Filepanel extends ViewPlugin {
createNewFile () {
return new Promise((resolve, reject) => {
const provider = this.fileManager.currentFileProvider()
const dir = provider.workspace || '/'
this.emit('createNewFileInputReducerEvent', dir, (err, data) => {
this.emit('createNewFileInputReducerEvent', '/', (err, data) => {
if (err) reject(err)
else resolve(data)
})
@ -114,10 +111,7 @@ module.exports = class Filepanel extends ViewPlugin {
uploadFile (target) {
return new Promise((resolve, reject) => {
const provider = this.fileManager.currentFileProvider()
const dir = provider.workspace || '/'
return this.emit('uploadFileReducerEvent', dir, target, (err, data) => {
return this.emit('uploadFileReducerEvent', '/', target, (err, data) => {
if (err) reject(err)
else resolve(data)
})

@ -24,7 +24,8 @@ export default class CodeParserAntlrService {
worker: Worker
parserStartTime: number = 0
workerTimer: NodeJS.Timer
parserTreshHold: number = 10
parserThreshold: number = 10
parserThresholdSampleAmount = 3
cache: {
[name: string]: {
text: string,
@ -58,7 +59,7 @@ export default class CodeParserAntlrService {
ast: ev.data.ast,
duration: ev.data.duration,
blocks: ev.data.blocks,
blockDurations: self.cache[ev.data.file].blockDurations? [...self.cache[ev.data.file].blockDurations.slice(-3), ev.data.blockDuration]: [ev.data.blockDuration]
blockDurations: self.cache[ev.data.file].blockDurations? [...self.cache[ev.data.file].blockDurations.slice(-self.parserThresholdSampleAmount), ev.data.blockDuration]: [ev.data.blockDuration]
}
self.setFileParsingState(ev.data.file)
}
@ -70,17 +71,15 @@ export default class CodeParserAntlrService {
setFileParsingState(file: string) {
if (this.cache[file]) {
if (this.cache[file].blockDurations && this.cache[file].blockDurations.length > 3) {
if (this.cache[file].blockDurations && this.cache[file].blockDurations.length > this.parserThresholdSampleAmount) {
// calculate average of durations to determine if the parsing should be disabled
const values = [...this.cache[file].blockDurations]
const average = values.reduce((a, b) => a + b, 0) / values.length
if (average > this.parserTreshHold) {
if (average > this.parserThreshold) {
this.cache[file].parsingEnabled = false
this.plugin.call('notification', 'toast','Some autocomplete features will be temporarily disabled because the file takes too long to process.')
} else {
this.cache[file].parsingEnabled = true
}
}
}
}
}
@ -249,7 +248,7 @@ export default class CodeParserAntlrService {
const startTime = Date.now()
const blocks = (SolidityParser as any).parseBlock(fileContent, { loc: true, range: true, tolerant: true })
if(this.cache[this.plugin.currentFile] && this.cache[this.plugin.currentFile].blockDurations){
this.cache[this.plugin.currentFile].blockDurations = [...this.cache[this.plugin.currentFile].blockDurations.slice(-3), Date.now() - startTime]
this.cache[this.plugin.currentFile].blockDurations = [...this.cache[this.plugin.currentFile].blockDurations.slice(-this.parserThresholdSampleAmount), Date.now() - startTime]
this.setFileParsingState(this.plugin.currentFile)
}
if (blocks) this.cache[this.plugin.currentFile].blocks = blocks

@ -273,7 +273,7 @@ export const RemixUiHomeTab = (props: RemixUiHomeTabProps) => {
<h4><FormattedMessage id='home.file' defaultMessage='File' /></h4>
<p className="mb-1">
<i className="mr-2 far fa-file"></i>
<label className="ml-1 mb-1 remixui_home_text" onClick={() => createNewFile()}><FormattedMessage id='home.newFile' defaultMessage='New File' /></label>
<label className="ml-1 mb-1 remixui_home_text" data-id="homeTabNewFile" onClick={() => createNewFile()}><FormattedMessage id='home.newFile' defaultMessage='New File' /></label>
</p>
<p className="mb-1">
<i className="mr-2 far fa-file-alt"></i>

Loading…
Cancel
Save