/* Commands for handling configuration read and write */ import * as vscode from 'vscode'; import { regInMessage, regOutMessage } from '../util/reg_messages'; import { MessageHandler } from './messageHandler'; import { DevChatConfig } from '../util/config'; regInMessage({command: 'readConfig', key: ['A','B']}); // when key is "", it will get all config values regOutMessage({command: 'readConfig', key: ['A', 'B'], value: 'any'}); export async function readConfig(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise { if (message.key === '' || message.key === '*' || message.key.length === 0 || message.key[1] === '*') { const config = DevChatConfig.getInstance().getAll(); MessageHandler.sendMessage(panel, {command: 'readConfig', key: message.key, value: config}); } else { const config = DevChatConfig.getInstance().get(message.key); MessageHandler.sendMessage(panel, {command: 'readConfig', key: message.key, value: config}); } } regInMessage({command: 'writeConfig', key: ['A', 'B'], value: 'any'}); // when key is "", it will rewrite all config values export async function writeConfig(message: any, panel: vscode.WebviewPanel|vscode.WebviewView): Promise { if (message.key === '' || message.key === '*' || message.key.length === 0 || message.key[1] === '*') { DevChatConfig.getInstance().setAll(message.value); } else { DevChatConfig.getInstance().set(message.key, message.value); } }