@finos/legend-application 2.0.13 → 3.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (43) hide show
  1. package/lib/application/LegendApplication.d.ts +0 -1
  2. package/lib/application/LegendApplication.d.ts.map +1 -1
  3. package/lib/application/LegendApplication.js +4 -15
  4. package/lib/application/LegendApplication.js.map +1 -1
  5. package/lib/application/LegendApplicationPluginManager.d.ts +4 -0
  6. package/lib/application/LegendApplicationPluginManager.d.ts.map +1 -1
  7. package/lib/application/LegendApplicationPluginManager.js +7 -0
  8. package/lib/application/LegendApplicationPluginManager.js.map +1 -1
  9. package/lib/index.css +1 -1
  10. package/lib/index.d.ts +2 -1
  11. package/lib/index.d.ts.map +1 -1
  12. package/lib/index.js +2 -1
  13. package/lib/index.js.map +1 -1
  14. package/lib/stores/ApplicationStore.d.ts +1 -1
  15. package/lib/stores/ApplicationStore.d.ts.map +1 -1
  16. package/lib/stores/ApplicationStore.js +10 -1
  17. package/lib/stores/ApplicationStore.js.map +1 -1
  18. package/lib/stores/LegendApplicationConfig.d.ts +4 -9
  19. package/lib/stores/LegendApplicationConfig.d.ts.map +1 -1
  20. package/lib/stores/LegendApplicationConfig.js +6 -13
  21. package/lib/stores/LegendApplicationConfig.js.map +1 -1
  22. package/lib/stores/LegendApplicationDocumentationRegistry.d.ts +13 -1
  23. package/lib/stores/LegendApplicationDocumentationRegistry.d.ts.map +1 -1
  24. package/lib/stores/LegendApplicationDocumentationRegistry.js +18 -0
  25. package/lib/stores/LegendApplicationDocumentationRegistry.js.map +1 -1
  26. package/lib/stores/LegendApplicationPlugin.d.ts +24 -0
  27. package/lib/stores/LegendApplicationPlugin.d.ts.map +1 -0
  28. package/lib/stores/LegendApplicationPlugin.js +19 -0
  29. package/lib/stores/LegendApplicationPlugin.js.map +1 -0
  30. package/lib/stores/PureLanguageSupport.d.ts +2 -33
  31. package/lib/stores/PureLanguageSupport.d.ts.map +1 -1
  32. package/lib/stores/PureLanguageSupport.js +86 -74
  33. package/lib/stores/PureLanguageSupport.js.map +1 -1
  34. package/package.json +15 -12
  35. package/src/application/LegendApplication.tsx +4 -36
  36. package/src/application/LegendApplicationPluginManager.tsx +10 -0
  37. package/src/index.ts +2 -2
  38. package/src/stores/ApplicationStore.ts +15 -2
  39. package/src/stores/LegendApplicationConfig.ts +11 -31
  40. package/src/stores/LegendApplicationDocumentationRegistry.ts +47 -1
  41. package/src/stores/LegendApplicationPlugin.ts +25 -0
  42. package/src/stores/PureLanguageSupport.ts +106 -81
  43. package/tsconfig.json +1 -0
@@ -15,56 +15,39 @@
15
15
  */
16
16
 
17
17
  /* eslint-disable prefer-named-capture-group */
