UNPKG

twoslash-python

Version:

Twoslash generator for Python - Enhance your Python documentation with TypeScript-like type information

61 lines 1.88 kB
import fs from 'fs'; function createTwoslasherPython(createOptions = {}) { const {} = createOptions; const twoslasher = (code, extension, options, pythonOptions) => { const default_nodes = [ { type: 'error', id: '', code: 0, text: 'Parsing error: Unexpected token Foo', start: 1, length: 1, level: 'error', filename: 'index.tsx', line: 0, character: 5, }, ]; if (!pythonOptions?.json_file_path) { console.log('no json_file_path'); return { code: code, nodes: default_nodes, }; } const json_file_path = pythonOptions.json_file_path; console.log('json_file_path', json_file_path); // Load the json file let json_data; let nodes; try { json_data = fs.readFileSync(json_file_path, 'utf8'); console.log('Raw JSON data:', json_data); nodes = JSON.parse(json_data); console.log('Parsed JSON data:', nodes); } catch (error) { console.error('Error loading json file', error); return { code: code, nodes: default_nodes, }; } console.log('nodes[0].type', nodes[0].type); // type Foo = { // bar: string // } console.log('nodes', nodes); // const code_without_first_line = code.split('\n').slice(1).join('\n'); return { code: code, nodes: nodes, }; }; twoslasher.getCacheMap = () => { return undefined; }; return twoslasher; } export { createTwoslasherPython }; //# sourceMappingURL=twoslasher.js.map