Skip to content

POC source map integration#5232

Open
Acepie wants to merge 11 commits intogleam-lang:mainfrom
Acepie:sourceMapsRevive
Open

POC source map integration#5232
Acepie wants to merge 11 commits intogleam-lang:mainfrom
Acepie:sourceMapsRevive

Conversation

@Acepie
Copy link
Contributor

@Acepie Acepie commented Dec 29, 2025

An initial implementation of #2249 based off the implementation that was started #3675 I tried to incorporate the feedback that was left on that pr as best as I could. To separate the sourcemapping logic out of the document printing directly i added a new observer node pattern so that we can call any function/method with the output file position while processing a document. This should theoretically be reusable if we had a need in the future though I'm not entirely sure if there would be one honestly. The bulk of the actual logic is inside the main javascript package where we instrument cursor observer points. essentially whenever we would want to denote a value to map (i.e. an expression, case, etc.) we add a new observer document. I tried writing out the raw mappings to make it a bit easier to line things up but the visualizer https://sokra.github.io/source-map-visualization/# is definitely the easiest way to check this for non trivial programs. I wrote out enough test cases to cover the unique bits but i think we might wanna add more as people try this out/find things that need more robust instrumentation. I think this is in a usable/nice enough state that people could find value in this. I was able to get debuggers working for running tests/a served local web page and it was pretty nice.

Screenshot 2025-12-28 at 5 19 16 PM Screenshot 2025-12-28 at 8 32 32 PM

}

#[macro_export]
macro_rules! assert_source_map {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this gets us the raw mappings in a state that is ok enough to line up but honestly its pretty hard to get a good visual without a third party html viewer. if people have ideas on how to improve the rendering lmk

module_name: EcoString,
src_path: EcoString,
line_numbers: &'module LineNumbers,
pub line_numbers: &'module LineNumbers,
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these are pub so that decision can reuse them. this feels slightly off to me but ultimately fine

@@ -0,0 +1,93 @@
use crate::assert_source_map;

#[test]
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these were all the cases that were unique enough to handle from what i ran into but we might wanna add more over time as people run into things/the markers get added/expanded

@Acepie
Copy link
Contributor Author

Acepie commented Jan 10, 2026

hey @lpil bumping this in case it got lost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant