1
1
# command-server README
2
2
3
- Creates an http server listening for commands.
3
+ Creates an http server listening for commands to execute .
4
4
5
5
## Features
6
6
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.
10
12
11
13
Accepts requests of the form:
12
14
@@ -27,4 +29,33 @@ Upon receiving the above, this extension would run the command
27
29
Note that the server is bound to ` localhost ` , so it will only accept commands
28
30
from processes running on the same host as VSCode.
29
31
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
+
30
61
## Release Notes
0 commit comments