Skip to content

Commit 63ef5db

Browse files
authored
Add ripgrep, fill native fs functions, add ping endpoint (#39)
* Add ripgrep, fill native fs functions, add ping endpoint * Make show in folder redirect to the workspace
1 parent ec881f8 commit 63ef5db

File tree

8 files changed

+65
-13
lines changed

8 files changed

+65
-13
lines changed

build/tasks.ts

+11-3
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
8383
const browserAppOutputPath = path.join(pkgsPath, "app", "browser", "out");
8484
const nodePtyModule = path.join(pkgsPath, "protocol", "node_modules", "node-pty", "build", "Release", "pty.node");
8585
const spdlogModule = path.join(pkgsPath, "protocol", "node_modules", "spdlog", "build", "Release", "spdlog.node");
86+
let ripgrepPath = path.join(pkgsPath, "..", "lib", "vscode", "node_modules", "vscode-ripgrep", "bin", "rg");
87+
if (os.platform() === "win32") {
88+
ripgrepPath += ".exe";
89+
}
8690

8791
if (!fs.existsSync(nodePtyModule)) {
8892
throw new Error("Could not find pty.node. Ensure all packages have been installed");
@@ -99,6 +103,9 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
99103
if (!fs.existsSync(bootstrapForkPath)) {
100104
throw new Error("Bootstrap fork must exist");
101105
}
106+
if (!fs.existsSync(ripgrepPath)) {
107+
throw new Error("Ripgrep must exist");
108+
}
102109
fse.copySync(defaultExtensionsPath, path.join(cliBuildPath, "extensions"));
103110
fs.writeFileSync(path.join(cliBuildPath, "bootstrap-fork.js.gz"), zlib.gzipSync(fs.readFileSync(bootstrapForkPath)));
104111
const cpDir = (dir: string, subdir: "auth" | "unauth", rootPath: string): void => {
@@ -116,9 +123,10 @@ const buildServerBinaryCopy = register("build:server:binary:copy", async (runner
116123
};
117124
cpDir(webOutputPath, "auth", webOutputPath);
118125
cpDir(browserAppOutputPath, "unauth", browserAppOutputPath);
119-
fse.mkdirpSync(path.join(cliBuildPath, "modules"));
120-
fse.copySync(nodePtyModule, path.join(cliBuildPath, "modules", "pty.node"));
121-
fse.copySync(spdlogModule, path.join(cliBuildPath, "modules", "spdlog.node"));
126+
fse.mkdirpSync(path.join(cliBuildPath, "dependencies"));
127+
fse.copySync(nodePtyModule, path.join(cliBuildPath, "dependencies", "pty.node"));
128+
fse.copySync(spdlogModule, path.join(cliBuildPath, "dependencies", "spdlog.node"));
129+
fse.copySync(ripgrepPath, path.join(cliBuildPath, "dependencies", "rg"));
122130
});
123131

124132
const buildServerBundle = register("build:server:bundle", async (runner) => {

packages/server/scripts/nexe.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ const path = require("path");
66
const nexePath = require.resolve("nexe");
77
const shimPath = path.join(path.dirname(nexePath), "lib/steps/shim.js");
88
let shimContent = fs.readFileSync(shimPath).toString();
9-
const replaceString = `global.nativeFs = { readdir: originalReaddir, readdirSync: originalReaddirSync };`;
9+
const replaceString = `global.nativeFs = { existsSync: originalExistsSync, readFile: originalReadFile, readFileSync: originalReadFileSync, createReadStream: originalCreateReadStream, readdir: originalReaddir, readdirSync: originalReaddirSync, statSync: originalStatSync, stat: originalStat, realpath: originalRealpath, realpathSync: originalRealpathSync };`;
1010
shimContent = shimContent.replace(/compiler\.options\.resources\.length[\s\S]*wrap\("(.*\\n)"/g, (om, a) => {
1111
return om.replace(a, `${a}${replaceString}`);
1212
});

packages/server/src/fill.ts

+31
Original file line numberDiff line numberDiff line change
@@ -161,4 +161,35 @@ export const fillFs = (): void => {
161161

162162
return nativeFs.readdir(directory, callback);
163163
});
164+
165+
const fillNativeFunc = <T extends keyof typeof fs>(propertyName: T): void => {
166+
replaceNative(propertyName, (callOld, newPath, ...args) => {
167+
if (typeof newPath !== "string") {
168+
return callOld();
169+
}
170+
171+
const rel = path.relative(newPath, buildDir!);
172+
if (rel.startsWith("..")) {
173+
return callOld();
174+
}
175+
176+
const func = nativeFs[propertyName] as any;
177+
178+
return func(newPath, ...args);
179+
});
180+
};
181+
182+
const properties: Array<keyof typeof fs> = [
183+
"existsSync",
184+
"readFile",
185+
"readFileSync",
186+
"createReadStream",
187+
"readdir",
188+
"readdirSync",
189+
"statSync",
190+
"stat",
191+
"realpath",
192+
"realpathSync",
193+
];
194+
properties.forEach((p) => fillNativeFunc(p));
164195
};

packages/server/src/modules.ts

+9-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ declare var __non_webpack_require__: typeof require;
88
* Handling of native modules within the CLI
99
*/
1010
export const setup = (dataDirectory: string): void => {
11-
path.resolve(dataDirectory, "modules").split(path.sep).reduce((parentDir, childDir) => {
11+
path.resolve(dataDirectory, "dependencies").split(path.sep).reduce((parentDir, childDir) => {
1212
const currentDir = path.join(parentDir, childDir);
1313
try {
1414
fs.mkdirSync(currentDir);
@@ -22,8 +22,8 @@ export const setup = (dataDirectory: string): void => {
2222
}, path.sep);
2323

2424
const unpackModule = (moduleName: string): void => {
25-
const memFile = path.join(isCli ? buildDir! : path.join(__dirname, ".."), "build/modules", moduleName + ".node");
26-
const diskFile = path.join(dataDirectory, "modules", moduleName + ".node");
25+
const memFile = path.join(isCli ? buildDir! : path.join(__dirname, ".."), "build/dependencies", moduleName);
26+
const diskFile = path.join(dataDirectory, "dependencies", moduleName);
2727
if (!fs.existsSync(diskFile)) {
2828
fs.writeFileSync(diskFile, fs.readFileSync(memFile));
2929
}
@@ -34,15 +34,17 @@ export const setup = (dataDirectory: string): void => {
3434
* If pty.node isn't unpacked a SIGSEGV is thrown and the application exits. The exact reasoning
3535
* for this is unknown ATM, but this patch works around it.
3636
*/
37-
unpackModule("pty");
38-
unpackModule("spdlog");
37+
unpackModule("pty.node");
38+
unpackModule("spdlog.node");
39+
unpackModule("rg");
3940
const nodePtyUtils = require("../../protocol/node_modules/node-pty/lib/utils") as typeof import("../../protocol/node_modules/node-pty/src/utils");
4041
// tslint:disable-next-line:no-any
4142
nodePtyUtils.loadNative = (modName: string): any => {
42-
return (typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : require)(path.join(dataDirectory, "modules", modName + ".node"));
43+
return (typeof __non_webpack_require__ !== "undefined" ? __non_webpack_require__ : require)(path.join(dataDirectory, "dependencies", modName + ".node"));
4344
};
45+
(<any>global).RIPGREP_LOCATION = path.join(dataDirectory, "dependencies", "rg");
4446
// tslint:disable-next-line:no-any
45-
(<any>global).SPDLOG_LOCATION = path.join(dataDirectory, "modules", "spdlog.node");
47+
(<any>global).SPDLOG_LOCATION = path.join(dataDirectory, "dependencies", "spdlog.node");
4648
// tslint:disable-next-line:no-unused-expression
4749
require("../../protocol/node_modules/node-pty/lib/index") as typeof import("../../protocol/node_modules/node-pty/src/index");
4850
};

packages/server/src/server.ts

+6
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import * as httpolyglot from "httpolyglot";
1111
import * as https from "https";
1212
import * as mime from "mime-types";
1313
import * as net from "net";
14+
import * as os from "os";
1415
import * as path from "path";
1516
import * as pem from "pem";
1617
import * as util from "util";
@@ -168,6 +169,11 @@ export const createApp = async (options: CreateAppOptions): Promise<{
168169
unauthStaticFunc(req, res, next);
169170
}
170171
});
172+
app.get("/ping", (req, res) => {
173+
res.json({
174+
hostname: os.hostname(),
175+
});
176+
});
171177
app.get("/resource/:url(*)", async (req, res) => {
172178
if (!ensureAuthed(req, res)) {
173179
return;

packages/vscode/src/fill/ripgrep.ts

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
import * as path from "path";
2+
3+
// tslint:disable-next-line:no-any
4+
module.exports.rgPath = (<any>global).RIPGREP_LOCATION || path.join(__dirname, "../bin/rg");

packages/vscode/src/fill/windowsService.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -308,8 +308,8 @@ class WindowsService implements IWindowsService {
308308
throw new Error("not implemented");
309309
}
310310

311-
public showItemInFolder(_path: string): Promise<void> {
312-
throw new Error("not implemented");
311+
public async showItemInFolder(_path: string): Promise<void> {
312+
workbench.workspace = URI.file(_path);
313313
}
314314

315315
public getActiveWindowId(): Promise<number | undefined> {

packages/vscode/webpack.bootstrap.config.js

+1
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ module.exports = merge(
5252
"vs/base/browser/browser": path.resolve(fills, "empty.ts"),
5353

5454
"electron": path.join(vsFills, "stdioElectron.ts"),
55+
"vscode-ripgrep": path.join(vsFills, "ripgrep.ts"),
5556
"native-keymap": path.join(vsFills, "native-keymap.ts"),
5657
"native-watchdog": path.join(vsFills, "native-watchdog.ts"),
5758
"vs/base/common/amd": path.resolve(vsFills, "amd.ts"),

0 commit comments

Comments
 (0)