mirror of
https://github.com/dandavison/delta.git
synced 2024-10-04 11:57:15 +03:00
Evolve python hyperlink server example
This commit is contained in:
parent
9889aedebd
commit
95457d30c9
@ -40,18 +40,23 @@ If your editor does not have its own URL protocol, then there are still many pos
|
||||
from subprocess import call
|
||||
from urllib.parse import parse_qs, urlparse
|
||||
|
||||
|
||||
class OpenInEditor(BaseHTTPRequestHandler):
|
||||
def do_GET(self):
|
||||
if self.path.startswith("/open-in-editor"):
|
||||
query = parse_qs(urlparse(self.path).query)
|
||||
[path], [line] = query["path"], query["line"]
|
||||
# TODO: You might need to change this to construct the correct root directory for the
|
||||
# project that the file is in, so that your IDE opens in the project workspace.
|
||||
cwd = Path(path).parent
|
||||
# TODO: Replace with the appropriate command for your editor
|
||||
call(["code", "-g", f"{path}:{line}"], cwd=Path(path).parent)
|
||||
call(["code", "-g", f"{path}:{line}"], cwd=cwd)
|
||||
self.send_response(200)
|
||||
else:
|
||||
self.send_response(404)
|
||||
self.end_headers()
|
||||
|
||||
|
||||
print("Starting httpd server on port 8000...")
|
||||
HTTPServer(("", 8000), OpenInEditor).serve_forever()
|
||||
```
|
||||
|
Loading…
Reference in New Issue
Block a user