UNPKG

radashi-helper

Version:
84 lines (73 loc) 3.08 kB
"use strict";Object.defineProperty(exports, "__esModule", {value: true}); function _optionalChain(ops) { let lastAccessLHS = undefined; let value = ops[0]; let i = 1; while (i < ops.length) { const op = ops[i]; const fn = ops[i + 1]; i += 2; if ((op === 'optionalAccess' || op === 'optionalCall') && value == null) { return undefined; } if (op === 'access' || op === 'optionalAccess') { lastAccessLHS = value; value = fn(value); } else if (op === 'call' || op === 'optionalCall') { value = fn((...args) => value.call(lastAccessLHS, ...args)); lastAccessLHS = undefined; } } return value; } var _chunk4WZBZWYDcjs = require('./chunk-4WZBZWYD.cjs'); var _chunkST3J6QTNcjs = require('./chunk-ST3J6QTN.cjs'); var _chunk5R2KEZLQcjs = require('./chunk-5R2KEZLQ.cjs'); // src/util/queryFuncs.ts async function queryFuncs(query, funcPaths, options = {}) { let funcPath; if (options.exactMatch) { funcPath = query; } else { let bestMatches; let confirm = false; if (query !== "") { const loweredQuery = query.toLowerCase(); const scores = funcPaths.map((funcPath2) => { const funcName = funcPath2.split("/").at(-1); return Math.min( _chunk5R2KEZLQcjs.similarity.call(void 0, loweredQuery, funcName.toLowerCase()), _chunk5R2KEZLQcjs.similarity.call(void 0, loweredQuery, funcPath2.toLowerCase()) ); }); const bestScore = Math.min(...scores); bestMatches = funcPaths.filter((_file, i) => { return scores[i] === bestScore; }); confirm = bestScore > 0; } else { bestMatches = funcPaths; } if (!bestMatches.length) { throw new (0, _chunkST3J6QTNcjs.RadashiError)( `No source file matching "${query}" was found in Radashi` ); } if (bestMatches.length > 1) { if (bestMatches.length > 1) { const selectedFunc = await _chunk4WZBZWYDcjs.prompt.call(void 0, { type: "autocomplete", name: "selectedFunc", message: options.message || "Select a function:", choices: bestMatches.map((f) => ({ title: f, value: f })) }); if (!selectedFunc) { throw new (0, _chunkST3J6QTNcjs.EarlyExitError)("No function selected. Exiting..."); } funcPath = selectedFunc; } else { funcPath = bestMatches[0]; if (confirm) { const shouldContinue = await _chunk4WZBZWYDcjs.prompt.call(void 0, { type: "confirm", name: "shouldContinue", message: _optionalChain([options, 'access', _ => _.confirmMessage, 'optionalAccess', _2 => _2.replace, 'call', _3 => _3("{funcPath}", funcPath)]) || `Is "${funcPath}" the function you wanted?`, initial: true }); if (!shouldContinue) { throw new (0, _chunkST3J6QTNcjs.EarlyExitError)(); } } } } else { funcPath = bestMatches[0]; } } return { funcPath, funcName: funcPath.split("/").at(-1) }; } exports.queryFuncs = queryFuncs;