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

Fix an exception in diagnostics #217

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
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
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
- (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))
- Exception thrown for unterminated docstrings ([#216](https://github.com/cucumber/language-service/pull/216))

## [1.6.0] - 2024-05-12
### Added
Expand Down
9 changes: 7 additions & 2 deletions src/service/getGherkinDiagnostics.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,13 @@ export function getGherkinDiagnostics(
error instanceof Errors.CompositeParserException ? error.errors : error ? [error] : []
for (const error of errors) {
if (error instanceof Errors.GherkinException) {
const line = error.location.line - 1
const character = error.location.column !== undefined ? error.location.column - 1 : 0
let line = error.location.line - 1
let character = error.location.column !== undefined ? error.location.column - 1 : 0
if (line >= lines.length) {
// EOF issue, e.g. something is not properly terminated
line = lines.length - 1
character = lines[line].length
}
const diagnostic: Diagnostic = {
severity: DiagnosticSeverity.Error,
range: {
Expand Down
28 changes: 28 additions & 0 deletions test/service/getGherkinDiagnostics.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,4 +203,32 @@ describe('getGherkinDiagnostics', () => {
const expectedDiagnostics: Diagnostic[] = []
assert.deepStrictEqual(diagnostics, expectedDiagnostics)
})

it('returns diagnostic for incomplete docstring', () => {
const diagnostics = getGherkinDiagnostics(
`Feature: Hello
Scenario: Hi
Given a defined step
"""`,
[new CucumberExpression('a defined step', new ParameterTypeRegistry())]
)
const expectedDiagnostics: Diagnostic[] = [
{
message: '(5:0): unexpected end of file, expected: #DocStringSeparator, #Other',
range: {
start: {
line: 3,
character: 9,
},
end: {
line: 3,
character: 9,
},
},
severity: DiagnosticSeverity.Error,
source: 'Cucumber',
},
]
assert.deepStrictEqual(diagnostics, expectedDiagnostics)
})
})