Skip to content

Commit d1b464c

Browse files
committed
More doc improvements
1 parent be06c90 commit d1b464c

File tree

1 file changed

+35
-4
lines changed

1 file changed

+35
-4
lines changed

README.md

Lines changed: 35 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# command-server README
22

3-
Creates an http server listening for commands.
3+
Creates an http server listening for commands to execute.
44

55
## Features
66

7-
On startup, spawns an http server listening for commands to execute. The port
8-
of the server for the active editor is written to a file named `vscode-port` in
9-
the operating system's default directory for temporary files.
7+
On startup, spawns an http server listening for commands to execute. Each
8+
running VSCode editor workspace runs its own server, each of which pick a
9+
different random free port on which to listen.
10+
The port of the server for the active editor is written to a file named
11+
`vscode-port` in the operating system's default directory for temporary files.
1012

1113
Accepts requests of the form:
1214

@@ -27,4 +29,33 @@ Upon receiving the above, this extension would run the command
2729
Note that the server is bound to `localhost`, so it will only accept commands
2830
from processes running on the same host as VSCode.
2931

32+
### Python example
33+
34+
```py
35+
import requests
36+
from pathlib import Path
37+
from tempfile import gettempdir
38+
39+
40+
port_file_path = Path(gettempdir()) / "vscode-port"
41+
port = port_file_path.read_text()
42+
43+
response = requests.post(
44+
f"http://localhost:{port}/execute-command",
45+
json={
46+
"commandId": "some-command-id",
47+
"args": ["some-argument"],
48+
},
49+
timeout=(0.05, 3.05),
50+
)
51+
response.raise_for_status()
52+
```
53+
54+
## Known issues
55+
56+
- The server won't respond until the extension is loaded. This may be obvious,
57+
but just be aware that if you have other extensions that take a while to
58+
load, the server might not respond for a little while after you load an
59+
editor window until everything is fully loaded.
60+
3061
## Release Notes

0 commit comments

Comments
 (0)