1
1
import {
2
2
buildSuggestions ,
3
+ CucumberExpressions ,
3
4
ExpressionBuilder ,
4
5
ExpressionBuilderResult ,
5
6
getGenerateSnippetCodeAction ,
@@ -85,18 +86,21 @@ export class CucumberLanguageServer {
85
86
private expressionBuilderResult : ExpressionBuilderResult | undefined = undefined
86
87
private reindexingTimeout : NodeJS . Timeout
87
88
private rootUri : string
88
- #suggestions: readonly Suggestion [ ]
89
- #files: Files
90
-
91
- get suggestions ( ) {
92
- return this . #suggestions
93
- }
89
+ private files : Files
90
+ public registry : CucumberExpressions . ParameterTypeRegistry
91
+ public expressions : readonly CucumberExpressions . Expression [ ] = [ ]
92
+ public suggestions : readonly Suggestion [ ] = [ ]
94
93
95
94
constructor (
96
95
private readonly connection : Connection ,
97
96
private readonly documents : TextDocuments < TextDocument > ,
98
97
parserAdapter : ParserAdapter ,
99
- private readonly makeFiles : ( rootUri : string ) => Files
98
+ private readonly makeFiles : ( rootUri : string ) => Files ,
99
+ private readonly onReindexed : (
100
+ registry : CucumberExpressions . ParameterTypeRegistry ,
101
+ expressions : readonly CucumberExpressions . Expression [ ] ,
102
+ suggestions : readonly Suggestion [ ]
103
+ ) => void
100
104
) {
101
105
this . expressionBuilder = new ExpressionBuilder ( parserAdapter )
102
106
@@ -120,7 +124,7 @@ export class CucumberLanguageServer {
120
124
} else {
121
125
connection . console . error ( `Could not determine rootPath` )
122
126
}
123
- this . # files = makeFiles ( this . rootUri )
127
+ this . files = makeFiles ( this . rootUri )
124
128
// Some users have reported that the globs don't find any files. This is to debug that issue
125
129
connection . console . info ( `Root uri : ${ this . rootUri } ` )
126
130
connection . console . info ( `Current dir : ${ process . cwd ( ) } ` )
@@ -224,8 +228,8 @@ export class CucumberLanguageServer {
224
228
return [ ]
225
229
}
226
230
const mustacheTemplate = settings . snippetTemplates [ languageName ]
227
- const createFile = ! ( await this . # files. exists ( link . targetUri ) )
228
- const relativePath = this . # files. relativePath ( link . targetUri )
231
+ const createFile = ! ( await this . files . exists ( link . targetUri ) )
232
+ const relativePath = this . files . relativePath ( link . targetUri )
229
233
const codeAction = getGenerateSnippetCodeAction (
230
234
diagnostics ,
231
235
link ,
@@ -401,7 +405,7 @@ export class CucumberLanguageServer {
401
405
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#workDoneProgress
402
406
403
407
this . connection . console . info ( `Reindexing ${ this . rootUri } ` )
404
- const gherkinSources = await loadGherkinSources ( this . # files, settings . features )
408
+ const gherkinSources = await loadGherkinSources ( this . files , settings . features )
405
409
this . connection . console . info (
406
410
`* Found ${ gherkinSources . length } feature file(s) in ${ JSON . stringify ( settings . features ) } `
407
411
)
@@ -410,7 +414,7 @@ export class CucumberLanguageServer {
410
414
[ ]
411
415
)
412
416
this . connection . console . info ( `* Found ${ stepTexts . length } steps in those feature files` )
413
- const glueSources = await loadGlueSources ( this . # files, settings . glue )
417
+ const glueSources = await loadGlueSources ( this . files , settings . glue )
414
418
this . connection . console . info (
415
419
`* Found ${ glueSources . length } glue file(s) in ${ JSON . stringify ( settings . glue ) } `
416
420
)
@@ -446,15 +450,19 @@ export class CucumberLanguageServer {
446
450
this . connection . languages . semanticTokens . refresh ( )
447
451
448
452
try {
449
- this . #suggestions = buildSuggestions (
453
+ const expressions = this . expressionBuilderResult . expressionLinks . map ( ( l ) => l . expression )
454
+ const suggestions = buildSuggestions (
450
455
this . expressionBuilderResult . registry ,
451
456
stepTexts ,
452
- this . expressionBuilderResult . expressionLinks . map ( ( l ) => l . expression )
453
- )
454
- this . connection . console . info (
455
- `* Built ${ this . #suggestions. length } suggestions for auto complete`
457
+ expressions
456
458
)
457
- this . searchIndex = jsSearchIndex ( this . #suggestions)
459
+ this . connection . console . info ( `* Built ${ suggestions . length } suggestions for auto complete` )
460
+ this . searchIndex = jsSearchIndex ( suggestions )
461
+ const registry = this . expressionBuilderResult . registry
462
+ this . registry = registry
463
+ this . expressions = expressions
464
+ this . suggestions = suggestions
465
+ this . onReindexed ( registry , expressions , suggestions )
458
466
} catch ( err ) {
459
467
this . connection . console . error ( err . stack )
460
468
this . connection . console . error (
0 commit comments