Skip to content

Commit 924bfac

Browse files
authored
Document opening a file at a line via the payload query parameter (#7909)
1 parent 4cf9c11 commit 924bfac

1 file changed

Lines changed: 34 additions & 0 deletions

File tree

docs/FAQ.md

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
- [Where is VS Code configuration stored?](#where-is-vs-code-configuration-stored)
1818
- [How can I reuse my VS Code configuration?](#how-can-i-reuse-my-vs-code-configuration)
1919
- [How does code-server decide what workspace or folder to open?](#how-does-code-server-decide-what-workspace-or-folder-to-open)
20+
- [Can I open a file at a specific line from a URL?](#can-i-open-a-file-at-a-specific-line-from-a-url)
2021
- [How do I access my Documents/Downloads/Desktop folders in code-server on macOS?](#how-do-i-access-my-documentsdownloadsdesktop-folders-in-code-server-on-macos)
2122
- [How do I direct server-side requests through a proxy?](#how-do-i-direct-server-side-requests-through-a-proxy)
2223
- [How do I debug issues with code-server?](#how-do-i-debug-issues-with-code-server)
@@ -230,6 +231,39 @@ code-server tries the following in this order:
230231
3. The workspace or directory passed via the command line
231232
4. The last opened workspace or directory
232233

234+
## Can I open a file at a specific line from a URL?
235+
236+
Yes. In addition to `workspace` and `folder`, code-server supports VS Code's
237+
`payload` query parameter, which can open a specific file — optionally at a
238+
line and column — once the workbench loads.
239+
240+
`payload` is a URL-encoded JSON array of `[key, value]` string pairs. The
241+
`openFile` key takes a `vscode-remote://<host>/<absolute path>` URI, where
242+
`<host>` is the host you use to reach code-server. Add
243+
`["gotoLineMode","true"]` to have a trailing `:line[:column]` suffix on the
244+
path interpreted as a cursor position:
245+
246+
```text
247+
https://code.example.com/?folder=/home/coder/project&payload=[["gotoLineMode","true"],["openFile","vscode-remote://code.example.com/home/coder/project/src/app.py:10:5"]]
248+
```
249+
250+
(with the `payload` value URL-encoded). Notes:
251+
252+
- Paths must be absolute; there is no form relative to `folder`.
253+
- This is upstream VS Code web behavior (the same mechanism vscode.dev uses),
254+
so it works without any code-server-specific configuration.
255+
256+
For example, to generate links from a shell:
257+
258+
```sh
259+
#!/bin/sh
260+
# usage: code-link <absolute-file> [line[:column]]
261+
HOST=code.example.com
262+
payload="[[\"gotoLineMode\",\"true\"],[\"openFile\",\"vscode-remote://$HOST$1${2:+:$2}\"]]"
263+
printf 'https://%s/?folder=%s&payload=%s\n' "$HOST" "$(dirname "$1")" \
264+
"$(printf '%s' "$payload" | jq -sRr @uri)"
265+
```
266+
233267
## How do I access my Documents/Downloads/Desktop folders in code-server on macOS?
234268

235269
Newer versions of macOS require permission through a non-UNIX mechanism for

0 commit comments

Comments
 (0)