|
17 | 17 | - [Where is VS Code configuration stored?](#where-is-vs-code-configuration-stored) |
18 | 18 | - [How can I reuse my VS Code configuration?](#how-can-i-reuse-my-vs-code-configuration) |
19 | 19 | - [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) |
20 | 21 | - [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) |
21 | 22 | - [How do I direct server-side requests through a proxy?](#how-do-i-direct-server-side-requests-through-a-proxy) |
22 | 23 | - [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: |
230 | 231 | 3. The workspace or directory passed via the command line |
231 | 232 | 4. The last opened workspace or directory |
232 | 233 |
|
| 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 | + |
233 | 267 | ## How do I access my Documents/Downloads/Desktop folders in code-server on macOS? |
234 | 268 |
|
235 | 269 | Newer versions of macOS require permission through a non-UNIX mechanism for |
|
0 commit comments