From 45f64b97088d06d59515ec70cade7b0f7d0bbba3 Mon Sep 17 00:00:00 2001 From: Adithya Haridas <34602379+surc54@users.noreply.github.com> Date: Wed, 19 Jul 2023 18:21:00 -0400 Subject: [PATCH 1/5] Support cjs/mjs/cts/mts glue extensions --- src/fs.ts | 4 +- test/CucumberLanguageServer.test.ts | 127 +++++++++++++++------------- testdata/typescript/stepdefs.cts | 4 + testdata/typescript/stepdefs.mts | 4 + 4 files changed, 77 insertions(+), 62 deletions(-) create mode 100644 testdata/typescript/stepdefs.cts create mode 100644 testdata/typescript/stepdefs.mts diff --git a/src/fs.ts b/src/fs.ts index 4da0ad24..63405cad 100644 --- a/src/fs.ts +++ b/src/fs.ts @@ -3,8 +3,8 @@ import { LanguageName, Source } from '@cucumber/language-service' import { extname, Files } from './Files.js' export const glueExtByLanguageName: Record = { - javascript: ['.js', '.jsx'], - tsx: ['.ts', '.tsx'], + javascript: ['.js', '.cjs', '.mjs', '.jsx'], + tsx: ['.ts', '.cts', '.mts', '.tsx'], java: ['.java'], c_sharp: ['.cs'], php: ['.php'], diff --git a/test/CucumberLanguageServer.test.ts b/test/CucumberLanguageServer.test.ts index e92deb7a..947a5f2d 100644 --- a/test/CucumberLanguageServer.test.ts +++ b/test/CucumberLanguageServer.test.ts @@ -109,73 +109,80 @@ 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 typescriptFileExtensions = ['ts', 'cts', 'mts'] + + typescriptFileExtensions.forEach((fileExtension) => + it(`returns completion items for *.${fileExtension} typescript 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) + }) + ) }) }) diff --git a/testdata/typescript/stepdefs.cts b/testdata/typescript/stepdefs.cts new file mode 100644 index 00000000..bd9a4fb9 --- /dev/null +++ b/testdata/typescript/stepdefs.cts @@ -0,0 +1,4 @@ +import { Given } from '@cucumber/cucumber' +import assert from 'assert' + +Given('I have {int} cukes', (count: number) => assert(count)) diff --git a/testdata/typescript/stepdefs.mts b/testdata/typescript/stepdefs.mts new file mode 100644 index 00000000..bd9a4fb9 --- /dev/null +++ b/testdata/typescript/stepdefs.mts @@ -0,0 +1,4 @@ +import { Given } from '@cucumber/cucumber' +import assert from 'assert' + +Given('I have {int} cukes', (count: number) => assert(count)) From 3fc243e0bc725685d8de4d40bc50de47ad3b09cc Mon Sep 17 00:00:00 2001 From: Adithya Haridas <34602379+surc54@users.noreply.github.com> Date: Sat, 22 Jul 2023 14:38:49 +0000 Subject: [PATCH 2/5] Add tests for javascript glue files --- test/CucumberLanguageServer.test.ts | 18 ++++++++++++++---- testdata/javascript/stepdefs.cjs | 4 ++++ testdata/javascript/stepdefs.js | 4 ++++ testdata/javascript/stepdefs.mjs | 4 ++++ 4 files changed, 26 insertions(+), 4 deletions(-) create mode 100644 testdata/javascript/stepdefs.cjs create mode 100644 testdata/javascript/stepdefs.js create mode 100644 testdata/javascript/stepdefs.mjs diff --git a/test/CucumberLanguageServer.test.ts b/test/CucumberLanguageServer.test.ts index 947a5f2d..0ba396af 100644 --- a/test/CucumberLanguageServer.test.ts +++ b/test/CucumberLanguageServer.test.ts @@ -109,10 +109,20 @@ describe('CucumberLanguageServer', () => { }) context('textDocument/completion', () => { - const typescriptFileExtensions = ['ts', 'cts', 'mts'] - - typescriptFileExtensions.forEach((fileExtension) => - it(`returns completion items for *.${fileExtension} typescript files`, async () => { + 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. diff --git a/testdata/javascript/stepdefs.cjs b/testdata/javascript/stepdefs.cjs new file mode 100644 index 00000000..f7a80303 --- /dev/null +++ b/testdata/javascript/stepdefs.cjs @@ -0,0 +1,4 @@ +import { Given } from '@cucumber/cucumber' +import assert from 'assert' + +Given('I have {int} cukes', (count) => assert(count)) diff --git a/testdata/javascript/stepdefs.js b/testdata/javascript/stepdefs.js new file mode 100644 index 00000000..f7a80303 --- /dev/null +++ b/testdata/javascript/stepdefs.js @@ -0,0 +1,4 @@ +import { Given } from '@cucumber/cucumber' +import assert from 'assert' + +Given('I have {int} cukes', (count) => assert(count)) diff --git a/testdata/javascript/stepdefs.mjs b/testdata/javascript/stepdefs.mjs new file mode 100644 index 00000000..f7a80303 --- /dev/null +++ b/testdata/javascript/stepdefs.mjs @@ -0,0 +1,4 @@ +import { Given } from '@cucumber/cucumber' +import assert from 'assert' + +Given('I have {int} cukes', (count) => assert(count)) From 491c0bdaf5c6c51725df59d8fb60bab9433281a8 Mon Sep 17 00:00:00 2001 From: Adithya Haridas <34602379+surc54@users.noreply.github.com> Date: Sat, 22 Jul 2023 20:17:21 +0000 Subject: [PATCH 3/5] Update changelog --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 153a9a28..ebee9a0d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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) From 58d0705f25400e474883b8085a2c49ced4ed3882 Mon Sep 17 00:00:00 2001 From: Adithya Haridas <34602379+surc54@users.noreply.github.com> Date: Thu, 10 Aug 2023 20:07:29 -0400 Subject: [PATCH 4/5] Attempt to fix test crash by changing processId to string --- test/CucumberLanguageServer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CucumberLanguageServer.test.ts b/test/CucumberLanguageServer.test.ts index 0ba396af..f4c14f1c 100644 --- a/test/CucumberLanguageServer.test.ts +++ b/test/CucumberLanguageServer.test.ts @@ -50,7 +50,7 @@ describe('CucumberLanguageServer', () => { const initializeParams: InitializeParams = { rootUri: `file://${process.cwd()}`, - processId: 1, + processId: 'N/A' as unknown as number, // This id is used by vscode-languageserver. Forcing this to be a string so that the watchdog responsible for watching this process does not run. capabilities: { workspace: { configuration: true, From 658f17727e32807f2a82dce89eed6bfb614315d0 Mon Sep 17 00:00:00 2001 From: Adithya Haridas <34602379+surc54@users.noreply.github.com> Date: Thu, 10 Aug 2023 20:57:15 -0400 Subject: [PATCH 5/5] Prefer NaN instead of string for test crash fix --- test/CucumberLanguageServer.test.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/CucumberLanguageServer.test.ts b/test/CucumberLanguageServer.test.ts index f4c14f1c..fec2e4fd 100644 --- a/test/CucumberLanguageServer.test.ts +++ b/test/CucumberLanguageServer.test.ts @@ -50,7 +50,7 @@ describe('CucumberLanguageServer', () => { const initializeParams: InitializeParams = { rootUri: `file://${process.cwd()}`, - processId: 'N/A' as unknown as number, // This id is used by vscode-languageserver. Forcing this to be a string so that the watchdog responsible for watching this process does not run. + 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,