(doc: CodeMirror.Doc, path: string | undefined)
| 83 | } |
| 84 | |
| 85 | export function language(doc: CodeMirror.Doc, path: string | undefined): Language { |
| 86 | if (path !== undefined) { |
| 87 | const basename = path.split('/').pop() ?? ''; |
| 88 | // Iterate over FILENAME_MAP for a match. |
| 89 | for (const [regex, language] of FILENAME_MAP) { |
| 90 | if (regex.test(basename)) { |
| 91 | return language; |
| 92 | } |
| 93 | } |
| 94 | } |
| 95 | const mime = doc.getEditor()?.getOption('mode'); |
| 96 | if (typeof mime === 'string') { |
| 97 | const language = MIME_MAP.get(mime); |
| 98 | if (language !== undefined) { |
| 99 | return language; |
| 100 | } |
| 101 | } |
| 102 | return MODE_MAP.get(getMode(doc).name) ?? Language.UNSPECIFIED; |
| 103 | } |
no test coverage detected