Skip to content

Commit

Permalink
Add a usage section to readme
Browse files Browse the repository at this point in the history
  • Loading branch information
marijnh committed Dec 30, 2024
1 parent be72c42 commit 032c8e3
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,3 +16,28 @@ We aim to be an inclusive, welcoming community. To make that explicit,
we have a [code of
conduct](http://contributor-covenant.org/version/1/1/0/) that applies
to communication around the project.

## Usage

```javascript
import {EditorView} from "@codemirror/view"
import {autocompletion} from "@codemirror/autocomplete"
import {jsonLanguage} from "@codemirror/lang-json"

const view = new EditorView({
parent: document.body,
extensions: [
jsonLanguage,
autocompletion(),
jsonLanguage.data.of({
autocomplete: ["id", "name", "address"]
})
]
})
```

This configuration will just complete the given words anywhere in JSON
context. Most language modules come with more refined autocompletion
built-in, but you can also write your own custom autocompletion
[sources](https://codemirror.net/docs/ref/#autocomplete.CompletionSource)
and associate them with your language this way.

0 comments on commit 032c8e3

Please sign in to comment.