Skip to content

Commit

Permalink
[pre-commit.ci lite] apply automatic fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
pre-commit-ci-lite[bot] authored Jun 13, 2024
1 parent f0f74cb commit 593a1c8
Showing 1 changed file with 53 additions and 28 deletions.
81 changes: 53 additions & 28 deletions cursorless.nvim/node/command-server/index/index.cjs
Original file line number Diff line number Diff line change
Expand Up @@ -8,19 +8,23 @@ var __export = (target, all) => {
__defProp(target, name, { get: all[name], enumerable: true });
};
var __copyProps = (to, from, except, desc) => {
if (from && typeof from === "object" || typeof from === "function") {
if ((from && typeof from === "object") || typeof from === "function") {
for (let key of __getOwnPropNames(from))
if (!__hasOwnProp.call(to, key) && key !== except)
__defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
__defProp(to, key, {
get: () => from[key],
enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable,
});
}
return to;
};
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
var __toCommonJS = (mod) =>
__copyProps(__defProp({}, "__esModule", { value: true }), mod);

// src/index.ts
var src_exports = {};
__export(src_exports, {
default: () => entry
default: () => entry,
});
module.exports = __toCommonJS(src_exports);

Expand All @@ -35,7 +39,10 @@ var import_path = require("path");
function getCommunicationDirPath() {
const info = (0, import_os.userInfo)();
const suffix = info.uid >= 0 ? `-${info.uid}` : "";
return (0, import_path.join)((0, import_os.tmpdir)(), `neovim-command-server${suffix}`);
return (0, import_path.join)(
(0, import_os.tmpdir)(),
`neovim-command-server${suffix}`,
);
}
function getSignalDirPath() {
return (0, import_path.join)(getCommunicationDirPath(), "signals");
Expand Down Expand Up @@ -84,21 +91,31 @@ var NativeIo = class {
async initialize() {
const communicationDirPath = getCommunicationDirPath();
console.log(`Creating communication dir ${communicationDirPath}`);
(0, import_fs.mkdirSync)(communicationDirPath, { recursive: true, mode: 504 });
(0, import_fs.mkdirSync)(communicationDirPath, {
recursive: true,
mode: 504,
});
const stats = (0, import_fs.lstatSync)(communicationDirPath);
const info = (0, import_os2.userInfo)();
if (!stats.isDirectory() || stats.isSymbolicLink() || stats.mode & import_constants.S_IWOTH || // On Windows, uid < 0, so we don't worry about it for simplicity
info.uid >= 0 && stats.uid !== info.uid) {
if (
!stats.isDirectory() ||
stats.isSymbolicLink() ||
stats.mode & import_constants.S_IWOTH || // On Windows, uid < 0, so we don't worry about it for simplicity
(info.uid >= 0 && stats.uid !== info.uid)
) {
throw new Error(
`Refusing to proceed because of invalid communication dir ${communicationDirPath}`
`Refusing to proceed because of invalid communication dir ${communicationDirPath}`,
);
}
}
async prepareResponse() {
if (this.responseFile) {
throw new Error("response is already locked");
}
this.responseFile = await (0, import_promises.open)(getResponsePath(), "wx");
this.responseFile = await (0, import_promises.open)(
getResponsePath(),
"wx",
);
}
async closeResponse() {
if (!this.responseFile) {
Expand All @@ -115,10 +132,15 @@ var NativeIo = class {
async readRequest() {
const requestPath = getRequestPath();
const stats = await (0, import_promises.stat)(requestPath);
const request = JSON.parse(await (0, import_promises.readFile)(requestPath, "utf-8"));
if (Math.abs(stats.mtimeMs - (/* @__PURE__ */ new Date()).getTime()) > NEOVIM_COMMAND_TIMEOUT_MS) {
const request = JSON.parse(
await (0, import_promises.readFile)(requestPath, "utf-8"),
);
if (
Math.abs(stats.mtimeMs - /* @__PURE__ */ new Date().getTime()) >
NEOVIM_COMMAND_TIMEOUT_MS
) {
throw new Error(
"Request file is older than timeout; refusing to execute command"
"Request file is older than timeout; refusing to execute command",
);
}
return request;
Expand Down Expand Up @@ -186,8 +208,7 @@ var CommandRunner = class {
this.runCommand = this.runCommand.bind(this);
this.reloadConfiguration();
}
reloadConfiguration() {
}
reloadConfiguration() {}
/**
* Reads a command from the request file and executes it. Writes information
* about command execution to the result of the command to the response file,
Expand All @@ -196,7 +217,9 @@ var CommandRunner = class {
* types.
*/
async runCommand() {
console.log("------------------------------------------------------------------------------");
console.log(
"------------------------------------------------------------------------------",
);
await this.io.prepareResponse();
let request;
try {
Expand All @@ -205,7 +228,8 @@ var CommandRunner = class {
await this.io.closeResponse();
throw err;
}
const { commandId, args, uuid, returnCommandOutput, waitForFinish } = request;
const { commandId, args, uuid, returnCommandOutput, waitForFinish } =
request;
const warnings = [];
try {
if (!commandId.match(this.allowRegex)) {
Expand All @@ -214,7 +238,10 @@ var CommandRunner = class {
if (this.denyRegex != null && commandId.match(this.denyRegex)) {
throw new Error("Command in denyList");
}
const commandPromise = getNeovimRegistry().executeCommand(commandId, ...args);
const commandPromise = getNeovimRegistry().executeCommand(
commandId,
...args,
);
let commandReturnValue = null;
if (returnCommandOutput) {
commandReturnValue = await commandPromise;
Expand All @@ -225,13 +252,13 @@ var CommandRunner = class {
error: null,
uuid,
returnValue: commandReturnValue,
warnings
warnings,
});
} catch (err) {
await this.io.writeResponse({
error: err.message,
uuid,
warnings
warnings,
});
}
await this.io.closeResponse();
Expand Down Expand Up @@ -271,8 +298,8 @@ async function activate() {
* This signal is emitted by the voice engine to indicate that a phrase has
* just begun execution.
*/
prePhrase: io.getInboundSignal("prePhrase")
}
prePhrase: io.getInboundSignal("prePhrase"),
},
};
}

Expand All @@ -282,13 +309,11 @@ function entry(plugin) {
plugin.registerFunction(
"CommandServerLoadExtension",
async () => await loadExtension(plugin),
{ sync: false }
);
plugin.registerFunction(
"CommandServerRunCommand",
() => runCommand(),
{ sync: false }
{ sync: false },
);
plugin.registerFunction("CommandServerRunCommand", () => runCommand(), {
sync: false,
});
}
async function loadExtension(plugin) {
console.log("loadExtension(command-server): start");
Expand Down

0 comments on commit 593a1c8

Please sign in to comment.