when file change externally, always override with new content

pull/3348/head
yann300 2 years ago committed by Aniket
parent e883118afd
commit 0fdba00eb0
  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. 12
      libs/remix-ui/workspace/src/lib/actions/events.ts
  6. 2
      libs/remix-ui/workspace/src/lib/actions/workspace.ts
  7. 12
      libs/remixd/src/services/remixdClient.ts
  8. 2
      libs/remixd/src/types/index.ts

@ -13,7 +13,7 @@ const profile = {
name: 'editor',
description: 'service - editor',
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 {
@ -280,11 +280,23 @@ class Editor extends Plugin {
/**
* 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.
*/
setText (text) {
if (this.currentFile && this.sessions[this.currentFile]) {
this.sessions[this.currentFile].setValue(text)
setText (url, text) {
if (this.sessions[url]) {
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) {
try{
const content = await provider.get(currentFile)
if(content) this.editor.setText(content)
if(content) this.editor.setText(currentFile, content)
}catch(error){
console.log(error)
}

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

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

@ -112,16 +112,22 @@ export const listenOnProviderEvents = (provider) => (reducerDispatch: React.Disp
const config = plugin.registry.get('config').api
const editor = plugin.registry.get('editor').api
if (config.get('currentFile') === path && editor.currentContent() !== content) {
if (provider.isReadOnly(path)) return editor.setText(content)
if (editor.getText(path) === content) return
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(
path + ' changed',
'This file has been changed outside of Remix IDE.',
'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
if ((config.get('currentFile') === name) && (editor.currentContent() !== event.target.result)) {
editor.setText(event.target.result)
editor.setText(name, event.target.result)
}
}
fileReader.readAsText(file)

@ -1,5 +1,5 @@
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 utils from '../utils'
import * as chokidar from 'chokidar'
@ -8,7 +8,6 @@ import * as isbinaryfile from 'isbinaryfile'
export class RemixdClient extends PluginClient {
methods: Array<string>
trackDownStreamUpdate: TrackDownStreamUpdate = {}
websocket: WS
currentSharedFolder: string
watcher: chokidar.FSWatcher
@ -101,7 +100,6 @@ export class RemixdClient extends PluginClient {
console.log('trying to write "undefined" ! stopping.')
return reject(new Error('trying to write "undefined" ! stopping.'))
}
this.trackDownStreamUpdate[path] = path
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('/')) })
@ -265,11 +263,9 @@ export class RemixdClient extends PluginClient {
})
*/
this.watcher.on('change', async (f: string) => {
if (this.trackDownStreamUpdate[f]) {
delete this.trackDownStreamUpdate[f]
return
}
if (this.isLoaded) {
const currentContent = await this.call('editor', 'getText' as any, f)
const newContent = fs.readFileSync(f)
if (currentContent !== newContent && this.isLoaded) {
this.emit('changed', utils.relativePath(f, this.currentSharedFolder))
}
})

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

Loading…
Cancel
Save