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

Backslashes in DataTable messes with highlighting #124

Open
maave0 opened this issue Dec 13, 2022 · 1 comment
Open

Backslashes in DataTable messes with highlighting #124

maave0 opened this issue Dec 13, 2022 · 1 comment
Labels
πŸ› bug Defect / Bug

Comments

@maave0
Copy link

maave0 commented Dec 13, 2022

πŸ‘“ What did you see?

I made a .feature file that included a DataTable and Examples table. Some lines had the last several characters uncolored - The lines that had backslashes in them.

image

βœ… What did you expect to see?

All the text inside the pipe formatting is colored.

πŸ“¦ Which tool/library version are you using?

Cucumber extension v1.7.0 for VSCode installed on VS Code v1.74.0

πŸ”¬ How could we reproduce it?

Steps to reproduce the behavior:

  1. Install Cucumber extension v1.7 onto VS Code v.1.74.0
  2. Create a file called 'whatever.feature'
  3. Write a scenario that includes either DataTable or Examples table
  4. Put numerous backslashes inside the table's text

Example:

@BugReport
Feature: BugReport

Scenario: DEID117 Success
    Given I submit a bug report

    And I put backslashes in a DataTable or Examples table
    | this line works fine |
    | C:\\Users\\this line won't highlight the last 2 characters |
    | I see it with escaped newlines and escaped backslashes. ( \n \n \n \n  ) will produce 4 uncolored characters|

    Then Cucumber team fixes the highlighting :)
@aslakhellesoy aslakhellesoy transferred this issue from cucumber/vscode Jan 5, 2023
@kieran-ryan kieran-ryan added the πŸ› bug Defect / Bug label Dec 10, 2023
@kieran-ryan
Copy link
Member

Thanks for catching this issue! Capturing some notes in case someone is in a position to take a look.

What's happening is the gherkin is being read and parsed as strings; and as they are escaped when evaluating their length, they are being incorrectly calculated as shorter than their full unescaped length. Thus, the syntax highlighting is not fully applied.

function makeToken(
lineNumber: number,
character: number,
token: string,
type: SemanticTokenTypes,
data: readonly number[]
) {
const charDelta = lineNumber === lastLineNumber ? character - lastCharacter : character
lastCharacter = character
const lineOffset = lineNumber - lastLineNumber
lastLineNumber = lineNumber
const length = token.length
const typeIndex = indexByType[type]
return data.concat([lineOffset, charDelta, length, typeIndex, 0])
}

There is also an issue where when parsing we may lose information e.g. \ and \\ may both evaluate to \\.

Text Token Length Expected Length
valu\e valu\\e 6 6
valu\\e valu\\e 6 7

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
πŸ› bug Defect / Bug
Projects
None yet
Development

No branches or pull requests

2 participants