language.ts 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. import type * as monacoType from 'monaco-editor/esm/vs/editor/editor.api';
  2. // Dynamic labels: https://docs.aws.amazon.com/AmazonCloudWatch/latest/monitoring/graph-dynamic-labels.html
  3. export const DYNAMIC_LABEL_PATTERNS = [
  4. '${DATAPOINT_COUNT}',
  5. '${FIRST}',
  6. '${FIRST_LAST_RANGE}',
  7. '${FIRST_LAST_TIME_RANGE}',
  8. '${FIRST_TIME}',
  9. '${FIRST_TIME_RELATIVE}',
  10. '${LABEL}',
  11. '${LAST}',
  12. '${LAST_TIME}',
  13. '${LAST_TIME_RELATIVE}',
  14. '${MAX}',
  15. '${MAX_TIME}',
  16. '${MAX_TIME_RELATIVE}',
  17. '${MIN}',
  18. '${MIN_MAX_RANGE}',
  19. '${MIN_MAX_TIME_RANGE}',
  20. '${MIN_TIME}',
  21. '${MIN_TIME_RELATIVE}',
  22. "${PROP('AccountId')}",
  23. "${PROP('MetricName')}",
  24. "${PROP('Namespace')}",
  25. "${PROP('Period')}",
  26. "${PROP('Region')}",
  27. "${PROP('Stat')}",
  28. '${SUM}',
  29. ];
  30. export const language: monacoType.languages.IMonarchLanguage = {
  31. id: 'dynamicLabels',
  32. ignoreCase: false,
  33. tokenizer: {
  34. root: [
  35. { include: '@whitespace' },
  36. { include: '@builtInFunctions' },
  37. { include: '@string' },
  38. [/\$\{PROP\('Dim.[a-zA-Z0-9-_]?.*'\)\}+/, 'predefined'], //custom handling for dimension patterns
  39. ],
  40. builtInFunctions: [[DYNAMIC_LABEL_PATTERNS.map(escapeRegExp).join('|'), 'predefined']],
  41. whitespace: [[/\s+/, 'white']],
  42. string: [],
  43. },
  44. };
  45. export const conf: monacoType.languages.LanguageConfiguration = {};
  46. function escapeRegExp(string: string) {
  47. return string.replace(/[.*+?^${}()|[\]\\]/g, '\\$&'); // $& means the whole matched string
  48. }