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

**URL:** https://discuss.codemirror.net/t/how-to-get-a-complete-syntax-tree-from-source-code/5508
**Category:** v6
**Created:** [January 2, 2023, 9:18pm UTC](https://discuss.codemirror.net/t/how-to-get-a-complete-syntax-tree-from-source-code/5508 "2023-01-02T21:18:38Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![thomasklein1982](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/thomasklein1982/32/1430_2.png) [@thomasklein1982](https://discuss.codemirror.net/u/thomasklein1982)
#### Post date: [January 2, 2023, 9:18pm UTC](https://discuss.codemirror.net/t/how-to-get-a-complete-syntax-tree-from-source-code/5508/1 "2023-01-02T21:18:39Z")

</div>

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)

```auto
offscreenEditor.dispatch({
      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.

Thanks!

---

<div class="post-metadata">

### Author: ![marijn](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/marijn/32/136_2.png) [@marijn](https://discuss.codemirror.net/u/marijn)
#### Post date: [January 2, 2023, 9:46pm UTC](https://discuss.codemirror.net/t/how-to-get-a-complete-syntax-tree-from-source-code/5508/2 "2023-01-02T21:46:53Z")

</div>

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

---

<div class="post-metadata">

### Author: ![thomasklein1982](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/thomasklein1982/32/1430_2.png) [@thomasklein1982](https://discuss.codemirror.net/u/thomasklein1982)
#### Post date: [January 3, 2023, 12:16am UTC](https://discuss.codemirror.net/t/how-to-get-a-complete-syntax-tree-from-source-code/5508/3 "2023-01-03T00:16:27Z")

</div>

> [@marijn](#):
>
> javaLanguage.parser.parse(code)

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