Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support cjs/mjs/cts/mts glue extensions #85

Merged
merged 5 commits into from
Aug 11, 2023
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]

### Added
- Allow Javascript/Typescript glue files with the following file extensions: cjs, mjs, cts, mts - [#85](https://github.com/cucumber/language-server/pull/85)

## [1.4.0] - 2022-12-08
### Added
- Added support for JavaScript - [#42](https://github.com/cucumber/language-service/issues/42), [#115](https://github.com/cucumber/language-service/pull/115), [#120](https://github.com/cucumber/language-service/pull/120)
Expand Down
4 changes: 2 additions & 2 deletions src/fs.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@ import { LanguageName, Source } from '@cucumber/language-service'
import { extname, Files } from './Files.js'

export const glueExtByLanguageName: Record<LanguageName, string[]> = {
javascript: ['.js', '.jsx'],
tsx: ['.ts', '.tsx'],
javascript: ['.js', '.cjs', '.mjs', '.jsx'],
tsx: ['.ts', '.cts', '.mts', '.tsx'],
java: ['.java'],
c_sharp: ['.cs'],
php: ['.php'],
Expand Down
139 changes: 78 additions & 61 deletions test/CucumberLanguageServer.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ describe('CucumberLanguageServer', () => {

const initializeParams: InitializeParams = {
rootUri: `file://${process.cwd()}`,
processId: 1,
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: {
configuration: true,
Expand Down Expand Up @@ -109,73 +109,90 @@ describe('CucumberLanguageServer', () => {
})

context('textDocument/completion', () => {
it('returns completion items for typescript', async () => {
// First we need to configure the server, telling it where to find Gherkin documents and Glue code.
// 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/**/*.ts'],
parameterTypes: [],
snippetTemplates: {},
}
const configParams: DidChangeConfigurationParams = {
settings,
}
await clientConnection.sendNotification(DidChangeConfigurationNotification.type, configParams)

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

// Create a document for auto completion
documents.get = () =>
TextDocument.create(
'testdoc',
'gherkin',
1,
`Feature: Hello
const fileExtensions = [
// Javascript
'js',
'cjs',
'mjs',

// Typescript
'ts',
'cts',
'mts',
]

fileExtensions.forEach((fileExtension) =>
it(`returns completion items for *.${fileExtension} files`, async () => {
// First we need to configure the server, telling it where to find Gherkin documents and Glue code.
// 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}`],
parameterTypes: [],
snippetTemplates: {},
}
const configParams: DidChangeConfigurationParams = {
settings,
}
await clientConnection.sendNotification(
DidChangeConfigurationNotification.type,
configParams
)

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

// Create a document for auto completion
documents.get = () =>
TextDocument.create(
'testdoc',
'gherkin',
1,
`Feature: Hello
Scenario: World
Given I have
`
)
const completionParams: CompletionParams = {
textDocument: {
uri: 'features/test.feature',
},
position: {
line: 2, // The step line
character: 16, // End of the step line
},
}
const completionItems = await clientConnection.sendRequest(
CompletionRequest.type,
completionParams
)
const completionParams: CompletionParams = {
textDocument: {
uri: 'features/test.feature',
},
position: {
line: 2, // The step line
character: 16, // End of the step line
},
}
const completionItems = await clientConnection.sendRequest(
CompletionRequest.type,
completionParams
)
const expected: CompletionItem[] = [
{
label: 'I have {int} cukes',
filterText: 'I have',
sortText: '1000',
insertTextFormat: InsertTextFormat.Snippet,
kind: CompletionItemKind.Text,
labelDetails: {},
textEdit: {
newText: 'I have ${1|5,8|} cukes',
range: {
start: {
line: 2,
character: 10,
},
end: {
line: 2,
character: 16,
const expected: CompletionItem[] = [
{
label: 'I have {int} cukes',
filterText: 'I have',
sortText: '1000',
insertTextFormat: InsertTextFormat.Snippet,
kind: CompletionItemKind.Text,
labelDetails: {},
textEdit: {
newText: 'I have ${1|5,8|} cukes',
range: {
start: {
line: 2,
character: 10,
},
end: {
line: 2,
character: 16,
},
},
},
},
},
]
assert.deepStrictEqual(completionItems, expected)
})
]
assert.deepStrictEqual(completionItems, expected)
})
)
})
})

Expand Down
4 changes: 4 additions & 0 deletions testdata/javascript/stepdefs.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Given } from '@cucumber/cucumber'
import assert from 'assert'

Given('I have {int} cukes', (count) => assert(count))
4 changes: 4 additions & 0 deletions testdata/javascript/stepdefs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Given } from '@cucumber/cucumber'
import assert from 'assert'

Given('I have {int} cukes', (count) => assert(count))
4 changes: 4 additions & 0 deletions testdata/javascript/stepdefs.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Given } from '@cucumber/cucumber'
import assert from 'assert'

Given('I have {int} cukes', (count) => assert(count))
4 changes: 4 additions & 0 deletions testdata/typescript/stepdefs.cts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Given } from '@cucumber/cucumber'
import assert from 'assert'

Given('I have {int} cukes', (count: number) => assert(count))
4 changes: 4 additions & 0 deletions testdata/typescript/stepdefs.mts
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
import { Given } from '@cucumber/cucumber'
import assert from 'assert'

Given('I have {int} cukes', (count: number) => assert(count))