Skip to content

Commit 1a62653

Browse files
committed
Update README.md
1 parent 39d3503 commit 1a62653

1 file changed

Lines changed: 42 additions & 0 deletions

File tree

README.md

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ https://user-images.githubusercontent.com/348107/120141150-c6bb9180-c1fd-11eb-8a
1414
- 📚 Hover Documentation
1515
- 🩺 Diagnostics
1616
- 🔍 Go to Definition, Declaration, and Type Definition
17+
- 🔦 Document Highlight
18+
- 🎨 Document Formatting and Range Formatting
1719

1820
## Usage
1921

@@ -67,6 +69,46 @@ var ls = languageServerWithTransport({
6769

6870
The `Transport` interface requires `send`, `onMessage`, `onClose`, `onError`, and `close` methods. You can import `Transport` and `WebSocketTransport` from the package.
6971

72+
### Document Highlight
73+
74+
Document highlights are enabled by default. When the cursor is on a symbol, all occurrences are highlighted. Style them with CSS:
75+
76+
```css
77+
.cm-lsp-highlight-text,
78+
.cm-lsp-highlight-read { background-color: rgba(255, 255, 0, 0.2); }
79+
.cm-lsp-highlight-write { background-color: rgba(255, 165, 0, 0.3); }
80+
```
81+
82+
### Formatting
83+
84+
`formatDocument` and `formatSelection` are CodeMirror commands that you can bind to keys:
85+
86+
```js
87+
import { keymap } from '@codemirror/view';
88+
import { formatDocument, formatSelection } from 'codemirror-languageserver';
89+
90+
keymap.of([
91+
{ key: 'Shift-Alt-f', run: formatDocument },
92+
{ key: 'Ctrl-k Ctrl-f', run: formatSelection },
93+
])
94+
```
95+
96+
To configure formatting options (tab size, spaces vs tabs, etc.), use the `formattingOptions` facet:
97+
98+
```js
99+
import { formattingOptions } from 'codemirror-languageserver';
100+
101+
// In extensions:
102+
formattingOptions.of({
103+
tabSize: 2,
104+
insertSpaces: true,
105+
trimTrailingWhitespace: true,
106+
insertFinalNewline: true,
107+
})
108+
```
109+
110+
By default, `tabSize` is read from the editor state.
111+
70112
### Using with Initialization Options
71113

72114
The plugin includes built-in TypeScript definitions for popular language servers:

0 commit comments

Comments
 (0)