openpanel/packages/devtools-server/src/serve-open-in-editor.ts
Stefan Pejcic 09f9f9502d packages
2024-11-07 19:03:37 +01:00

17 lines
477 B
TypeScript

import type { 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);
});
};