openpanel/packages/devtools-server/src/serve-open-in-editor.ts
2024-02-05 10:23:04 +01:00

17 lines
502 B
TypeScript

import { Express } from "express";
import path from "path";
export const serveOpenInEditor = (app: Express, basePath: string) => {
app.get("/open-in-editor/*", (req, res) => {
const { line, column } = req.query;
const filePath = req.path.replace("/open-in-editor", "");
const vscodeUrl = `vscode://file/${path.join(basePath, filePath)}?${
line ? `line=${line}` : ""
}${column ? `&column=${column}` : ""}`;
res.redirect(vscodeUrl);
});
};