-
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathindex.tsx
89 lines (77 loc) · 2.41 KB
/
index.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
import { ParameterTypeRegistry } from '@cucumber/cucumber-expressions'
import {
buildSuggestions,
ExpressionBuilder,
jsSearchIndex,
LanguageName,
Source,
} from '@cucumber/language-service'
import { WasmParserAdapter } from '@cucumber/language-service/wasm'
import * as monaco from 'monaco-editor/esm/vs/editor/editor.api'
import React from 'react'
import { createRoot } from 'react-dom/client'
import { ConfigureEditor, configureMonaco } from '../src/index.js'
import { MonacoEditor } from './MonacoEditor.js'
async function makeConfigureEditor(): Promise<ConfigureEditor> {
monaco.languages.register({ id: 'typescript' })
const adapter = new WasmParserAdapter('.')
await adapter.init()
const expressionBuilder = new ExpressionBuilder(adapter)
const sources: Source<LanguageName>[] = [
{
languageName: 'java',
uri: 'file:///tmp/StepDefinitions.java',
content: `class StepDefinitions {
@Given("I have {int} cukes in my belly" )
void method1() {
}
@Given("there are {int} blind mice")
void method2() {
}
@Given("there is/are some/none/1 apple(s)")
void method2() {
}
}
`,
},
]
const { expressionLinks, errors } = expressionBuilder.build(sources, [])
for (const error of errors) {
console.error(error)
}
const expressions = expressionLinks.map((link) => link.expression)
const registry = new ParameterTypeRegistry()
const docs = buildSuggestions(
registry,
['I have 42 cukes in my belly', 'I have 96 cukes in my belly', 'there are 38 blind mice'],
expressions
)
const index = jsSearchIndex(docs)
return configureMonaco(monaco, index, expressions)
}
const value = `@foo
Feature: Hello
Scenario: Hi
Given I have 58 cukes in my belly
And this is an undefined step
| some | poorly |
| formatted | table |
`
const options = {
value,
language: 'gherkin',
theme: 'vs-dark',
// semantic tokens provider is disabled by default
'semanticHighlighting.enabled': true,
}
const javascriptEditor = document.getElementById('editor1')
const reactEditor = document.getElementById('editor2')
makeConfigureEditor()
.then((configureEditor) => {
// @ts-ignore
configureEditor(monaco.editor.create(javascriptEditor, options))
// @ts-ignore
const root = createRoot(reactEditor)
root.render(<MonacoEditor options={options} className="editor" configure={configureEditor} />)
})
.catch((err) => console.error(err.stack))