react to config changes

pull/5370/head
filip mertens 2 years ago
parent abca41ecbb
commit 2e3e641ea6
  1. 3
      apps/remix-ide/src/app/plugins/config.ts
  2. 21
      apps/remix-ide/src/app/plugins/parser/code-parser.tsx
  3. 3
      apps/remix-ide/src/app/tabs/settings-tab.tsx
  4. 7
      apps/remix-ide/src/config.js

@ -6,7 +6,8 @@ const profile = {
name: 'config',
displayName: 'Config',
description: 'Config',
methods: ['getAppParameter', 'setAppParameter']
methods: ['getAppParameter', 'setAppParameter'],
events: ['configChanged']
}
export class ConfigPlugin extends Plugin {

@ -77,7 +77,7 @@ export class CodeParser extends Plugin {
getANTLRBlockAtPosition: (position: any, text?: string) => Promise<any>
setCurrentFileAST: (text?: string) => Promise<ParseResult>
getImports: () => Promise<CodeParserImportsData[]>
constructor(astWalker: any) {
super(profile)
@ -133,7 +133,7 @@ export class CodeParser extends Plugin {
this.on('fileManager', 'fileRemoved', async () => {
await this.importService.setFileTree()
})
this.on('fileManager', 'currentFileChanged', async () => {
await this.call('editor', 'discardLineTexts')
const completionSettings = await this.call('config', 'getAppParameter', 'auto-completion')
@ -147,8 +147,25 @@ export class CodeParser extends Plugin {
this.compilerService.compiler.loadVersion(true, `${url}?t=${Date.now()}`)
})
this.on('config', 'configChanged', async (config) => {
await this.reload()
})
this.on('settings', 'configChanged', async (config) => {
await this.reload()
})
await this.compilerService.init()
this.on('solidity', 'compilerLoaded', async () => {
await this.reload()
})
}
async reload(){
await this.call('editor', 'discardLineTexts')
await this.call('fileDecorator', 'clearFileDecorators')
await this.call('editor', 'clearErrorMarkers', [this.currentFile])
await this.handleChangeEvents()
}
/**

@ -32,6 +32,9 @@ module.exports = class SettingsTab extends ViewPlugin {
constructor (config, editor) {
super(profile)
this.config = config
this.config.events.on('configChanged', (changedConfig) => {
this.emit('configChanged', changedConfig)
})
this.editor = editor
this._deps = {
themeModule: Registry.getInstance().get('themeModule').api

@ -3,7 +3,7 @@
var CONFIG_FILE = '.remix.config'
const EventEmitter = require('events')
function Config (storage) {
function Config(storage) {
this.items = {}
this.unpersistedItems = {}
this.events = new EventEmitter()
@ -15,7 +15,7 @@ function Config (storage) {
this.items = JSON.parse(config)
}
} catch (exception) {
/* Do nothing. */
/* Do nothing. */
}
this.exists = function (key) {
@ -30,9 +30,10 @@ function Config (storage) {
this.items[key] = content
try {
storage.set(CONFIG_FILE, JSON.stringify(this.items))
this.events.emit('configChanged', { key, content })
this.events.emit(key + '_changed', content)
} catch (exception) {
/* Do nothing. */
/* Do nothing. */
}
}

Loading…
Cancel
Save