diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 0000000..0a76a97 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,10 @@ +{ + "workbench.colorCustomizations": { + "statusBar.background": "#eba0ac", + "statusBar.foreground": "#181825", + "statusBarItem.hoverBackground": "#e27687", + "statusBarItem.remoteBackground": "#eba0ac", + "statusBarItem.remoteForeground": "#181825" + }, + "peacock.color": "#eba0ac" +} \ No newline at end of file diff --git a/examples/.vscode/settings.json b/examples/.vscode/settings.json new file mode 100644 index 0000000..caa2bb9 --- /dev/null +++ b/examples/.vscode/settings.json @@ -0,0 +1,28 @@ +{ + "workbench.colorCustomizations": { + "statusBar.background": "#f5c2e7", + "statusBar.foreground": "#181825", + "statusBarItem.hoverBackground": "#ee96d6", + "statusBarItem.remoteBackground": "#f5c2e7", + "statusBarItem.remoteForeground": "#181825" + }, + "peacock.color": "#f5c2e7", + "scratch-vhdl-vscode.templates": { + "led4_button4": { + "entity": { + "clk": ["in", "std_logic"], + "reset": ["in", "std_logic"], + "incr": ["in", "std_logic"], + "buttons": ["in", "std_logic_vector(3 downto 0)"], + "leds": ["out", "std_logic_vector(3 downto 0)"] + }, + "signals": {}, + "aliases": {}, + "name": "led4_button4", + "constants": { + "button_tab_c": ["natural", "1"] + }, + "libraries": { "ieee": {} } + } + } +} diff --git a/scratch-vhdl-vscode/src/webview/main.ts b/scratch-vhdl-vscode/src/webview/main.ts index 47b71cb..9bb86db 100644 --- a/scratch-vhdl-vscode/src/webview/main.ts +++ b/scratch-vhdl-vscode/src/webview/main.ts @@ -23,6 +23,7 @@ import { provideVSCodeDesignSystem().register(vsCodeButton()); async function updateEntity(data: { entity: Entity; filename: string }) { + const oldEntity = entity; entity = data.entity; filename = data.filename; @@ -129,6 +130,95 @@ async function updateEntity(data: { entity: Entity; filename: string }) { ...categories, ]; + if (oldEntity) { + const es = Object.keys(entity.entity); + const oes = Object.keys(oldEntity.entity); + for (const e in es) { + const v = ws.getVariable(es[e]); + if (!v) { + if (oes[e]) { + const ov = ws.getVariable(oes[e]); + if (ov) { + ws.renameVariableById(ov.getId(), es[e]); + } else { + ws.createVariable(es[e], null, null); + } + } else { + ws.createVariable(es[e], null, null); + } + } + } + const as = Object.keys(entity.aliases); + const oas = Object.keys(oldEntity.aliases); + for (const a in as) { + const v = ws.getVariable(as[a]); + if (!v) { + if (oas[a]) { + const ov = ws.getVariable(oas[a]); + if (ov) { + ws.renameVariableById(ov.getId(), as[a]); + } else { + ws.createVariable(as[a], null, null); + } + } else { + ws.createVariable(as[a], null, null); + } + } + } + const ss = Object.keys(entity.signals); + const oss = Object.keys(oldEntity.signals); + for (const s in ss) { + const v = ws.getVariable(ss[s]); + if (!v) { + if (oss[s]) { + const ov = ws.getVariable(oss[s]); + if (ov) { + ws.renameVariableById(ov.getId(), ss[s]); + } else { + ws.createVariable(ss[s], null, null); + } + } else { + ws.createVariable(ss[s], null, null); + } + } + } + } else { + const es = Object.keys(entity.entity); + for (const e in es) { + console.log(es[e]); + const v = ws.getVariable(es[e]); + console.log(v, !v); + if (!v) { + console.log(ws.createVariable(es[e], null, null)); + } + } + const as = Object.keys(entity.aliases); + for (const a in as) { + const v = ws.getVariable(as[a]); + if (!v) { + ws.createVariable(as[a], null, null); + } + } + const ss = Object.keys(entity.signals); + for (const s in ss) { + const v = ws.getVariable(ss[s]); + if (!v) { + ws.createVariable(ss[s], null, null); + } + } + } + for (const v of ws.getAllVariables()) { + if ( + !( + v.name in entity.entity || + v.name in entity.aliases || + v.name in entity.signals + ) + ) { + ws.deleteVariableById(v.getId()); + } + } + ws.updateToolbox(tb); ws.getAllBlocks(false).forEach((b) => @@ -368,7 +458,9 @@ export class FieldVar extends Blockly.FieldVariable { static dropdownCreate( this: Blockly.FieldVariable ): Blockly.MenuOption[] { - return super.dropdownCreate().slice(0, -2); + const o = super.dropdownCreate(); + if (o.length > 2) return o.slice(0, -2); + else return o; } protected render_(): void { @@ -423,3 +515,5 @@ ws.addChangeListener((e) => { }); main(); + +setTimeout(() => updateEntity({ entity, filename }), 1000); diff --git a/scratch_vhdl.code-workspace b/scratch_vhdl.code-workspace index f357d81..28b83a7 100644 --- a/scratch_vhdl.code-workspace +++ b/scratch_vhdl.code-workspace @@ -25,17 +25,28 @@ "buttons": ["in", "std_logic_vector(3 downto 0)"], "leds": ["out", "std_logic_vector(3 downto 0)"] }, + "signals": {}, + "aliases": {}, "name": "led4_button4", "constants": { "button_tab_c": ["natural", "1"] - } + }, + "libraries": { "ieee": {} } } }, "markdownlint.config": { "MD033": false, "MD024": false }, - "scratch-vhdl-vscode.asm_compile_path": "./design/asm_compile.cmd" + "scratch-vhdl-vscode.asm_compile_path": "./design/asm_compile.cmd", + "workbench.colorCustomizations": { + "statusBar.background": "#cba6f7", + "statusBar.foreground": "#181825", + "statusBarItem.hoverBackground": "#b077f3", + "statusBarItem.remoteBackground": "#cba6f7", + "statusBarItem.remoteForeground": "#181825" + }, + "peacock.color": "#cba6f7" }, "extensions": { "recommendations": [