Changed remixd set and createDir implementation, changed fileProvider's exist implementation

pull/1140/head
ioedeveloper 4 years ago
parent 3a1a03a85c
commit bf80ca988a
  1. 6
      apps/remix-ide/src/app/compiler/compiler-imports.js
  2. 5
      apps/remix-ide/src/app/editor/contextView.js
  3. 2
      apps/remix-ide/src/app/files/fileManager.js
  4. 3
      apps/remix-ide/src/app/files/fileProvider.js
  5. 9
      apps/remix-ide/src/app/files/remixDProvider.js
  6. 2
      apps/remix-ide/src/app/panels/file-panel.js
  7. 4
      apps/remix-ide/src/app/tabs/testTab/testTab.js
  8. 5
      apps/remix-ide/src/app/ui/renderer.js
  9. 14
      apps/remix-ide/src/lib/helper.js
  10. 6
      libs/remix-ui/file-explorer/src/lib/file-explorer.tsx
  11. 73
      libs/remixd/src/services/remixdClient.ts

@ -121,9 +121,7 @@ module.exports = class CompilerImports extends Plugin {
if (provider.type === 'localhost' && !provider.isConnected()) {
return reject(new Error(`file provider ${provider.type} not available while trying to resolve ${url}`))
}
provider.exists(url, (error, exist) => {
if (error) return reject(error)
provider.exists(url).then(exist => {
/*
if the path is absolute and the file does not exist, we can stop here
Doesn't make sense to try to resolve "localhost/node_modules/localhost/node_modules/<path>" and we'll end in an infinite loop.
@ -162,6 +160,8 @@ module.exports = class CompilerImports extends Plugin {
if (error) return reject(error)
resolve(content)
})
}).catch(error => {
return reject(error)
})
}
})

@ -109,10 +109,11 @@ class ContextView {
if (filename !== this._deps.config.get('currentFile')) {
const provider = this._deps.fileManager.fileProviderOf(filename)
if (provider) {
provider.exists(filename, (error, exist) => {
if (error) return console.log(error)
provider.exists(filename).then(exist => {
this._deps.fileManager.open(filename)
jumpToLine(lineColumn)
}).catch(error => {
if (error) return console.log(error)
})
}
} else {

@ -121,7 +121,7 @@ class FileManager extends Plugin {
try {
path = this.limitPluginScope(path)
const provider = this.fileProviderOf(path)
const result = provider.exists(path, () => {})
const result = provider.exists(path)
return result
} catch (e) {

@ -63,11 +63,10 @@ class FileProvider {
})
}
exists (path, cb) {
async exists (path) {
// todo check the type (directory/file) as well #2386
// currently it is not possible to have a file and folder with same path
const ret = this._exists(path)
if (cb) cb(null, ret)
return ret
}

@ -74,16 +74,15 @@ module.exports = class RemixDProvider extends FileProvider {
})
}
exists (path, cb) {
if (!this._isReady) return cb && cb('provider not ready')
exists (path) {
if (!this._isReady) throw new Error('provider not ready')
const unprefixedpath = this.removePrefix(path)
return this._appManager.call('remixd', 'exists', { path: unprefixedpath })
.then((result) => {
if (cb) return cb(null, result)
return result
}).catch((error) => {
if (cb) return cb(error)
})
.catch((error) => {
throw new Error(error)
})
}

@ -229,7 +229,7 @@ module.exports = class Filepanel extends ViewPlugin {
/** these are called by the react component, action is already finished whent it's called */
async setWorkspace (workspace) {
this._deps.fileManager.removeTabsOf(this._deps.fileProviders.workspace)
this._deps.fileManager.closeAllFiles()
if (workspace.isLocalhost) {
this.call('manager', 'activatePlugin', 'remixd')
} else if (await this.call('manager', 'isActive', 'remixd')) {

@ -18,7 +18,9 @@ class TestTabLogic {
// Checking to ignore the value which contains only whitespaces
if (!path || !(/\S/.test(path))) return
const fileProvider = this.fileManager.fileProviderOf(path.split('/')[0])
fileProvider.exists(path, (e, res) => { if (!res) fileProvider.createDir(path) })
fileProvider.exists(path).then(res => {
if (!res) fileProvider.createDir(path)
})
}
pathExists (path) {

@ -39,10 +39,11 @@ Renderer.prototype._errorClick = function (errFile, errLine, errCol) {
// TODO: refactor with this._components.contextView.jumpTo
var provider = self._deps.fileManager.fileProviderOf(errFile)
if (provider) {
provider.exists(errFile, (error, exist) => {
if (error) return console.log(error)
provider.exists(errFile).then(exist => {
self._deps.fileManager.open(errFile)
editor.gotoLine(errLine, errCol)
}).catch(error => {
if (error) return console.log(error)
})
}
} else {

@ -36,14 +36,12 @@ module.exports = {
async.whilst(
() => { return exist },
(callback) => {
fileProvider.exists(name + counter + prefix + '.' + ext, (error, currentExist) => {
if (error) {
callback(error)
} else {
exist = currentExist
if (exist) counter = (counter | 0) + 1
callback()
}
fileProvider.exists(name + counter + prefix + '.' + ext).then(currentExist => {
exist = currentExist
if (exist) counter = (counter | 0) + 1
callback()
}).catch(error => {
if (error) console.log(error)
})
},
(error) => { cb(error, name + counter + prefix + '.' + ext) }

@ -368,8 +368,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
const name = `${parentFolder}/${file.name}`
filesProvider.exists(name, (error, exist) => {
if (error) console.log(error)
filesProvider.exists(name).then(exist => {
if (!exist) {
loadFile(name)
} else {
@ -383,6 +382,8 @@ export const FileExplorer = (props: FileExplorerProps) => {
fn: () => {}
})
}
}).catch(error => {
if (error) console.log(error)
})
})
}
@ -730,6 +731,7 @@ export const FileExplorer = (props: FileExplorerProps) => {
}
const renderFiles = (file: File, index: number) => {
if (!file || !file.path || typeof file === 'string' || typeof file === 'number' || typeof file === 'boolean') return
const labelClass = state.focusEdit.element === file.path
? 'bg-light' : state.focusElement.findIndex(item => item.key === file.path) !== -1
? 'bg-secondary' : state.mouseOverElement === file.path

@ -85,11 +85,10 @@ export class RemixdClient extends PluginClient {
}
}
set (args: SharedFolderArgs): Promise<void> {
set (args: SharedFolderArgs) {
try {
return new Promise((resolve, reject) => {
if (this.readOnly) return reject(new Error('Cannot write file: read-only mode selected'))
const isFolder = args.path.endsWith('/')
const path = utils.absolutePath(args.path, this.currentSharedFolder)
const exists = fs.existsSync(path)
@ -99,31 +98,25 @@ export class RemixdClient extends PluginClient {
return reject(new Error('trying to write "undefined" ! stopping.'))
}
this.trackDownStreamUpdate[path] = path
if (isFolder) {
fs.mkdirp(path).then(() => {
let splitPath = args.path.split('/')
splitPath = splitPath.filter(dir => dir)
const dir = '/' + splitPath.join('/')
this.emit('folderAdded', dir)
resolve()
}).catch((e: Error) => reject(e))
if (!exists && args.path.indexOf('/') !== -1) {
// the last element is the filename and we should remove it
this.createDir({ path: args.path.substr(0, args.path.lastIndexOf('/')) })
}
try {
fs.writeFile(path, args.content, 'utf8', (error: Error) => {
if (error) {
console.log(error)
return reject(error)
}
resolve(true)
})
} catch (e) {
return reject(e)
}
if (!exists) {
this.emit('fileAdded', args.path)
} else {
fs.ensureFile(path).then(() => {
fs.writeFile(path, args.content, 'utf8', (error: Error) => {
if (error) {
console.log(error)
return reject(error)
}
resolve()
})
}).catch((e: Error) => reject(e))
if (!exists) {
this.emit('fileAdded', args.path)
} else {
this.emit('fileChanged', args.path)
}
this.emit('fileChanged', args.path)
}
})
} catch (error) {
@ -131,24 +124,22 @@ export class RemixdClient extends PluginClient {
}
}
createDir (args: SharedFolderArgs): Promise<void> {
createDir (args: SharedFolderArgs) {
try {
return new Promise((resolve, reject) => {
if (this.readOnly) return reject(new Error('Cannot create folder: read-only mode selected'))
const path = utils.absolutePath(args.path, this.currentSharedFolder)
const exists = fs.existsSync(path)
if (exists && !isRealPath(path)) return reject(new Error(''))
this.trackDownStreamUpdate[path] = path
fs.mkdirp(path).then(() => {
let splitPath = args.path.split('/')
splitPath = splitPath.filter(dir => dir)
const dir = '/' + splitPath.join('/')
this.emit('folderAdded', dir)
resolve()
}).catch((e: Error) => reject(e))
const paths = args.path.split('/').filter(value => value)
if (paths.length && paths[0] === '') paths.shift()
let currentCheck = ''
paths.forEach((value) => {
currentCheck = currentCheck ? currentCheck + '/' + value : value
const path = utils.absolutePath(currentCheck, this.currentSharedFolder)
if (!fs.existsSync(path)) {
fs.mkdirp(path)
this.emit('folderAdded', currentCheck)
}
})
resolve(true)
})
} catch (error) {
throw new Error(error)

Loading…
Cancel
Save