| 1 | /* Patch bundled Monaco C# monarch with modern keywords (C# 9–14). */ |
| 2 | (function (global) { |
| 3 | 'use strict'; |
| 4 | |
| 5 | const MODERN_KEYWORDS = [ |
| 6 | 'record', 'file', 'required', 'init', 'scoped', 'nint', 'nuint', 'and', 'or', 'not', 'when', |
| 7 | 'nameof', 'await', 'async', 'unsafe', 'fixed', 'sizeof', 'stackalloc', 'enum', 'interface', |
| 8 | 'global', 'using', 'with', |
| 9 | ]; |
| 10 | |
| 11 | function patchCsharpMonarch(monaco, require) { |
| 12 | if (!monaco || !require) return; |
| 13 | try { |
| 14 | const mod = require('vs/basic-languages/csharp/csharp'); |
| 15 | if (!mod?.language) return; |
| 16 | const lang = { ...mod.language }; |
| 17 | const base = Array.isArray(lang.keywords) ? lang.keywords : []; |
| 18 | lang.keywords = [...new Set([...base, ...MODERN_KEYWORDS])]; |
| 19 | monaco.languages.setMonarchTokensProvider('csharp', lang); |
| 20 | if (mod.conf) { |
| 21 | monaco.languages.setLanguageConfiguration('csharp', mod.conf); |
| 22 | } |
| 23 | } catch (err) { |
| 24 | console.warn('cide: csharp monarch patch failed', err); |
| 25 | } |
| 26 | } |
| 27 | |
| 28 | global.cidePatchCsharpMonarch = patchCsharpMonarch; |
| 29 | })(typeof window !== 'undefined' ? window : globalThis); |
| 30 | |