when file change externally, always override with new content

pull/5370/head
yann300 2 years ago committed by Aniket
parent 1a827c4771
commit 7d4df6825d
  1. 20
      apps/remix-ide/src/app/editor/editor.js
  2. 2
      apps/remix-ide/src/app/files/fileManager.ts
  3. 2
      apps/vyper/src/app/app.tsx
  4. 5
      apps/vyper/src/app/utils/compiler.tsx
  5. 14
      libs/remix-ui/workspace/src/lib/actions/events.ts
  6. 2
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  7. 14
      libs/remixd/src/services/remixdClient.ts
  8. 2
      libs/remixd/src/types/index.ts

@ -13,7 +13,7 @@ const profile = {
name: 'editor', name: 'editor',
description: 'service - editor', description: 'service - editor',
version: packageJson.version, version: packageJson.version,
methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addLineText', 'discardLineTexts', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition', 'open', 'addModel','addErrorMarker', 'clearErrorMarkers'], methods: ['highlight', 'discardHighlight', 'clearAnnotations', 'addLineText', 'discardLineTexts', 'addAnnotation', 'gotoLine', 'revealRange', 'getCursorPosition', 'open', 'addModel','addErrorMarker', 'clearErrorMarkers', 'getText'],
} }
class Editor extends Plugin { class Editor extends Plugin {
@ -280,11 +280,23 @@ class Editor extends Plugin {
/** /**
* Set the text in the current session, if any. * Set the text in the current session, if any.
* @param {string} url Address of the text to replace.
* @param {string} text New text to be place. * @param {string} text New text to be place.
*/ */
setText (text) { setText (url, text) {
if (this.currentFile && this.sessions[this.currentFile]) { if (this.sessions[url]) {
this.sessions[this.currentFile].setValue(text) this.sessions[url].setValue(text)
}
}
/**
* Get the text in the current session, if any.
* @param {string} url Address of the text to replace.
* @param {string} text New text to be place.
*/
getText (url) {
if (this.sessions[url]) {
return this.sessions[url].getValue()
} }
} }

@ -795,7 +795,7 @@ class FileManager extends Plugin {
if (provider) { if (provider) {
try{ try{
const content = await provider.get(currentFile) const content = await provider.get(currentFile)
if(content) this.editor.setText(content) if(content) this.editor.setText(currentFile, content)
}catch(error){ }catch(error){
console.log(error) console.log(error)
} }

@ -72,7 +72,7 @@ const App: React.FC = () => {
<header> <header>
<div className="title"> <div className="title">
<img src={vyperLogo} alt="Vyper logo" /> <img src={vyperLogo} alt="Vyper logo" />
<h4>yper Compiler</h4> <h4>yper Compiler</h4><h5></h5>
</div> </div>
<a <a
rel="noopener noreferrer" rel="noopener noreferrer"

@ -43,10 +43,11 @@ export async function compile(url: string, contract: Contract): Promise<VyperCom
if (extension !== 'vy') { if (extension !== 'vy') {
throw new Error('Use extension .vy for Vyper.') throw new Error('Use extension .vy for Vyper.')
} }
const data = JSON.stringify({ code: contract.content })
const response = await fetch(url, { const response = await fetch(url, {
method: 'POST', method: 'POST',
headers: { 'Content-Type': 'application/json' }, headers: { 'Content-Type': 'application/json', 'Content-Length': data.length.toString() },
body: JSON.stringify({ code: contract.content }) body: data
}) })
if (response.status === 404) { if (response.status === 404) {

@ -108,20 +108,26 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp
dispatch(loadLocalhostRequest()) dispatch(loadLocalhostRequest())
}) })
provider.event.on('fileExternallyChanged', (path: string, content: string) => { provider.event.on('fileExternallyChanged', (path: string, content: string) => {
const config = plugin.registry.get('config').api const config = plugin.registry.get('config').api
const editor = plugin.registry.get('editor').api const editor = plugin.registry.get('editor').api
if (config.get('currentFile') === path && editor.currentContent() !== content) { if (editor.getText(path) === content) return
if (provider.isReadOnly(path)) return editor.setText(content) if (provider.isReadOnly(path)) return editor.setText(path, content)
if (config.get('currentFile') === path) {
// if it's the current file and the content is different:
dispatch(displayNotification( dispatch(displayNotification(
path + ' changed', path + ' changed',
'This file has been changed outside of Remix IDE.', 'This file has been changed outside of Remix IDE.',
'Replace by the new content', 'Keep the content displayed in Remix', 'Replace by the new content', 'Keep the content displayed in Remix',
() => { () => {
editor.setText(content) editor.setText(path, content)
} }
)) ))
} else {
// this isn't the current file, we can silently update the model
editor.setText(path, content)
} }
}) })

@ -374,7 +374,7 @@ export const uploadFile = async (target, targetFolder: string, cb?: (err: Error,
const editor = plugin.registry.get('editor').api const editor = plugin.registry.get('editor').api
if ((config.get('currentFile') === name) && (editor.currentContent() !== event.target.result)) { if ((config.get('currentFile') === name) && (editor.currentContent() !== event.target.result)) {
editor.setText(event.target.result) editor.setText(name, event.target.result)
} }
} }
fileReader.readAsText(file) fileReader.readAsText(file)

@ -1,5 +1,5 @@
import { PluginClient } from '@remixproject/plugin' import { PluginClient } from '@remixproject/plugin'
import { SharedFolderArgs, TrackDownStreamUpdate, Filelist, ResolveDirectory, FileContent } from '../types' // eslint-disable-line import { SharedFolderArgs, Filelist, ResolveDirectory, FileContent } from '../types' // eslint-disable-line
import * as WS from 'ws' // eslint-disable-line import * as WS from 'ws' // eslint-disable-line
import * as utils from '../utils' import * as utils from '../utils'
import * as chokidar from 'chokidar' import * as chokidar from 'chokidar'
@ -8,7 +8,6 @@ import * as isbinaryfile from 'isbinaryfile'
export class RemixdClient extends PluginClient { export class RemixdClient extends PluginClient {
methods: Array<string> methods: Array<string>
trackDownStreamUpdate: TrackDownStreamUpdate = {}
websocket: WS websocket: WS
currentSharedFolder: string currentSharedFolder: string
watcher: chokidar.FSWatcher watcher: chokidar.FSWatcher
@ -101,7 +100,6 @@ export class RemixdClient extends PluginClient {
console.log('trying to write "undefined" ! stopping.') console.log('trying to write "undefined" ! stopping.')
return reject(new Error('trying to write "undefined" ! stopping.')) return reject(new Error('trying to write "undefined" ! stopping.'))
} }
this.trackDownStreamUpdate[path] = path
if (!exists && args.path.indexOf('/') !== -1) { if (!exists && args.path.indexOf('/') !== -1) {
// the last element is the filename and we should remove it // the last element is the filename and we should remove it
this.createDir({ path: args.path.substr(0, args.path.lastIndexOf('/')) }) this.createDir({ path: args.path.substr(0, args.path.lastIndexOf('/')) })
@ -265,13 +263,11 @@ export class RemixdClient extends PluginClient {
}) })
*/ */
this.watcher.on('change', async (f: string) => { this.watcher.on('change', async (f: string) => {
if (this.trackDownStreamUpdate[f]) { const currentContent = await this.call('editor', 'getText' as any, f)
delete this.trackDownStreamUpdate[f] const newContent = fs.readFileSync(f)
return if (currentContent !== newContent && this.isLoaded) {
}
if (this.isLoaded) {
this.emit('changed', utils.relativePath(f, this.currentSharedFolder)) this.emit('changed', utils.relativePath(f, this.currentSharedFolder))
} }
}) })
this.watcher.on('unlink', async (f: string) => { this.watcher.on('unlink', async (f: string) => {
if (this.isLoaded) { if (this.isLoaded) {

@ -42,8 +42,6 @@ export type FileContent = {
readonly: boolean readonly: boolean
} }
export type TrackDownStreamUpdate = KeyPairString
export type SharedFolderArgs = FolderArgs & KeyPairString export type SharedFolderArgs = FolderArgs & KeyPairString
export type WS = typeof Websocket export type WS = typeof Websocket

Loading…
Cancel
Save