forked from deco-cx/inspect-vscode
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandler.ts
More file actions
27 lines (24 loc) · 691 Bytes
/
Copy pathhandler.ts
File metadata and controls
27 lines (24 loc) · 691 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
import { search } from "./search.ts";
export default async function inspectHandler(
inspectPath = "/_live/inspect/",
req: Request,
): Promise<Response> {
const outerHTML = await req.text();
const url = new URL(req.url);
const manifestKey = "./" + url.pathname.replace(inspectPath, "");
const { fullpath, lineNumber, column } = await search(
outerHTML,
manifestKey,
);
const link = vsCodeLinkFromResult(fullpath, lineNumber, column);
return new Response(link, {
headers: { "Content-Type": "text/html" },
});
}
function vsCodeLinkFromResult(
file: string,
line: number,
column: number,
): string {
return `vscode://file/${file}:${line}:${column}`;
}