getWhereBindings
Extract 'where' clauses from PureScript functions to identify local helper functions and variables, aiding in understanding function implementation details.
Instructions
Find 'where' clauses in PureScript functions. These contain local helper functions and variables. Useful for understanding function implementation details.
Input Schema
TableJSON Schema
| Name | Required | Description | Default |
|---|---|---|---|
| code | Yes | PureScript code snippet. |
Implementation Reference
- index.js:887-921 (handler)Handler function that uses Tree-sitter to parse PureScript code, queries for 'where' clauses in functions (where keyword followed by declarations block), extracts and combines the text of these blocks, deduplicates them, and returns as a JSON array of strings."getWhereBindings": async (args) => { if (!treeSitterInitialized) throw new Error("Tree-sitter not initialized."); const code = await getCodeFromInput(args, false); // Snippet-oriented const tree = purescriptTsParser.parse(code); const whereClausesText = []; // Query for 'where' keyword followed by a 'declarations' block within a function or let binding const querySource = ` (function (where) @where_keyword (declarations) @declarations_block) `; // Also consider 'let' bindings with 'where' clauses, though less common for top-level 'where' // (let_binding (where) @where_keyword (declarations) @declarations_block) const query = new Query(PureScriptLanguage, querySource); const matches = query.matches(tree.rootNode); for (const match of matches) { const whereKeywordNode = match.captures.find(c => c.name === 'where_keyword')?.node; const declarationsNode = match.captures.find(c => c.name === 'declarations_block')?.node; if (whereKeywordNode && declarationsNode) { // Construct the text from "where" keyword to the end of the declarations block // This requires careful handling of start and end positions if they are not contiguous in the source text string // For simplicity, if they are siblings and in order, we can take text from start of 'where' to end of 'declarations' // A safer way is to combine their individual texts if they represent the full conceptual block const fullWhereClauseText = `${whereKeywordNode.text} ${declarationsNode.text}`; whereClausesText.push(fullWhereClauseText.trim()); } } // Deduplicate, as some complex structures might yield multiple partial matches const uniqueWhereClauses = [...new Set(whereClausesText)]; return { content: [{ type: "text", text: JSON.stringify(uniqueWhereClauses, null, 2) }] }; },
- index.js:628-636 (registration)Tool registration in TOOL_DEFINITIONS array, including name, description, and input schema (requires 'code' string). Used by tools/list method.name: "getWhereBindings", description: "Find 'where' clauses in PureScript functions. These contain local helper functions and variables. Useful for understanding function implementation details.", inputSchema: { type: "object", properties: { code: { type: "string", description: "PureScript code snippet." } }, required: ["code"], additionalProperties: false } },
- index.js:628-636 (schema)Input schema definition for getWhereBindings tool: object with required 'code' property (PureScript code snippet).name: "getWhereBindings", description: "Find 'where' clauses in PureScript functions. These contain local helper functions and variables. Useful for understanding function implementation details.", inputSchema: { type: "object", properties: { code: { type: "string", description: "PureScript code snippet." } }, required: ["code"], additionalProperties: false } },
- index.js:125-151 (helper)Helper function getCodeFromInput used by getWhereBindings (and other tools) to retrieve code from args.code or filePath, validating inputs and preferring snippets for this tool.// Helper to get code from input args (filePath or code string) async function getCodeFromInput(args, isModuleOriented = true) { if (isModuleOriented) { const hasFilePath = args && typeof args.filePath === 'string'; const hasCode = args && typeof args.code === 'string'; if ((hasFilePath && hasCode) || (!hasFilePath && !hasCode)) { throw new Error("Invalid input: Exactly one of 'filePath' or 'code' must be provided for module-oriented tools."); } if (hasFilePath) { if (!path.isAbsolute(args.filePath)) { throw new Error(`Invalid filePath: '${args.filePath}' is not an absolute path. Only absolute paths are supported.`); } try { return await fs.readFile(args.filePath, 'utf-8'); } catch (e) { throw new Error(`Failed to read file at ${args.filePath}: ${e.message}`); } } return args.code; } else { // Snippet-oriented if (!args || typeof args.code !== 'string') { throw new Error("Invalid input: 'code' (string) is required for snippet-oriented tools."); } return args.code; } }