Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

### Fixed
- User's `snippetTemplates` config is ignored
- Default `glue` globs miss `.cjs`, `.mjs`, `.cts` and `.mts` files
- Glue and feature files not found when root is not the current directory

## [1.7.0] - 2025-05-18
### Changed
Expand Down
4 changes: 4 additions & 0 deletions src/CucumberLanguageServer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,8 +61,12 @@ const defaultSettings: Settings = {
'src/test/**/*.java',
// Cucumber-Js
'features/**/*.ts',
'features/**/*.cts',
'features/**/*.mts',
'features/**/*.tsx',
'features/**/*.js',
'features/**/*.cjs',
'features/**/*.mjs',
'features/**/*.jsx',
// Behat
'features/**/*.php',
Expand Down
7 changes: 6 additions & 1 deletion src/node/NodeFiles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,12 @@ export class NodeFiles implements Files {

async findUris(glob: string): Promise<readonly string[]> {
const cwd = url.fileURLToPath(this.rootUri)
const paths = await fg(glob, { cwd, caseSensitiveMatch: false, onlyFiles: true })
const paths = await fg(glob, {
cwd,
absolute: true,
caseSensitiveMatch: false,
onlyFiles: true,
})
return paths.map((path) => url.pathToFileURL(path).href)
}

Expand Down
52 changes: 49 additions & 3 deletions test/CucumberLanguageServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
createProtocolConnection,
DidChangeConfigurationNotification,
type DidChangeConfigurationParams,
InitializedNotification,
type InitializeParams,
InitializeRequest,
InsertTextFormat,
Expand All @@ -27,6 +28,7 @@ import { NodeFiles } from '../src/node/NodeFiles.js'
import type { Settings } from '../src/types.js'

describe('CucumberLanguageServer', () => {
let rootPath = process.cwd()
let inputStream: Duplex
let outputStream: Duplex
let clientConnection: ProtocolConnection
Expand All @@ -49,7 +51,7 @@ describe('CucumberLanguageServer', () => {
serverConnection.listen()

const initializeParams: InitializeParams = {
rootUri: `file://${process.cwd()}`,
rootUri: `file://${rootPath}`,
processId: NaN, // This id is used by vscode-languageserver. Set as NaN so that the watchdog responsible for watching this process does not run.
capabilities: {
workspace: {
Expand Down Expand Up @@ -126,8 +128,8 @@ describe('CucumberLanguageServer', () => {
// Note that *pushing* settings from the client to the server is deprecated in the LSP. We're only using it
// here because it's easier to implement in the test.
const settings: Settings = {
features: ['testdata/**/*.feature'],
glue: [`testdata/**/*.${fileExtension}`],
features: ['testdata/gherkin/*.feature'],
glue: [`testdata/{javascript,typescript}/*.${fileExtension}`],
parameterTypes: [],
snippetTemplates: {},
}
Expand Down Expand Up @@ -193,6 +195,50 @@ describe('CucumberLanguageServer', () => {
assert.deepStrictEqual(completionItems, expected)
})
}

context('with default settings', () => {
before(() => {
rootPath = `${process.cwd()}/testdata/default-globs`
})

after(() => {
rootPath = process.cwd()
})

it('finds glue in module-specific JavaScript and TypeScript files', async () => {
await clientConnection.sendNotification(InitializedNotification.type, {})

// TODO: Wait for a WorkDoneProgressEnd notification instead
await new Promise((resolve) => setTimeout(resolve, 1000))

documents.get = () =>
TextDocument.create(
'testdoc',
'gherkin',
1,
`Feature: Hello
Scenario: World
Given I have
`
)
const completionItems = (await clientConnection.sendRequest(CompletionRequest.type, {
textDocument: {
uri: 'features/test.feature',
},
position: {
line: 2,
character: 16,
},
})) as CompletionItem[]

assert.deepStrictEqual(completionItems.map((item) => item.label).sort(), [
'I have {int} cjs cukes',
'I have {int} cts cukes',
'I have {int} mjs cukes',
'I have {int} mts cukes',
])
})
})
})
})

Expand Down
3 changes: 3 additions & 0 deletions testdata/default-globs/features/steps/stepdefs.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Given } from '@cucumber/cucumber'

Given('I have {int} cjs cukes', () => undefined)
3 changes: 3 additions & 0 deletions testdata/default-globs/features/steps/stepdefs.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Given } from '@cucumber/cucumber'

Given('I have {int} cts cukes', () => undefined)
3 changes: 3 additions & 0 deletions testdata/default-globs/features/steps/stepdefs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Given } from '@cucumber/cucumber'

Given('I have {int} mjs cukes', () => undefined)
3 changes: 3 additions & 0 deletions testdata/default-globs/features/steps/stepdefs.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { Given } from '@cucumber/cucumber'

Given('I have {int} mts cukes', () => undefined)
Loading