mirror of
https://github.com/sehugg/8bitworkshop.git
synced 2026-11-22 04:28:05 +00:00
urust: show gutter for header windows
Header windows (the read-only view of toolchain and shared include files, and urust modules) show the code-offset gutter for lines the build compiled, the same as source files, and follow the *Show line numbers* setting. Headers that emit no code show an empty gutter.
This commit is contained in:
1 parent
c3c07c837e
commit
d4f401b989
5 files changed
+70
-8
No files matched your search
@@ -48,6 +48,8 @@ See [extension/CHANGELOG.md](extension/CHANGELOG.md).
|
||||
|
||||
### Editor and UI
|
||||
|
||||
- Header windows (the read-only view of toolchain and shared include files, and urust modules) show the code-offset gutter for lines the build compiled, the same as source files, and follow the *Show line numbers* setting. Headers that emit no code show an empty gutter.
|
||||
|
||||
- On large screens a small **filter button** next to the Project Selector opens a menu that narrows its examples to one category, or to **Local Files** or **Repositories** when the platform has them (**All** shows everything). While a filter is active the button turns amber and the top of the project list says **Filtering by ...**. The picker holds a fixed width there, so changing the filter or its options doesn't resize it. The choice is remembered per platform; on smaller screens the menu is hidden and the full list is shown.
|
||||
|
||||
- Clicking the link on an urust `use rs8::nes::util::…` line now opens the child module (`nes/util.rs`) instead of the parent `nes.rs`. A `use` of a child module resolves to its own file, while an item of the parent (`rs8::nes::PPUCTRL`, `rs8::math::sin`) still opens the module; the bundled sources now include the `rs8/<module>/` subdirectories, and a test keeps the child list in step with what the package ships.
|
||||
|
||||
+2
-1
@@ -19,7 +19,8 @@ The sidebar lists one entry per file in the project:
|
||||
Address**.
|
||||
- **Toolchain headers** — clicking the badge next to an `#include` line
|
||||
opens the referenced header from the toolchain's bundled include
|
||||
filesystem in a read-only viewer.
|
||||
filesystem in a read-only viewer. Lines that compile to code show
|
||||
their hex offsets in the gutter, as in source files.
|
||||
- **Binary files** — binary files open in a read-only hex dump.
|
||||
|
||||
## Gutter
|
||||
|
||||
@@ -105,6 +105,15 @@ function getEditorSelectionText(view: EditorView): string {
|
||||
return view.state.sliceDoc(range.from, range.to);
|
||||
}
|
||||
|
||||
/** Executable line offsets for the gutter, keyed by source line. */
|
||||
function sourceLineOffsetMap(sourcefile: SourceFile): Map<number, string> {
|
||||
const offsets = new Map<number, string>();
|
||||
for (var info of (sourcefile && sourcefile.lines) || []) {
|
||||
if (info.offset >= 0) offsets.set(info.line, hex(info.offset & 0xffff, 4));
|
||||
}
|
||||
return offsets;
|
||||
}
|
||||
|
||||
export class SourceEditor implements ProjectView {
|
||||
// Whether to highlight recently-executed lines from live trace data.
|
||||
// Off by default (probing has a runtime cost); toggled via toolbar button.
|
||||
@@ -574,15 +583,12 @@ export class SourceEditor implements ProjectView {
|
||||
this.clearErrors();
|
||||
var lstlines = this.sourcefile.lines || [];
|
||||
|
||||
const newOffsets = new Map();
|
||||
const newOffsets = sourceLineOffsetMap(this.sourcefile);
|
||||
const newBytes = new Map();
|
||||
const newClocks = new Map();
|
||||
|
||||
for (var info of lstlines) {
|
||||
//if (info.path && info.path != this.path) continue;
|
||||
if (info.offset >= 0) {
|
||||
newOffsets.set(info.line, hex(info.offset & 0xffff, 4));
|
||||
}
|
||||
if (info.insns) {
|
||||
var insnstr = info.insns.length > 9 ? ("...") : info.insns;
|
||||
newBytes.set(info.line, insnstr);
|
||||
@@ -1190,6 +1196,8 @@ export class HeaderView implements ProjectView {
|
||||
}
|
||||
currentPath: string;
|
||||
languageCompartment = new Compartment();
|
||||
sourcefile: SourceFile;
|
||||
dirtylisting = true;
|
||||
|
||||
constructor(public fn?: string) {
|
||||
}
|
||||
@@ -1208,15 +1216,32 @@ export class HeaderView implements ProjectView {
|
||||
EditorState.allowMultipleSelections.of(true),
|
||||
drawSelection(),
|
||||
highlightActiveLine(),
|
||||
highlightActiveLineGutter(),
|
||||
highlightSelectionMatches(),
|
||||
// line numbers follow the user setting, like SourceEditor; the
|
||||
// offset gutter below is the default view of code in headers
|
||||
...settingsExtensions(loadSettings()),
|
||||
foldGutter(),
|
||||
search({ top: true }),
|
||||
keymap.of(ideSearchKeymap),
|
||||
this.languageCompartment.of(lang),
|
||||
mbo,
|
||||
editorTheme,
|
||||
// offsets for the lines that the build actually compiled
|
||||
offset.field,
|
||||
offset.gutter,
|
||||
EditorState.readOnly.of(true),
|
||||
EditorView.updateListener.of(update => {
|
||||
for (let effect of update.transactions.flatMap(tr => tr.effects)) {
|
||||
if (effect.is(currentPcMarker.runToLine)) {
|
||||
const pc = this.sourcefile && this.sourcefile.line2offset.get(effect.value);
|
||||
if (pc >= 0) runToPC([pc]);
|
||||
}
|
||||
}
|
||||
}),
|
||||
],
|
||||
});
|
||||
registerEditor(this.view);
|
||||
this.refresh(false);
|
||||
return div;
|
||||
}
|
||||
@@ -1232,6 +1257,25 @@ export class HeaderView implements ProjectView {
|
||||
effects: this.languageCompartment.reconfigure(lang),
|
||||
changes: { from: 0, to: this.view.state.doc.length, insert: text }
|
||||
});
|
||||
// replacing the whole document drops the gutter markers, so they have to
|
||||
// be applied again even if the listing itself is unchanged
|
||||
this.dirtylisting = true;
|
||||
this.refreshListing();
|
||||
}
|
||||
|
||||
// show the listing's code offsets for this header, when the build produced
|
||||
// any (a declarations-only header has none)
|
||||
refreshListing() {
|
||||
if (!this.view || !this.currentPath) return;
|
||||
var lst = current_project.getListingForFile(this.currentPath);
|
||||
var sourcefile = (lst && lst.sourcefile) || null;
|
||||
if (sourcefile !== this.sourcefile) {
|
||||
this.sourcefile = sourcefile;
|
||||
this.dirtylisting = true;
|
||||
}
|
||||
if (!this.dirtylisting) return;
|
||||
this.view.dispatch({ effects: offset.set.of(sourceLineOffsetMap(sourcefile)) });
|
||||
this.dirtylisting = false;
|
||||
}
|
||||
|
||||
refresh(moveCursor: boolean) {
|
||||
@@ -1243,6 +1287,7 @@ export class HeaderView implements ProjectView {
|
||||
fn = this.fn = decodeURIComponent(hash.substring('#headerview/'.length));
|
||||
}
|
||||
this.loadIncludeFile(fn);
|
||||
this.refreshListing();
|
||||
}
|
||||
|
||||
async loadIncludeFile(fn: string) {
|
||||
|
||||
@@ -1,9 +1,8 @@
|
||||
import { RangeSet, StateEffect, StateField } from "@codemirror/state";
|
||||
import { gutter, GutterMarker } from "@codemirror/view";
|
||||
import { hex } from "../../common/util";
|
||||
import { canUseBreakpoints } from "../breakpoints";
|
||||
|
||||
const setOffset = StateEffect.define<Map<number, number>>();
|
||||
const setOffset = StateEffect.define<Map<number, string>>();
|
||||
const setBytes = StateEffect.define<Map<number, string>>();
|
||||
const setClock = StateEffect.define<Map<number, string>>();
|
||||
// clicking the gutter only *requests* a toggle; the breakpoint store
|
||||
@@ -34,7 +33,7 @@ const offsetField = StateField.define<RangeSet<GutterMarker>>({
|
||||
for (let [line, val] of map.entries()) {
|
||||
if (line >= 1 && line <= tr.state.doc.lines) {
|
||||
const pos = tr.state.doc.line(line).from;
|
||||
ranges.push(new OffsetMarker(hex(val, 4)).range(pos));
|
||||
ranges.push(new OffsetMarker(val).range(pos));
|
||||
}
|
||||
}
|
||||
value = RangeSet.of(ranges, true);
|
||||
|
||||
@@ -52,4 +52,19 @@ describe('CodeProject.getListingForFile', function () {
|
||||
assert.strictEqual(lst.sourcefile.line2offset.get(5), 0x200);
|
||||
});
|
||||
|
||||
// the read-only header view asks for the listing of a library module
|
||||
// (urust keys its listings by the module's path)
|
||||
it('finds the listing for a library module opened in the header view', function () {
|
||||
const proj = makeProject('main.rs');
|
||||
proj.processBuildListings({ listings: {
|
||||
'main.rs': { lines: [{ line: 3, path: 'main.rs', offset: 0xc000, iscode: true }] },
|
||||
'rs8/nes/util.rs': { lines: [{ line: 70, path: 'rs8/nes/util.rs', offset: 0xc100, iscode: true }] },
|
||||
} } as any);
|
||||
const lst = proj.getListingForFile('rs8/nes/util.rs');
|
||||
assert.strictEqual(lst.sourcefile.line2offset.get(70), 0xc100);
|
||||
assert.strictEqual(proj.getListingForFile('rs8/nes/nothing.rs'), undefined);
|
||||
// the header view names it relative to the shared filesystem's /rs8
|
||||
assert.strictEqual(proj.getListingForFile('nes/util.rs')?.sourcefile.line2offset.get(70), 0xc100);
|
||||
});
|
||||
|
||||
});
|
||||
Reference in new issue
Block a user