You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+1-1Lines changed: 1 addition & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -132,7 +132,7 @@ It's very similar to Claude Code in terms of capability. Here are the key differ
132
132
133
133
- 100% open source
134
134
- 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
136
136
- 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.
137
137
- 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.
Copy file name to clipboardExpand all lines: packages/web/src/content/docs/formatters.mdx
+19-8Lines changed: 19 additions & 8 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: Formatters
3
3
description: OpenCode uses language specific formatters.
4
4
---
5
5
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.
7
7
8
8
---
9
9
@@ -40,25 +40,36 @@ OpenCode comes with several built-in formatters for popular languages and framew
40
40
| uv | .py, .pyi |`uv` command available |
41
41
| zig | .zig, .zon |`zig` command available |
42
42
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`.
44
44
45
45
---
46
46
47
47
## How it works
48
48
49
-
When OpenCode writes or edits a file, it:
49
+
When OpenCode writes or edits a file and formatters are enabled, it:
50
50
51
51
1. Checks the file extension against all enabled formatters.
52
52
2. Runs the appropriate formatter command on the file.
53
-
3. Applies the formatting changes automatically.
53
+
3. Applies the formatting changes.
54
54
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.
56
56
57
57
---
58
58
59
59
## Configure
60
60
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.
62
73
63
74
```json title="opencode.json"
64
75
{
@@ -82,7 +93,7 @@ Let's look at some examples.
82
93
83
94
### Disabling formatters
84
95
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`:
86
97
87
98
```json title="opencode.json" {3}
88
99
{
@@ -108,7 +119,7 @@ To disable a **specific** formatter, set `disabled` to `true`:
108
119
109
120
### Custom formatters
110
121
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 or add new ones by specifying the command, environment variables, and file extensions:
Copy file name to clipboardExpand all lines: packages/web/src/content/docs/lsp.mdx
+25-9Lines changed: 25 additions & 9 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,7 +3,7 @@ title: LSP Servers
3
3
description: OpenCode integrates with your LSP servers.
4
4
---
5
5
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.
7
7
8
8
---
9
9
@@ -48,7 +48,7 @@ OpenCode comes with several built-in LSP servers for popular languages:
48
48
| yaml-ls | .yaml, .yml | Auto-installs Red Hat yaml-language-server |
49
49
| zls | .zig, .zon |`zig` command available |
50
50
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.
52
52
53
53
:::note
54
54
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_
58
58
59
59
## How It Works
60
60
61
-
When opencode opens a file, it:
61
+
When LSP is enabled and opencode opens a file, it:
62
62
63
63
1. Checks the file extension against all enabled LSP servers.
64
64
2. Starts the appropriate LSP server if not already running.
@@ -67,7 +67,18 @@ When opencode opens a file, it:
67
67
68
68
## Configure
69
69
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.
71
82
72
83
```json title="opencode.json"
73
84
{
@@ -76,7 +87,9 @@ You can customize LSP servers through the `lsp` section in your opencode config.
76
87
}
77
88
```
78
89
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.
Use the `env` property to set environment variables when starting the LSP server:
96
109
97
-
```json title="opencode.json" {5-7}
110
+
```json title="opencode.json" {5-8}
98
111
{
99
112
"$schema": "https://opencode.ai/config.json",
100
113
"lsp": {
101
114
"rust": {
115
+
"command": ["rust-analyzer"],
102
116
"env": {
103
117
"RUST_LOG": "debug"
104
118
}
@@ -113,11 +127,13 @@ Use the `env` property to set environment variables when starting the LSP server
113
127
114
128
Use the `initialization` property to pass initialization options to the LSP server. These are server-specific settings sent during the LSP `initialize` request:
115
129
116
-
```json title="opencode.json" {5-9}
130
+
```json title="opencode.json" {5-13}
117
131
{
118
132
"$schema": "https://opencode.ai/config.json",
119
133
"lsp": {
120
-
"typescript": {
134
+
"custom-lsp": {
135
+
"command": ["custom-lsp-server", "--stdio"],
136
+
"extensions": [".custom"],
121
137
"initialization": {
122
138
"preferences": {
123
139
"importModuleSpecifierPreference": "relative"
@@ -136,7 +152,7 @@ Initialization options vary by LSP server. Check your LSP server's documentation
136
152
137
153
### Disabling LSP servers
138
154
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`:
0 commit comments