Skip to content

Commit

Permalink
fix: parameter highlighting for outline steps with leading spaces (#219)
Browse files Browse the repository at this point in the history
* fix: invalid syntax highlighting for scenario outline variables

* Drop line number redeclaration

---------

Co-authored-by: Kieran Ryan <kierankilkenny@gmail.com>
  • Loading branch information
michaelboyles and kieran-ryan committed Jul 14, 2024
1 parent 92bb6eb commit 6db4a1a
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 9 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).

## [Unreleased]
### Fixed
- Parameter highlighting for scenario outline steps with leading spaces ([#219](https://github.com/cucumber/language-service/pull/219))
- (Ruby) Support `And` and `But` step definition annotations ([#211](https://github.com/cucumber/language-service/pull/211))
- (Python) Title variants of Behave's decorators (`Step`, `Given`, `When`, `Then`) ([#213](https://github.com/cucumber/language-service/pull/213))
- (PHP) Scoped query to match annotations only (`@Given`) ([#214](https://github.com/cucumber/language-service/pull/214))
Expand Down
15 changes: 6 additions & 9 deletions src/service/getGherkinSemanticTokens.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,13 @@ export function getGherkinSemanticTokens(
arr = makeLocationToken(step.location, step.keyword, SemanticTokenTypes.keyword, arr)
if (inScenarioOutline) {
const regexp = /(<[^>]+>)/g
let match: RegExpExecArray | null = null
const line = step.location.line - 1
const startOfText = lines[line].indexOf(step.text)

let match: RegExpExecArray | null
while ((match = regexp.exec(step.text)) !== null) {
const character = step.location.column - 1 + step.keyword.length + match.index
arr = makeToken(
step.location.line - 1,
character,
match[0],
SemanticTokenTypes.variable,
arr
)
const character = startOfText + match.index
arr = makeToken(line, character, match[0], SemanticTokenTypes.variable, arr)
}
} else {
for (const expression of expressions) {
Expand Down
29 changes: 29 additions & 0 deletions test/service/getGherkinSemanticTokens.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,35 @@ Feature: a
]
assert.deepStrictEqual(actual, expected)
})

it('ignores whitespace for scenario outlines', () => {
// Note that 'When' step uses two spaces, to align the text with 'Given'
const gherkinSource = `
Feature: making drinks
Scenario Outline:
Given a <ingredient>
When I make <drink>
Examples:
| ingredient | drink |
| apple | apple juice |
`
const semanticTokens = getGherkinSemanticTokens(gherkinSource, [])
const actual = tokenize(gherkinSource, semanticTokens.data)
const expected: TokenWithType[] = [
['Feature', SemanticTokenTypes.keyword],
['Scenario Outline', SemanticTokenTypes.keyword],
['Given ', SemanticTokenTypes.keyword],
['<ingredient>', SemanticTokenTypes.variable],
['When ', SemanticTokenTypes.keyword],
['<drink>', SemanticTokenTypes.variable],
['Examples', SemanticTokenTypes.keyword],
['ingredient', SemanticTokenTypes.property],
['drink', SemanticTokenTypes.property],
['apple', SemanticTokenTypes.string],
['apple juice', SemanticTokenTypes.string],
]
assert.deepStrictEqual(actual, expected)
})
})

// See https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocument_semanticTokens
Expand Down

0 comments on commit 6db4a1a

Please sign in to comment.