Skip to content

Commit 6b68b10

Browse files
authored
docs: clarify LSP and formatter opt-in config (#25502)
1 parent 85bb900 commit 6b68b10

5 files changed

Lines changed: 92 additions & 22 deletions

File tree

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ It's very similar to Claude Code in terms of capability. Here are the key differ
132132

133133
- 100% open source
134134
- Not coupled to any provider. Although we recommend the models we provide through [OpenCode Zen](https://opencode.ai/zen), OpenCode can be used with Claude, OpenAI, Google, or even local models. As models evolve, the gaps between them will close and pricing will drop, so being provider-agnostic is important.
135-
- Out-of-the-box LSP support
135+
- Built-in opt-in LSP support
136136
- A focus on TUI. OpenCode is built by neovim users and the creators of [terminal.shop](https://terminal.shop); we are going to push the limits of what's possible in the terminal.
137137
- A client/server architecture. This, for example, can allow OpenCode to run on your computer while you drive it remotely from a mobile app, meaning that the TUI frontend is just one of the possible clients.
138138

packages/opencode/src/config/config.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,8 +192,14 @@ export const Info = Schema.Struct({
192192
]),
193193
),
194194
).annotate({ description: "MCP (Model Context Protocol) server configurations" }),
195-
formatter: Schema.optional(ConfigFormatter.Info),
196-
lsp: Schema.optional(ConfigLSP.Info),
195+
formatter: Schema.optional(ConfigFormatter.Info).annotate({
196+
description:
197+
"Enable or configure formatters. Omit or set to false to disable, true to enable built-ins, or an object to enable built-ins with overrides.",
198+
}),
199+
lsp: Schema.optional(ConfigLSP.Info).annotate({
200+
description:
201+
"Enable or configure LSP servers. Omit or set to false to disable, true to enable built-ins, or an object to enable built-ins with overrides.",
202+
}),
197203
instructions: Schema.optional(Schema.mutable(Schema.Array(Schema.String))).annotate({
198204
description: "Additional instruction files or patterns to include",
199205
}),

packages/web/src/content/docs/config.mdx

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -575,7 +575,16 @@ Notice that this only works if it was not installed using a package manager such
575575

576576
### Formatters
577577

578-
You can configure code formatters through the `formatter` option.
578+
You can enable and configure code formatters through the `formatter` option. Omit it to keep formatters disabled.
579+
580+
```json title="opencode.json"
581+
{
582+
"$schema": "https://opencode.ai/config.json",
583+
"formatter": true
584+
}
585+
```
586+
587+
Use an object to keep built-ins enabled while configuring overrides or custom formatters.
579588

580589
```json title="opencode.json"
581590
{
@@ -599,6 +608,34 @@ You can configure code formatters through the `formatter` option.
599608

600609
---
601610

611+
### LSP Servers
612+
613+
You can enable and configure LSP servers through the `lsp` option. Omit it to keep LSP disabled.
614+
615+
```json title="opencode.json"
616+
{
617+
"$schema": "https://opencode.ai/config.json",
618+
"lsp": true
619+
}
620+
```
621+
622+
Use an object to keep built-ins enabled while configuring overrides or custom LSP servers.
623+
624+
```json title="opencode.json"
625+
{
626+
"$schema": "https://opencode.ai/config.json",
627+
"lsp": {
628+
"typescript": {
629+
"disabled": true
630+
}
631+
}
632+
}
633+
```
634+
635+
[Learn more about LSP servers here](/docs/lsp).
636+
637+
---
638+
602639
### Permissions
603640

604641
By default, opencode **allows all operations** without requiring explicit approval. You can change this using the `permission` option.

packages/web/src/content/docs/formatters.mdx

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: Formatters
33
description: OpenCode uses language specific formatters.
44
---
55

6-
OpenCode automatically formats files after they are written or edited using language-specific formatters. This ensures that the code that is generated follows the code styles of your project.
6+
OpenCode can format files after they are written or edited using language-specific formatters. Formatters are disabled by default; enable them in your config before OpenCode will run them.
77

88
---
99

@@ -40,25 +40,36 @@ OpenCode comes with several built-in formatters for popular languages and framew
4040
| uv | .py, .pyi | `uv` command available |
4141
| zig | .zig, .zon | `zig` command available |
4242

43-
So if your project has `prettier` in your `package.json`, OpenCode will automatically use it.
43+
When formatters are enabled, OpenCode will use `prettier` for matching files if your project has `prettier` in `package.json`.
4444

4545
---
4646

4747
## How it works
4848

49-
When OpenCode writes or edits a file, it:
49+
When OpenCode writes or edits a file and formatters are enabled, it:
5050

5151
1. Checks the file extension against all enabled formatters.
5252
2. Runs the appropriate formatter command on the file.
53-
3. Applies the formatting changes automatically.
53+
3. Applies the formatting changes.
5454

55-
This process happens in the background, ensuring your code styles are maintained without any manual steps.
55+
This process happens in the background for enabled formatters.
5656

5757
---
5858

5959
## Configure
6060

61-
You can customize formatters through the `formatter` section in your OpenCode config.
61+
You can enable and customize formatters through the `formatter` section in your OpenCode config.
62+
63+
To enable all built-in formatters, set `formatter` to `true`.
64+
65+
```json title="opencode.json"
66+
{
67+
"$schema": "https://opencode.ai/config.json",
68+
"formatter": true
69+
}
70+
```
71+
72+
Use an object to keep built-ins enabled while configuring overrides or custom formatters.
6273

6374
```json title="opencode.json"
6475
{
@@ -72,7 +83,7 @@ Each formatter configuration supports the following:
7283
| Property | Type | Description |
7384
| ------------- | -------- | ------------------------------------------------------- |
7485
| `disabled` | boolean | Set this to `true` to disable the formatter |
75-
| `command` | string[] | The command to run for formatting |
86+
| `command` | string[] | The command to run for formatting. Required for custom formatters; optional for built-ins. |
7687
| `environment` | object | Environment variables to set when running the formatter |
7788
| `extensions` | string[] | File extensions this formatter should handle |
7889

@@ -82,7 +93,7 @@ Let's look at some examples.
8293

8394
### Disabling formatters
8495

85-
To disable **all** formatters globally, set `formatter` to `false`:
96+
If `formatter` is omitted, all formatters are disabled. To disable all formatters after another config enabled them, set `formatter` to `false`:
8697

8798
```json title="opencode.json" {3}
8899
{
@@ -108,7 +119,7 @@ To disable a **specific** formatter, set `disabled` to `true`:
108119

109120
### Custom formatters
110121

111-
You can override the built-in formatters or add new ones by specifying the command, environment variables, and file extensions:
122+
You can configure built-in formatters with options like `environment` or `extensions`. To add a custom formatter, specify a `command` and `extensions`:
112123

113124
```json title="opencode.json" {4-14}
114125
{

packages/web/src/content/docs/lsp.mdx

Lines changed: 25 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ title: LSP Servers
33
description: OpenCode integrates with your LSP servers.
44
---
55

6-
OpenCode integrates with your Language Server Protocol (LSP) to help the LLM interact with your codebase. It uses diagnostics to provide feedback to the LLM.
6+
OpenCode can integrate with your Language Server Protocol (LSP) to help the LLM interact with your codebase. It uses diagnostics to provide feedback to the LLM.
77

88
---
99

@@ -48,7 +48,7 @@ OpenCode comes with several built-in LSP servers for popular languages:
4848
| yaml-ls | .yaml, .yml | Auto-installs Red Hat yaml-language-server |
4949
| zls | .zig, .zon | `zig` command available |
5050

51-
LSP servers are automatically enabled when one of the above file extensions are detected and the requirements are met.
51+
When LSP is enabled, servers start when one of the above file extensions is detected and the requirements are met.
5252

5353
:::note
5454
You can disable automatic LSP server downloads by setting the `OPENCODE_DISABLE_LSP_DOWNLOAD` environment variable to `true`.
@@ -58,7 +58,7 @@ You can disable automatic LSP server downloads by setting the `OPENCODE_DISABLE_
5858

5959
## How It Works
6060

61-
When opencode opens a file, it:
61+
When LSP is enabled and opencode opens a file, it:
6262

6363
1. Checks the file extension against all enabled LSP servers.
6464
2. Starts the appropriate LSP server if not already running.
@@ -67,7 +67,18 @@ When opencode opens a file, it:
6767

6868
## Configure
6969

70-
You can customize LSP servers through the `lsp` section in your opencode config.
70+
You can enable and customize LSP servers through the `lsp` section in your opencode config.
71+
72+
To enable all built-in LSP servers, set `lsp` to `true`.
73+
74+
```json title="opencode.json"
75+
{
76+
"$schema": "https://opencode.ai/config.json",
77+
"lsp": true
78+
}
79+
```
80+
81+
Use an object to keep built-ins enabled while configuring overrides or custom servers.
7182

7283
```json title="opencode.json"
7384
{
@@ -76,7 +87,9 @@ You can customize LSP servers through the `lsp` section in your opencode config.
7687
}
7788
```
7889

79-
Each LSP server supports the following:
90+
Each configured LSP server entry supports the following:
91+
92+
Server entries need `command` unless they only disable a server.
8093

8194
| Property | Type | Description |
8295
| ---------------- | -------- | ------------------------------------------------- |
@@ -94,11 +107,12 @@ Let's look at some examples.
94107

95108
Use the `env` property to set environment variables when starting the LSP server:
96109

97-
```json title="opencode.json" {5-7}
110+
```json title="opencode.json" {5-8}
98111
{
99112
"$schema": "https://opencode.ai/config.json",
100113
"lsp": {
101114
"rust": {
115+
"command": ["rust-analyzer"],
102116
"env": {
103117
"RUST_LOG": "debug"
104118
}
@@ -113,11 +127,13 @@ Use the `env` property to set environment variables when starting the LSP server
113127

114128
Use the `initialization` property to pass initialization options to the LSP server. These are server-specific settings sent during the LSP `initialize` request:
115129

116-
```json title="opencode.json" {5-9}
130+
```json title="opencode.json" {5-13}
117131
{
118132
"$schema": "https://opencode.ai/config.json",
119133
"lsp": {
120-
"typescript": {
134+
"custom-lsp": {
135+
"command": ["custom-lsp-server", "--stdio"],
136+
"extensions": [".custom"],
121137
"initialization": {
122138
"preferences": {
123139
"importModuleSpecifierPreference": "relative"
@@ -136,7 +152,7 @@ Initialization options vary by LSP server. Check your LSP server's documentation
136152

137153
### Disabling LSP servers
138154

139-
To disable **all** LSP servers globally, set `lsp` to `false`:
155+
If `lsp` is omitted, all LSP servers are disabled. To disable all LSP servers after another config enabled them, set `lsp` to `false`:
140156

141157
```json title="opencode.json" {3}
142158
{

0 commit comments

Comments
 (0)