(source: { text: string; path: string }, subject?: { name: string; kind?: string })
| 126 | |
| 127 | /** The facts of the code a selection stands for, or undefined without code. */ |
| 128 | export function codeFacts(source: { text: string; path: string }, subject?: { name: string; kind?: string }): CodeFacts | undefined { |
| 129 | const lines = source.text.replace(/\r\n?/g, '\n').split('\n'); |
| 130 | if (!source.text.trim()) return undefined; |
| 131 | const fence = FENCES[extension(source.path)] ?? ''; |
| 132 | return (fence === 'python' ? pythonFacts(lines, subject?.name) : undefined) ?? definitionLine(lines, subject?.name, fence); |
| 133 | } |
| 134 | |
| 135 | const LANGUAGES: Readonly<Record<string, string>> = { python: 'Python', typescript: 'TypeScript', javascript: 'JavaScript', go: 'Go', rust: 'Rust', java: 'Java', c: 'C', cpp: 'C++', |
| 136 | ruby: 'Ruby', bash: 'Shell', kotlin: 'Kotlin', csharp: 'C#', php: 'PHP', swift: 'Swift' }; |
no test coverage detected