From 39713649769d9a5346448e73127d76beb718604c Mon Sep 17 00:00:00 2001 From: Graham Bates Date: Tue, 22 Nov 2022 14:03:12 +0000 Subject: [PATCH 1/2] Hover improvements - Increase width to handle 3 digit ranges - Add byte size - Add rules between sections --- src/assembly_language_provider.ts | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/assembly_language_provider.ts b/src/assembly_language_provider.ts index 67901cfe..597a58b2 100644 --- a/src/assembly_language_provider.ts +++ b/src/assembly_language_provider.ts @@ -290,14 +290,14 @@ export class SourceContext { const cycleText = min !== max ? `${min}-${max}`: min.toString(); this.cycles.set(lineNum, cycleText + "T"); - let detail = "```m68k\n" + instructionToString(inst.instruction) + "\n```\n"; + let detail = "```m68k\n" + instructionToString(inst.instruction) + "\n```\n---\n"; if (timings.labels.length) { detail += "| | Clock | Read | Write |\n"; detail += "|-|:-----:|:----:|:-----:|\n"; for (let i = 0; i < timings.labels.length; i++) { const label = timings.labels[i]; const [c, r, w] = timings.values[i]; - detail += `| ${label} | ${c} | ${r} | ${w} |\n`; + detail += `|**${label}**| ${c} | ${r} | ${w} |\n`; } } else { const [c, r, w] = timings.values[0]; @@ -305,6 +305,7 @@ export class SourceContext { detail += "|:-----:|:----:|:-----:|\n"; detail += `| ${c} | ${r} | ${w} |\n`; } + detail += `---\n${bytes.length} bytes`; this.hoverText.set(lineNum, detail); } } catch (err) {} @@ -333,7 +334,7 @@ export class SourceContext { before: { textDecoration: 'none; white-space: pre; padding: 0 10px 0 10px', margin: '0 10px 0 10px', - contentText: ' ' + contentText: ' ' } }); @@ -351,7 +352,7 @@ export class SourceContext { range, renderOptions: { before: { - contentText: cyclesStr.padStart(6, ' ') + contentText: cyclesStr.padStart(8, ' ') } } }); From f5de3c8f1e5c72f42caa46c2c0bff73c3a119bb9 Mon Sep 17 00:00:00 2001 From: Graham Bates Date: Tue, 22 Nov 2022 15:45:59 +0000 Subject: [PATCH 2/2] Absolute position decoration workaround Prevents misalignment / jumping while editing due to the delay adding decorations. The idea is that *every* line always has an 'empty' decoration to add horizontal space. We can add this immediately to new lines on edit. The actual cycle count decoration is added in addition to this and absolutely positioned on top, so doesn't affect layout. --- src/assembly_language_provider.ts | 22 ++++++++++++++++------ src/extension.ts | 1 + 2 files changed, 17 insertions(+), 6 deletions(-) diff --git a/src/assembly_language_provider.ts b/src/assembly_language_provider.ts index 597a58b2..d585b392 100644 --- a/src/assembly_language_provider.ts +++ b/src/assembly_language_provider.ts @@ -324,16 +324,16 @@ export class SourceContext { // theoretical 68000 cycle decorations private static decoration = vscode.window.createTextEditorDecorationType({ before: { - textDecoration: 'none; white-space: pre; border-radius: 6px; padding: 0 10px 0 10px', + textDecoration: 'none; white-space: pre; border-radius: 6px; padding: 0 10px 0 10px; position: absolute; line-height: 1rem;', backgroundColor: new vscode.ThemeColor("badge.background"), color: new vscode.ThemeColor("badge.foreground"), - margin: '0 10px 0 10px' + margin: '2px 10px 2px 0', } }); private static decorationEmpty = vscode.window.createTextEditorDecorationType({ before: { textDecoration: 'none; white-space: pre; padding: 0 10px 0 10px', - margin: '0 10px 0 10px', + margin: '0 10px 0 0', contentText: ' ' } }); @@ -343,7 +343,6 @@ export class SourceContext { return; const optionsArray: vscode.DecorationOptions[] = []; - const emptyRanges: vscode.Range[] = []; for(let line = 0; line < textEditor.document.lineCount; line++) { const cyclesStr = this.cycles.get(line + 1); const range = new vscode.Range(new vscode.Position(line, 0), new vscode.Position(line, 0)); @@ -356,11 +355,19 @@ export class SourceContext { } } }); - } else { - emptyRanges.push(range); } } textEditor.setDecorations(SourceContext.decoration, optionsArray); + } + + public setEmptyDecorations(textEditor: vscode.TextEditor) { + if(textEditor === null) + return; + const emptyRanges: vscode.Range[] = []; + for(let line = 0; line < textEditor.document.lineCount; line++) { + const range = new vscode.Range(new vscode.Position(line, 0), new vscode.Position(line, 0)); + emptyRanges.push(range); + } textEditor.setDecorations(SourceContext.decorationEmpty, emptyRanges); } @@ -396,6 +403,7 @@ export class AmigaAssemblyDocumentMananger { if (vscode.languages.match(selector, document)) { console.log("initial parse " + document.fileName); this.getSourceContext(document.fileName).setText(document.getText()); + this.getSourceContext(document.fileName).setEmptyDecorations(getEditorForDocument(document)); void this.getSourceContext(document.fileName).parse().then(() => { this.getSourceContext(document.fileName).setDecorations(getEditorForDocument(document)); }); @@ -406,6 +414,7 @@ export class AmigaAssemblyDocumentMananger { vscode.workspace.onDidOpenTextDocument((document: vscode.TextDocument) => { if (vscode.languages.match(selector, document)) { console.log("openTextDocument: initial parse " + document.fileName); + this.getSourceContext(document.fileName).setEmptyDecorations(getEditorForDocument(document)); this.getSourceContext(document.fileName).setText(document.getText()); void this.getSourceContext(document.fileName).parse().then(() => { this.getSourceContext(document.fileName).setDecorations(getEditorForDocument(document)); @@ -417,6 +426,7 @@ export class AmigaAssemblyDocumentMananger { vscode.workspace.onDidChangeTextDocument((event: vscode.TextDocumentChangeEvent) => { if (vscode.languages.match(selector, event.document)) { const fileName = event.document.fileName; + this.getSourceContext(event.document.fileName).setEmptyDecorations(getEditorForDocument(event.document)); this.getSourceContext(event.document.fileName).setText(event.document.getText()); if (changeTimers.has(fileName)) { clearTimeout(changeTimers.get(fileName)); diff --git a/src/extension.ts b/src/extension.ts index 5789fc02..4af5e9c0 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -236,6 +236,7 @@ class AmigaDebugExtension { private activeEditorChanged(editor: vscode.TextEditor) { if(vscode.languages.match(this.assemblyLanguageSelector, editor?.document)) { + this.assemblyDocumentManager.getSourceContext(editor.document.fileName).setEmptyDecorations(getEditorForDocument(editor.document)); this.assemblyDocumentManager.getSourceContext(editor.document.fileName).setDecorations(getEditorForDocument(editor.document)); return; }