Merge pull request #3413 from ethereum/fix-sync

Fix Remixd Sync
pull/5370/head
Aniket 2 years ago committed by GitHub
commit b3b372d81f
  1. 8
      libs/remixd/src/services/remixdClient.ts

@ -5,12 +5,14 @@ import * as utils from '../utils'
import * as chokidar from 'chokidar' import * as chokidar from 'chokidar'
import * as fs from 'fs-extra' import * as fs from 'fs-extra'
import * as isbinaryfile from 'isbinaryfile' import * as isbinaryfile from 'isbinaryfile'
import * as pathModule from 'path'
export class RemixdClient extends PluginClient { export class RemixdClient extends PluginClient {
methods: Array<string> methods: Array<string>
websocket: WS websocket: WS
currentSharedFolder: string currentSharedFolder: string
watcher: chokidar.FSWatcher watcher: chokidar.FSWatcher
trackDownStreamUpdate: Record<string, string> = {}
constructor (private readOnly = false) { constructor (private readOnly = false) {
super() super()
@ -105,6 +107,7 @@ export class RemixdClient extends PluginClient {
this.createDir({ path: args.path.substr(0, args.path.lastIndexOf('/')) }) this.createDir({ path: args.path.substr(0, args.path.lastIndexOf('/')) })
} }
try { try {
this.trackDownStreamUpdate[path] = args.content
fs.writeFile(path, args.content, 'utf8', (error: Error) => { fs.writeFile(path, args.content, 'utf8', (error: Error) => {
if (error) { if (error) {
console.log(error) console.log(error)
@ -263,8 +266,9 @@ export class RemixdClient extends PluginClient {
}) })
*/ */
this.watcher.on('change', async (f: string) => { this.watcher.on('change', async (f: string) => {
const currentContent = await this.call('editor', 'getText' as any, f) const path = pathModule.resolve(f)
const newContent = fs.readFileSync(f) const currentContent = this.trackDownStreamUpdate[path]
const newContent = fs.readFileSync(f, 'utf-8')
if (currentContent !== newContent && this.isLoaded) { if (currentContent !== newContent && this.isLoaded) {
this.emit('changed', utils.relativePath(f, this.currentSharedFolder)) this.emit('changed', utils.relativePath(f, this.currentSharedFolder))
} }

Loading…
Cancel
Save