# Show syntax error from Lezer parse

**URL:** https://discuss.codemirror.net/t/show-syntax-error-from-lezer-parse/5346
**Category:** v6
**Created:** [November 24, 2022, 1:00pm UTC](https://discuss.codemirror.net/t/show-syntax-error-from-lezer-parse/5346 "2022-11-24T13:00:03Z")
**Posts on this page:** 1
**Showing post:** 3

<div class="post-metadata">

### Author: ![tslocke](https://discuss.codemirror.net/user_avatar/discuss.codemirror.net/tslocke/32/2736_2.png) [@tslocke](https://discuss.codemirror.net/u/tslocke)
#### Post date: [November 24, 2022, 2:45pm UTC](https://discuss.codemirror.net/t/show-syntax-error-from-lezer-parse/5346/3 "2022-11-24T14:45:20Z")

</div>

Amazingly helpful answer in four lines!

In case this is useful to others, here is a working extension:

```auto
import {syntaxTree} from "@codemirror/language"
import {linter} from '@codemirror/lint'

function simpleLezerLinter() {
  return linter(view => {
    const {state} = view
    const tree = syntaxTree(state)
    if (tree.length === state.doc.length) {
      let pos = null
      tree.iterate({enter: n => {
        if (pos == null && n.type.isError) {
          pos = n.from
          return false
        }
      }})

      if (pos != null)
        return [{from: pos, to: pos+1, severity: 'error', message: 'syntax error'}]
    } 

    return []
  })
}

```

---

_[View the full topic](https://discuss.codemirror.net/t/show-syntax-error-from-lezer-parse/5346)._