18
- import type {
18
+ import {
19
+ type GraphPluginManager,
20
+ PARSER_SECTION_MARKER,
21
+ PURE_ELEMENT_NAME,
22
+ PURE_CONNECTION_NAME,
23
+ PURE_PARSER,
24
+ } from '@finos/legend-graph';
25
+ import {
19
26
  editor as monacoEditorAPI,
20
27
  languages as monacoLanguagesAPI,
21
28
  } from 'monaco-editor';
29
+ import { EDITOR_LANGUAGE, EDITOR_THEME } from '../const';
22
30
 
23
- export enum GRAMMAR_ELEMENT_TYPE_LABEL {
24
- PROFILE = 'Profile',
25
- CLASS = 'Class',
26
- ENUMERATION = 'Enum',
27
- MEASURE = 'Measure',
28
- ASSOCIATION = 'Association',
29
- FLAT_DATA = 'FlatData',
30
- MAPPING = 'Mapping',
31
- DATABASE = 'Database',
32
- SERVICE_STORE = 'ServiceStore',
33
- FUNCTION = 'function',
34
- SERVICE = 'Service',
35
- RUNTIME = 'Runtime',
36
- CONNECTION = 'Connection',
37
- FILE_GENERATION = 'FileGeneration',
38
- GENERATION_SPECIFICATION = 'GenerationSpecification',
39
-
40
- JSON_MODEL_CONNECTION = 'JsonModelConnection',
41
- XML_MODEL_CONNECTION = 'XmlModelConnection',
42
- MODEL_CHAIN_CONNECTION = 'ModelChainConnection',
43
- FLAT_DATA_CONNECTION = 'FlatDataConnection',
44
- RELATIONAL_DATABASE_CONNECTION = 'RelationalDatabaseConnection',
45
- }
46
-
47
- export const theme: monacoEditorAPI.IStandaloneThemeData = {
31
+ const theme: monacoEditorAPI.IStandaloneThemeData = {
48
32
  base: 'vs-dark', // can also be vs-dark or hc-black
49
33
  inherit: true, // can also be false to completely replace the builtin rules
50
34
  colors: {},
51
35
  rules: [
36
+ // NOTE: unfortunately, `monaco-editor` only accepts HEX values, not CSS variables
52
37
  { token: 'package', foreground: '808080' },
53
38
  { token: 'parser-marker', foreground: 'c586c0' },
54
39
  { token: 'property', foreground: 'dcdcaa' },
55
40
  { token: 'function', foreground: 'dcdcaa' },
56
41
  { token: 'language-struct', foreground: 'c586c0' },
57
- // { token: 'multiplicity', foreground: '2d796b' },
42
+ { token: 'multiplicity', foreground: '2d796b' },
58
43
  { token: 'attribute', foreground: '9cdcfe' },
59
- { token: 'cast', foreground: 'f98a00' },
44
+ { token: 'cast', foreground: '569cd6' },
60
45
  ],
61
46
  };
62
47
 
63
48
  // Taken from `monaco-languages` configuration for Java in order to do propert brace matching
64
49
  // See https://github.com/microsoft/monaco-languages/blob/master/src/java/java.ts
65
- export const configuration: monacoLanguagesAPI.LanguageConfiguration = {
66
- // the default separators except `@$`
67
- wordPattern: /(-?\d*\.\d\w*)|([^`~!#%^&*()-=+[{]}\\\|;:'",\.<>\/\?\s]+)/g,
50
+ const configuration: monacoLanguagesAPI.LanguageConfiguration = {
68
51
  comments: {
69
52
  lineComment: '//',
70
53
  blockComment: ['/*', '*/'],
@@ -104,7 +87,7 @@ export const configuration: monacoLanguagesAPI.LanguageConfiguration = {
104
87
  * The way SQL monarch definition is organized is good and worth learning from
105
88
  * See https://github.com/microsoft/monaco-languages/blob/master/src/sql/sql.ts
106
89
  */
107
- export const generateLanguageMonarch = (
90
+ const generateLanguageMonarch = (
108
91
  extraKeywords: string[],
109
92
  extraParsers: string[],
110
93
  ): monacoLanguagesAPI.IMonarchLanguage =>
@@ -116,30 +99,47 @@ export const generateLanguageMonarch = (
116
99
 
117
100
  keywords: [
118
101
  ...extraKeywords,
102
+ // relational
103
+ 'Schema',
104
+ 'Table',
105
+ 'Join',
106
+ 'View',
107
+ 'primaryKey',
108
+ 'groupBy',
109
+ 'mainTable',
110
+ // native
111
+ 'let',
119
112
  'extends',
120
- 'function',
121
113
  'projects',
122
-
123
- GRAMMAR_ELEMENT_TYPE_LABEL.CLASS,
124
- GRAMMAR_ELEMENT_TYPE_LABEL.ASSOCIATION,
125
- GRAMMAR_ELEMENT_TYPE_LABEL.ENUMERATION,
126
- GRAMMAR_ELEMENT_TYPE_LABEL.MEASURE,
127
- GRAMMAR_ELEMENT_TYPE_LABEL.PROFILE,
128
- GRAMMAR_ELEMENT_TYPE_LABEL.FLAT_DATA,
129
- GRAMMAR_ELEMENT_TYPE_LABEL.DATABASE,
130
- GRAMMAR_ELEMENT_TYPE_LABEL.SERVICE_STORE,
131
- GRAMMAR_ELEMENT_TYPE_LABEL.MAPPING,
132
- GRAMMAR_ELEMENT_TYPE_LABEL.SERVICE,
133
- GRAMMAR_ELEMENT_TYPE_LABEL.RUNTIME,
134
- GRAMMAR_ELEMENT_TYPE_LABEL.CONNECTION,
135
- GRAMMAR_ELEMENT_TYPE_LABEL.FILE_GENERATION,
136
- GRAMMAR_ELEMENT_TYPE_LABEL.GENERATION_SPECIFICATION,
137
-
138
- GRAMMAR_ELEMENT_TYPE_LABEL.JSON_MODEL_CONNECTION,
139
- GRAMMAR_ELEMENT_TYPE_LABEL.MODEL_CHAIN_CONNECTION,
140
- GRAMMAR_ELEMENT_TYPE_LABEL.XML_MODEL_CONNECTION,
141
- GRAMMAR_ELEMENT_TYPE_LABEL.FLAT_DATA_CONNECTION,
142
- GRAMMAR_ELEMENT_TYPE_LABEL.RELATIONAL_DATABASE_CONNECTION,
114
+ // elements
115
+ PURE_ELEMENT_NAME.CLASS,
116
+ PURE_ELEMENT_NAME.ASSOCIATION,
117
+ PURE_ELEMENT_NAME.ENUMERATION,
118
+ PURE_ELEMENT_NAME.MEASURE,
119
+ PURE_ELEMENT_NAME.PROFILE,
120
+ PURE_ELEMENT_NAME.FUNCTION,
121
+ PURE_ELEMENT_NAME.FLAT_DATA,
122
+ PURE_ELEMENT_NAME.DATABASE,
123
+ PURE_ELEMENT_NAME.MAPPING,
124
+ PURE_ELEMENT_NAME.SERVICE,
125
+ PURE_ELEMENT_NAME.RUNTIME,
126
+ PURE_ELEMENT_NAME.CONNECTION,
127
+ PURE_ELEMENT_NAME.FILE_GENERATION,
128
+ PURE_ELEMENT_NAME.GENERATION_SPECIFICATION,
129
+ PURE_ELEMENT_NAME.DATA_ELEMENT,
130
+ // connections
131
+ PURE_CONNECTION_NAME.JSON_MODEL_CONNECTION,
132
+ PURE_CONNECTION_NAME.MODEL_CHAIN_CONNECTION,
133
+ PURE_CONNECTION_NAME.XML_MODEL_CONNECTION,
134
+ PURE_CONNECTION_NAME.FLAT_DATA_CONNECTION,
135
+ PURE_CONNECTION_NAME.RELATIONAL_DATABASE_CONNECTION,
136
+ // mapping
137
+ 'EnumerationMapping',
138
+ 'Pure',
139
+ 'Relational', // to be modularized
140
+ 'AssociationMapping',
141
+ 'XStore',
142
+ 'AggregationAware',
143
143
  ],
144
144
 
145
145
  operators: [
@@ -166,27 +166,32 @@ export const generateLanguageMonarch = (
166
166
  '^',
167
167
  '%',
168
168
  '->',
169
+ '#{',
170
+ '}#',
171
+ '@',
169
172
  ],
170
173
 
171
174
  languageStructs: ['import', 'native', 'if', 'fold'],
172
175
 
173
- parsers: [
174
- ...extraParsers.map((parser) => `###${parser}`),
175
- '###Pure',
176
- '###Connection',
177
- '###Runtime',
178
- '###Mapping',
179
-
180
- '###Service',
181
- '###FlatData',
182
- '###Relational',
183
- '###ServiceStore',
184
- '###GenerationSpecification',
185
- '###FileGeneration',
186
- ],
176
+ parsers: (
177
+ [
178
+ PURE_PARSER.PURE,
179
+ PURE_PARSER.CONNECTION,
180
+ PURE_PARSER.RUNTIME,
181
+ PURE_PARSER.MAPPING,
182
+ PURE_PARSER.SERVICE,
183
+ PURE_PARSER.FLATDATA,
184
+ PURE_PARSER.RELATIONAL,
185
+ PURE_PARSER.GENERATION_SPECIFICATION,
186
+ PURE_PARSER.FILE_GENERATION,
187
+ PURE_PARSER.DATA,
188
+ ] as string[]
189
+ )
190
+ .concat(extraParsers)
191
+ .map((parser) => `${PARSER_SECTION_MARKER}${parser}`),
187
192
 
188
193
  // common regular expressions to be used in tokenizer
189
- symbols: /[=><!~?:&|+\-*/^%]+/,
194
+ symbols: /[=><!~?:&|+\-*/^%#@]+/,
190
195
  escapes:
191
196
  /\\(?:[abfnrtv\\"']|x[0-9A-Fa-f]{1,4}|u[0-9A-Fa-f]{4}|U[0-9A-Fa-f]{8})/,
192
197
  digits: /\d+(_+\d+)*/,
@@ -198,10 +203,6 @@ export const generateLanguageMonarch = (
198
203
 
199
204
  tokenizer: {
200
205
  root: [
201
- // multiplicity
202
- // TODO: this as it can clash with array of numbers
203
- [/@multiplicity/, 'multiplicity'],
204
-
205
206
  // packages
206
207
  { include: '@package' },
207
208
 
@@ -213,7 +214,8 @@ export const generateLanguageMonarch = (
213
214
 
214
215
  // parser markers
215
216
  [
216
- /^###[\w]+/,
217
+ // NOTE: any leading whitespace to the section header is considered invalid syntax
218
+ /^\s*###[\w]+/,
217
219
  {
218
220
  cases: {
219
221
  '@parsers': 'parser-marker',
@@ -244,7 +246,7 @@ export const generateLanguageMonarch = (
244
246
  /@symbols/,
245
247
  {
246
248
  cases: {
247
- '@operators': 'delimiter',
249
+ '@operators': 'operator',
248
250
  '@default': '',
249
251
  },
250
252
  },
@@ -287,16 +289,16 @@ export const generateLanguageMonarch = (
287
289
  [/(@package)(\*)/, ['package', 'tag']],
288
290
  [/(@package)([\w_]+)/, ['package', 'type']],
289
291
  [
290
- /(@package)([\w_]+)(@multiplicity)/,
291
- ['package', 'type', 'multiplicity'],
292
+ /(@package)([\w_]+)(\s*)(@multiplicity)/,
293
+ ['package', 'type', '', 'multiplicity'],
292
294
  ],
293
295
  [
294
- /([\w_]+)(\s*:\s*)(@package)([\w_]+)(@multiplicity)/,
295
- ['attribute', '', 'package', 'type', 'multiplicity'],
296
+ /([\w_]+)(\s*:\s*)(@package)([\w_]+)(\s*)(@multiplicity)/,
297
+ ['attribute', '', 'package', 'type', '', 'multiplicity'],
296
298
  ],
297
299
  [
298
- /([\w_]+)(\s*:\s*)([\w_]+)(@multiplicity)/,
299
- ['attribute', '', 'type', 'multiplicity'],
300
+ /(:\s*)([\w_]+)(\s*)(@multiplicity)/,
301
+ ['', 'type', '', 'multiplicity'],
300
302
  ],
301
303
  ],
302
304
 
@@ -338,3 +340,26 @@ export const generateLanguageMonarch = (
338
340
  ],
339
341
  },
340
342
  } as monacoLanguagesAPI.IMonarchLanguage);
343
+
344
+ export const setupPureLanguageService = (
345
+ pluginManager: GraphPluginManager,
346
+ ): void => {
347
+ // register Pure language in `monaco-editor`
348
+ monacoEditorAPI.defineTheme(EDITOR_THEME.LEGEND, theme);
349
+ monacoLanguagesAPI.register({ id: EDITOR_LANGUAGE.PURE });
350
+ monacoLanguagesAPI.setLanguageConfiguration(
351
+ EDITOR_LANGUAGE.PURE,
352
+ configuration,
353
+ );
354
+ monacoLanguagesAPI.setMonarchTokensProvider(
355
+ EDITOR_LANGUAGE.PURE,
356
+ generateLanguageMonarch(
357
+ pluginManager
358
+ .getPureGraphManagerPlugins()
359
+ .flatMap((plugin) => plugin.getExtraPureGrammarKeywords?.() ?? []),
360
+ pluginManager
361
+ .getPureGraphManagerPlugins()
362
+ .flatMap((plugin) => plugin.getExtraPureGrammarParserNames?.() ?? []),
363
+ ),
364
+ );
365
+ };
package/tsconfig.json CHANGED
@@ -41,6 +41,7 @@
41
41
  "./src/stores/LambdaEditorState.ts",
42
42
  "./src/stores/LegendApplicationConfig.ts",
43
43
  "./src/stores/LegendApplicationDocumentationRegistry.ts",
44
+ "./src/stores/LegendApplicationPlugin.ts",
44
45
  "./src/stores/PackageableElementOption.ts",
45
46
  "./src/stores/PureLanguageSupport.ts",
46
47
  "./src/stores/WebApplicationNavigator.ts",