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

An initial go at Python Support #69

Merged
merged 10 commits into from
Jul 14, 2022
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 .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@ storybook-static
# stryker temp files
.stryker-tmp
reports
# python
.python-version
.mypy-cache
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Added
- Basic Python Support via behave ([#69](https://github.com/cucumber/language-service/pull/69))

## [0.30.0] - 2022-06-13
### Fixed
Expand Down
30 changes: 27 additions & 3 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ See [cucumber/vscode/CONTRIBUTING.md](https://github.com/cucumber/vscode/blob/ma

If your contribution is to add support for a new programming language, follow these steps:

0. Read and understand tree-sitter. It's job is to query the source code of whatever language you are trying to add support for. By doing this we can find the specific functions or methods that correspond to that language's Cucumber support. This allows the `language-service` to abstract away the language specific components and allows the rest of the program to work in more universal Gherkin space.
1. Run `npm install -E tree-sitter-{language}`
2. Update `languages` in `scripts/build.js`
2. Update `languages` in `scripts/build.js` and add it to [cucumber/vscode/README.md](https://github.com/cucumber/vscode/blob/main/README.md).
3. Run `npm install` - this should build a wasm for the new language into `dist/{language}.wasm`
4. Add the following files, porting the names and expressions from one of the existing implementations:
- `test/language/testdata/{language}/ParameterTypes.{ext}` (if the Cucumber implementation supports [Cucumber Expressions](https://github.com/cucumber/cucumber-expressions#readme))
Expand All @@ -31,14 +32,37 @@ If your contribution is to add support for a new programming language, follow th
6. Add the name of the new language to the `LanguageName` type
7. Update `languageByName` in `src/language/language.ts`
8. Update `src/tree-sitter-node/NodeParserAdapter.ts`
9. Run tests
9. Update `test/language/ExpressionBuilder.test.ts` to include the new language if it supports Cucumber Expressions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍🏻

10. Run tests

As you are working on step 4 and 5 - use [tree-sitter playground](https://tree-sitter.github.io/tree-sitter/playground)
to build your query. The queries must have [capturing nodes](https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax):
to build your query. The queries _must have_ [capturing nodes](https://tree-sitter.github.io/tree-sitter/using-parsers#query-syntax):

- `defineParameterTypeQueries`: `@expression`, `@name` and `@root`
- `defineStepDefinitionQueries`: `@expression` and `@root`

Changing the names of these aliases will result in test failures, even if they work within the tree-sitter playground.

## Snippets

mrkaiser marked this conversation as resolved.
Show resolved Hide resolved
Languages _should_ (Should as in, will not merge but could technically work) contain a snippet in their respective `src/language/{language}Language.ts`.

Below is the canonical Ruby example:

```
{{ keyword }}('{{ expression }}') do |{{ #parameters }}{{ #seenParameter }}, {{ /seenParameter }}{{ name }}{{ /parameters }}|
// {{ blurb }}
end
```

This is a [Mustache Template](https://mustache.github.io/). Here is the [documentation](https://mustache.github.io/mustache.5.html)

Here there are a number of parameters to use:
`keyword` this your languages Given, When, Then
`expression` this the cucumber expression to associate with the given step definition
`blurb` this is the default place holder blurb for developer
`parameters` and `seenParameter` are the parameters used for development (i.e for Ruby the use of the word date for the parameter in the expression)

## One last thing

Please make sure all code is formatted before submitting a pull request
Expand Down
Loading