Skip to content

Commit

Permalink
Merge pull request #90 from cucumber/tsx-support
Browse files Browse the repository at this point in the history
Add support for tsx
  • Loading branch information
aslakhellesoy authored Sep 8, 2022
2 parents bb53245 + 800665b commit aea8606
Show file tree
Hide file tree
Showing 15 changed files with 144 additions and 22 deletions.
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
- Add support for `.tsx` ([#87](https://github.com/cucumber/language-service/issues/87) [#90](https://github.com/cucumber/language-service/pull/90))

## [0.32.0] - 2022-08-27
### Fixed
- Recognize parameter types using array for `regexp` ([#67](https://github.com/cucumber/language-service/issues/67), [#86](https://github.com/cucumber/language-service/pull/86))
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and [Cucumber Monaco](https://github.com/cucumber/monaco#readme).
- Languages
- [x] Java
- [x] TypeScript
- [x] TypeScript JSX (TSX)
- [x] C#
- [x] PHP
- [x] Ruby
Expand Down
116 changes: 115 additions & 1 deletion package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 6 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,24 +67,25 @@
"js-search": "2.0.0",
"mustache": "4.2.0",
"vscode-languageserver-types": "3.17.2",
"web-tree-sitter": "0.20.7"
"web-tree-sitter": "^0.20.5"
},
"optionalDependencies": {
"tree-sitter": "0.20.0",
"tree-sitter-cli": "0.20.7",
"tree-sitter-c-sharp": "0.19.1",
"tree-sitter-cli": "0.20.7",
"tree-sitter-java": "0.19.1",
"tree-sitter-php": "0.19.0",
"tree-sitter-python": "0.20.1",
"tree-sitter-ruby": "0.19.0",
"tree-sitter-typescript": "0.20.1",
"tree-sitter-python": "0.20.1"
"tree-sitter-typescript": "0.20.1"
},
"devDependencies": {
"@cucumber/cucumber": "^8.5.2",
"@cucumber/message-streams": "^4.0.1",
"@types/glob": "8.0.0",
"@types/mocha": "9.1.1",
"@types/node": "18.7.14",
"@types/react": "18.0.18",
"@typescript-eslint/eslint-plugin": "5.36.2",
"@typescript-eslint/parser": "5.36.2",
"eslint": "8.23.0",
Expand All @@ -99,6 +100,7 @@
"npm-check-updates": "16.1.0",
"prettier": "2.7.1",
"pretty-quick": "3.1.3",
"react": "18.2.0",
"ts-node": "10.9.1",
"txtgen": "3.0.2",
"typescript": "4.8.2"
Expand Down
4 changes: 2 additions & 2 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,8 @@ const languages = [
},
{
npm: 'tree-sitter-typescript',
dir: 'typescript',
wasm: 'typescript',
dir: 'tsx',
wasm: 'tsx',
},
{
npm: 'tree-sitter-c-sharp',
Expand Down
5 changes: 4 additions & 1 deletion src/language/SourceAnalyzer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,10 @@ export class SourceAnalyzer {
try {
tree = this.parse(source)
} catch (err) {
err.message += `\nuri: ${source.uri}`
err.message += `
uri: ${source.uri}
language: ${source.languageName}
`
this.errors.push(err)
continue
}
Expand Down
4 changes: 2 additions & 2 deletions src/language/languages.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@ import { javaLanguage } from './javaLanguage.js'
import { phpLanguage } from './phpLanguage.js'
import { pythonLanguage } from './pythonLanguage.js'
import { rubyLanguage } from './rubyLanguage.js'
import { tsxLanguage } from './tsxLanguage.js'
import { Language, LanguageName } from './types.js'
import { typescriptLanguage } from './typescriptLanguage.js'

const languageByName: Record<LanguageName, Language> = {
java: javaLanguage,
typescript: typescriptLanguage,
tsx: tsxLanguage,
c_sharp: csharpLanguage,
php: phpLanguage,
ruby: rubyLanguage,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { RegExps } from '@cucumber/cucumber-expressions/dist/cjs/src/ParameterTy
import { childrenToString, filter, NO_QUOTES, NO_SLASHES } from './helpers.js'
import { Language, TreeSitterSyntaxNode } from './types.js'

export const typescriptLanguage: Language = {
export const tsxLanguage: Language = {
toParameterTypeName(node) {
return childrenToString(node, NO_QUOTES)
},
Expand Down
2 changes: 1 addition & 1 deletion src/language/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export type SnippetParameters = Readonly<Record<ParameterTypeName, SnippetParame

export type ParameterTypeMeta = Readonly<{ name: string; regexp: string }>

export const LanguageNames = ['java', 'typescript', 'c_sharp', 'php', 'python', 'ruby'] as const
export const LanguageNames = ['java', 'tsx', 'c_sharp', 'php', 'python', 'ruby'] as const
export type LanguageName = typeof LanguageNames[number]

export type Source<L> = Readonly<{
Expand Down
2 changes: 1 addition & 1 deletion src/tree-sitter-node/NodeParserAdapter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class NodeParserAdapter implements ParserAdapter {
case 'java':
this.parser.setLanguage(Java)
break
case 'typescript':
case 'tsx':
this.parser.setLanguage(TypeScript.typescript)
break
case 'c_sharp':
Expand Down
7 changes: 1 addition & 6 deletions test/language/ExpressionBuilder.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,7 @@ import { NodeParserAdapter } from '../../src/tree-sitter-node/NodeParserAdapter.
import { WasmParserAdapter } from '../../src/tree-sitter-wasm/WasmParserAdapter.js'

// List languages that support Cucumber Expressions here
const cucumberExpressionsSupport: Set<LanguageName> = new Set([
'c_sharp',
'java',
'ruby',
'typescript',
])
const cucumberExpressionsSupport: Set<LanguageName> = new Set(['c_sharp', 'java', 'ruby', 'tsx'])

function defineContract(makeParserAdapter: () => ParserAdapter) {
let expressionBuilder: ExpressionBuilder
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import { Given } from '@cucumber/cucumber'
import assert from 'assert'
import React from 'react'

const dummyTsx = <span>Hello</span>

Given('a {uuid}', async function (uuid: string) {
assert(uuid)
Expand Down
4 changes: 2 additions & 2 deletions test/service/getGenerateSnippetCodeAction.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ describe('getGenerateSnippetCodeAction', () => {
'step_definitions/steps.ts',
true,
undefined,
'typescript',
'tsx',
new ParameterTypeRegistry()
)
const expectedAction: CodeAction = {
Expand Down Expand Up @@ -111,7 +111,7 @@ Given('I have {int} cukes', (int: number) => {
'step_definitions/steps.ts',
false,
undefined,
'typescript',
'tsx',
new ParameterTypeRegistry()
)
const expectedAction: CodeAction = {
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"target": "ES6",
"moduleResolution": "node",
"allowSyntheticDefaultImports": true,
"noEmit": true
"noEmit": true,
"jsx": "react"
}
}

0 comments on commit aea8606

Please sign in to comment.