Skip to content

Commit 95b3823

Browse files
Merge pull request #73 from cucumber/blockly2
Expose registry and expressions
2 parents 2b8efd3 + 8817a66 commit 95b3823

15 files changed

+214
-132
lines changed

bin/cucumber-language-server.cjs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,19 @@
11
#!/usr/bin/env node
22
/* eslint-disable @typescript-eslint/no-var-requires */
33
require('source-map-support').install()
4-
const { startWasmServer } = require('../dist/cjs/src/wasm/startWasmServer')
4+
const { startStandaloneServer } = require('../dist/cjs/src/wasm/startStandaloneServer')
55
const { NodeFiles } = require('../dist/cjs/src/node/NodeFiles')
66
const url = require('url')
7+
const { version } = require('../src/version')
8+
79
const wasmBaseUrl = url.pathToFileURL(
810
`${__dirname}/../node_modules/@cucumber/language-service/dist`
911
)
10-
startWasmServer(wasmBaseUrl.href, (rootUri) => new NodeFiles(rootUri))
12+
const { connection } = startStandaloneServer(wasmBaseUrl.href, (rootUri) => new NodeFiles(rootUri))
13+
14+
// Don't die on unhandled Promise rejections
15+
process.on('unhandledRejection', (reason, p) => {
16+
connection.console.error(
17+
`Cucumber Language Server ${version}: Unhandled Rejection at promise: ${p}, reason: ${reason}`
18+
)
19+
})

package-lock.json

Lines changed: 109 additions & 34 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,8 @@
8686
"vscode-languageserver-protocol": "3.17.2"
8787
},
8888
"dependencies": {
89-
"@cucumber/gherkin-utils": "^8.0.1",
90-
"@cucumber/language-service": "^1.2.0",
89+
"@cucumber/gherkin-utils": "^8.0.2",
90+
"@cucumber/language-service": "^1.3.0",
9191
"fast-glob": "3.2.12",
9292
"source-map-support": "0.5.21",
9393
"vscode-languageserver": "8.0.2",

src/CucumberLanguageServer.ts

Lines changed: 26 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import {
22
buildSuggestions,
3+
CucumberExpressions,
34
ExpressionBuilder,
45
ExpressionBuilderResult,
56
getGenerateSnippetCodeAction,
@@ -85,18 +86,21 @@ export class CucumberLanguageServer {
8586
private expressionBuilderResult: ExpressionBuilderResult | undefined = undefined
8687
private reindexingTimeout: NodeJS.Timeout
8788
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[] = []
9493

9594
constructor(
9695
private readonly connection: Connection,
9796
private readonly documents: TextDocuments<TextDocument>,
9897
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
100104
) {
101105
this.expressionBuilder = new ExpressionBuilder(parserAdapter)
102106

@@ -120,7 +124,7 @@ export class CucumberLanguageServer {
120124
} else {
121125
connection.console.error(`Could not determine rootPath`)
122126
}
123-
this.#files = makeFiles(this.rootUri)
127+
this.files = makeFiles(this.rootUri)
124128
// Some users have reported that the globs don't find any files. This is to debug that issue
125129
connection.console.info(`Root uri : ${this.rootUri}`)
126130
connection.console.info(`Current dir : ${process.cwd()}`)
@@ -224,8 +228,8 @@ export class CucumberLanguageServer {
224228
return []
225229
}
226230
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)
229233
const codeAction = getGenerateSnippetCodeAction(
230234
diagnostics,
231235
link,
@@ -401,7 +405,7 @@ export class CucumberLanguageServer {
401405
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#workDoneProgress
402406

403407
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)
405409
this.connection.console.info(
406410
`* Found ${gherkinSources.length} feature file(s) in ${JSON.stringify(settings.features)}`
407411
)
@@ -410,7 +414,7 @@ export class CucumberLanguageServer {
410414
[]
411415
)
412416
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)
414418
this.connection.console.info(
415419
`* Found ${glueSources.length} glue file(s) in ${JSON.stringify(settings.glue)}`
416420
)
@@ -446,15 +450,19 @@ export class CucumberLanguageServer {
446450
this.connection.languages.semanticTokens.refresh()
447451

448452
try {
449-
this.#suggestions = buildSuggestions(
453+
const expressions = this.expressionBuilderResult.expressionLinks.map((l) => l.expression)
454+
const suggestions = buildSuggestions(
450455
this.expressionBuilderResult.registry,
451456
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
456458
)
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)
458466
} catch (err) {
459467
this.connection.console.error(err.stack)
460468
this.connection.console.error(

src/index.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1+
export * from './CucumberLanguageServer.js'
12
export * from './Files.js'
2-
export * from './newWasmServer.js'
3-
export * from './startServer.js'
3+
export { CucumberExpressions, Suggestion } from '@cucumber/language-service'

0 commit comments

Comments
 (0)