-
-
Notifications
You must be signed in to change notification settings - Fork 689
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cucumber language server, VSCode extension and Monaco editor (#1689)
* More LSP work * More LSP/VSCode work * Write dry run messages * Extract LSP server * Fix test * Prettier * Add vscode extension * More vscode * Update index automatically * warnings for undefined steps * Fix CI * Start implementing semantic tokens. Refactor to lsp lib. * Implement semantic tokens * Hightlight parameters * Fix build * highlight docstrings * Refactor makeToken * Highlight tables * Semantic tokens for tagds * highlight <placeholders> * Refactor * Ignore Scenario Outline steps * Refactor * Misc improvements * Handle parse errors * tweak colours * Initialize index and expressions * Extract new @cucumber/language-service library * Misc updates * Add Monaco plugin * Build docs * Improve diagnostics * Documentation * Add dummy test
- Loading branch information
1 parent
46d058f
commit 3c3eaa9
Showing
144 changed files
with
11,708 additions
and
5,917 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ acceptance/ | |
storybook-static | ||
*-go | ||
*.iml | ||
.vscode-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ acceptance/ | |
storybook-static | ||
*-go | ||
*.iml | ||
.vscode-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ acceptance/ | |
storybook-static | ||
*-go | ||
*.iml | ||
.vscode-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ acceptance/ | |
storybook-static | ||
*-go | ||
*.iml | ||
.vscode-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ acceptance/ | |
storybook-static | ||
*-go | ||
*.iml | ||
.vscode-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ acceptance/ | |
storybook-static | ||
*-go | ||
*.iml | ||
.vscode-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,3 +16,4 @@ acceptance/ | |
storybook-static | ||
*-go | ||
*.iml | ||
.vscode-test |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
import * as messages from '@cucumber/messages' | ||
|
||
export type GherkinDocumentHandlers<Acc> = { | ||
feature: (feature: messages.Feature, acc: Acc) => Acc | ||
background: (backgrounf: messages.Background, acc: Acc) => Acc | ||
rule: (rule: messages.Rule, acc: Acc) => Acc | ||
scenario: (scenario: messages.Scenario, acc: Acc) => Acc | ||
step: (step: messages.Step, acc: Acc) => Acc | ||
examples: (examples: messages.Examples, acc: Acc) => Acc | ||
tag: (tag: messages.Tag, acc: Acc) => Acc | ||
comment: (comment: messages.Comment, acc: Acc) => Acc | ||
dataTable: (dataTable: messages.DataTable, acc: Acc) => Acc | ||
tableRow: (tableRow: messages.TableRow, acc: Acc) => Acc | ||
tableCell: (tableCell: messages.TableCell, acc: Acc) => Acc | ||
docString: (docString: messages.DocString, acc: Acc) => Acc | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,137 @@ | ||
import * as messages from '@cucumber/messages' | ||
import { GherkinDocumentHandlers } from './GherkinDocumentHandlers' | ||
|
||
/** | ||
* Walks a Gherkin Document, visiting each node depth first (in the order they appear in the source) | ||
* | ||
* @param gherkinDocument | ||
* @param initialValue the initial value of the traversal | ||
* @param handlers handlers for each node type, which may return a new value | ||
* @return result the final value | ||
*/ | ||
export function walkGherkinDocument<Acc>( | ||
gherkinDocument: messages.GherkinDocument, | ||
initialValue: Acc, | ||
handlers: Partial<GherkinDocumentHandlers<Acc>> | ||
): Acc { | ||
let acc = initialValue | ||
const h: GherkinDocumentHandlers<Acc> = { ...makeDefaultHandlers<Acc>(), ...handlers } | ||
const feature = gherkinDocument.feature | ||
if (!feature) return acc | ||
acc = walkTags(feature.tags || [], acc) | ||
acc = h.feature(feature, acc) | ||
|
||
for (const child of feature.children) { | ||
if (child.background) { | ||
acc = walkStepContainer(child.background, acc) | ||
} else if (child.scenario) { | ||
acc = walkStepContainer(child.scenario, acc) | ||
} else if (child.rule) { | ||
acc = walkTags(child.rule.tags || [], acc) | ||
acc = h.rule(child.rule, acc) | ||
for (const ruleChild of child.rule.children) { | ||
if (ruleChild.background) { | ||
acc = walkStepContainer(ruleChild.background, acc) | ||
} else if (ruleChild.scenario) { | ||
acc = walkStepContainer(ruleChild.scenario, acc) | ||
} | ||
} | ||
} | ||
} | ||
return acc | ||
|
||
function walkTags(tags: readonly messages.Tag[], acc: Acc): Acc { | ||
return tags.reduce((acc, tag) => h.tag(tag, acc), acc) | ||
} | ||
|
||
function walkSteps(steps: readonly messages.Step[], acc: Acc): Acc { | ||
return steps.reduce((acc, step) => walkStep(step, acc), acc) | ||
} | ||
|
||
function walkStep(step: messages.Step, acc: Acc): Acc { | ||
acc = h.step(step, acc) | ||
if (step.docString) { | ||
acc = h.docString(step.docString, acc) | ||
} | ||
if (step.dataTable) { | ||
acc = h.dataTable(step.dataTable, acc) | ||
acc = walkTableRows(step.dataTable.rows, acc) | ||
} | ||
return acc | ||
} | ||
|
||
function walkTableRows(tableRows: readonly messages.TableRow[], acc: Acc): Acc { | ||
return tableRows.reduce((acc, tableRow) => walkTableRow(tableRow, acc), acc) | ||
} | ||
|
||
function walkTableRow(tableRow: messages.TableRow, acc: Acc): Acc { | ||
acc = h.tableRow(tableRow, acc) | ||
return tableRow.cells.reduce((acc, tableCell) => h.tableCell(tableCell, acc), acc) | ||
} | ||
|
||
function walkStepContainer( | ||
stepContainer: messages.Scenario | messages.Background, | ||
acc: Acc | ||
): Acc { | ||
const scenario: messages.Scenario = 'tags' in stepContainer ? stepContainer : null | ||
acc = walkTags(scenario?.tags || [], acc) | ||
acc = scenario | ||
? h.scenario(scenario, acc) | ||
: h.background(stepContainer as messages.Background, acc) | ||
acc = walkSteps(stepContainer.steps, acc) | ||
|
||
if (scenario) { | ||
for (const examples of scenario.examples || []) { | ||
acc = walkTags(examples.tags || [], acc) | ||
acc = h.examples(examples, acc) | ||
if (examples.tableHeader) { | ||
acc = walkTableRow(examples.tableHeader, acc) | ||
acc = walkTableRows(examples.tableBody || [], acc) | ||
} | ||
} | ||
} | ||
return acc | ||
} | ||
} | ||
|
||
function makeDefaultHandlers<Acc>() { | ||
const defaultHandlers: GherkinDocumentHandlers<Acc> = { | ||
feature(feature, acc) { | ||
return acc | ||
}, | ||
background(background, acc) { | ||
return acc | ||
}, | ||
rule(rule, acc) { | ||
return acc | ||
}, | ||
scenario(scenario, acc) { | ||
return acc | ||
}, | ||
step(step, acc) { | ||
return acc | ||
}, | ||
examples(examples, acc) { | ||
return acc | ||
}, | ||
tag(tag, acc) { | ||
return acc | ||
}, | ||
comment(comment, acc) { | ||
return acc | ||
}, | ||
dataTable(dataTable, acc) { | ||
return acc | ||
}, | ||
tableRow(tableRow, acc) { | ||
return acc | ||
}, | ||
tableCell(tableCell, acc) { | ||
return acc | ||
}, | ||
docString(docString, acc) { | ||
return acc | ||
}, | ||
} | ||
return defaultHandlers | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.