How to get a complete syntax-tree from source-code

Hello and happy new year!

I’m trying to get a complete syntax tree from some user-generated Java-code which can be arbitrary long (the code from the last program is restored from localstorage).
I use an offscreen-cm-instance and do the following (where src is the source-code)

      changes: {from: 0, to: offscreenEditor.viewState.state.doc.length, insert: src}

If the source-code is too long I won’t get a complete syntax tree.

I stumbled upon ParseContext, which provides the method “forceParsing” that seems to do the trick but I don’t have any clue how to get access to it.

Maybe I’m totally doing this from the wrong direction: I simply need the (complete) syntax-tree from Java-source-code.


If you don’t need an editor, creating an off-screen one isn’t needed here. Just run javaLanguage.parser.parse(code).

Wow, that was very quick. Thank you very much!