Skip to content

Commit b34ea18

Browse files
committed
Release 0.18.0
1 parent 31c8199 commit b34ea18

7 files changed

Lines changed: 52 additions & 13 deletions

File tree

CHANGELOG.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
77

88
## [Unreleased]
99

10+
## [0.18.0] - 2022-05-10
11+
### Changed
12+
- Autocomlete suggestions now set `filterText` to prevent VSCode from filtering out suggestions
13+
- Autocomlete suggestions now set `sortText` to display suggestions from undefined steps last
14+
1015
## [0.17.0] - 2022-05-09
1116
### Added
1217
- Ruby support ([#44](https://github.com/cucumber/language-service/pull/44))
@@ -141,7 +146,8 @@ and this project adheres to [Semantic Versioning](http://semver.org/).
141146
([#1732](https://github.com/cucumber/common/pull/1732)
142147
[aslakhellesoy](https://github.com/aslakhellesoy))
143148

144-
[Unreleased]: https://github.com/cucumber/language-service/compare/v0.17.0...HEAD
149+
[Unreleased]: https://github.com/cucumber/language-service/compare/v0.18.0...HEAD
150+
[0.18.0]: https://github.com/cucumber/language-service/compare/v0.17.0...v0.18.0
145151
[0.17.0]: https://github.com/cucumber/language-service/compare/v0.16.0...v0.17.0
146152
[0.16.0]: https://github.com/cucumber/language-service/compare/v0.15.0...v0.16.0
147153
[0.15.0]: https://github.com/cucumber/language-service/compare/v0.14.4...v0.15.0

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "@cucumber/language-service",
3-
"version": "0.17.0",
3+
"version": "0.18.0",
44
"description": "Cucumber Language Service",
55
"type": "module",
66
"main": "dist/cjs/src/index.js",

src/index/fuseIndex.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export function fuseIndex(suggestions: readonly Suggestion[]): Index {
2121
threshold: 0.1,
2222
ignoreLocation: true,
2323
fieldNormWeight: 1,
24+
shouldSort: true,
2425
})
2526

2627
return (text) => {
Lines changed: 23 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,10 @@
11
import { walkGherkinDocument } from '@cucumber/gherkin-utils'
2-
import { CompletionItem, CompletionItemKind, InsertTextFormat } from 'vscode-languageserver-types'
2+
import {
3+
CompletionItem,
4+
CompletionItemKind,
5+
InsertTextFormat,
6+
Position,
7+
} from 'vscode-languageserver-types'
38

49
import { parseGherkinDocument } from '../gherkin/parseGherkinDocument.js'
510
import { Index } from '../index/index.js'
@@ -8,7 +13,7 @@ import { lspCompletionSnippet } from './snippet/lspCompletionSnippet.js'
813
// https://microsoft.github.io/language-server-protocol/specifications/specification-3-17/#textDocument_completion
914
export function getGherkinCompletionItems(
1015
gherkinSource: string,
11-
line: number,
16+
position: Position,
1217
index: Index
1318
): readonly CompletionItem[] {
1419
const { gherkinDocument } = parseGherkinDocument(gherkinSource)
@@ -20,7 +25,7 @@ export function getGherkinCompletionItems(
2025
let endCharacter: number
2126
walkGherkinDocument(gherkinDocument, undefined, {
2227
step(step) {
23-
if (step.location.line === line + 1 && step.location.column !== undefined) {
28+
if (step.location.line === position.line + 1 && step.location.column !== undefined) {
2429
text = step.text
2530
startCharacter = step.location.column + step.keyword.length - 1
2631
endCharacter = startCharacter + text.length
@@ -29,28 +34,40 @@ export function getGherkinCompletionItems(
2934
})
3035
if (text === undefined) return []
3136
const suggestions = index(text)
32-
return suggestions.map((suggestion) => {
37+
// https://github.com/microsoft/language-server-protocol/issues/898#issuecomment-593968008
38+
return suggestions.map((suggestion, i) => {
39+
// The index has already sorted the syggestions by match score.
40+
// We're moving suggestions that are from undefined steps to the bottom
41+
const sortText = (suggestion.matched ? i + 1000 : i + 2000).toString()
3342
const item: CompletionItem = {
3443
label: suggestion.label,
3544
insertTextFormat: InsertTextFormat.Snippet,
3645
kind: CompletionItemKind.Text,
3746
labelDetails: {
3847
...(suggestion.matched ? {} : { detail: ' (undefined step)' }),
3948
},
49+
// VSCode will only display suggestions that literally match the label.
50+
// We're overriding this behaviour by setting filterText to what the user has typed,
51+
// so that the suggestions are always displayed
52+
filterText: text,
53+
sortText,
4054
textEdit: {
4155
newText: lspCompletionSnippet(suggestion.segments),
4256
range: {
4357
start: {
44-
line,
58+
line: position.line,
4559
character: startCharacter,
4660
},
4761
end: {
48-
line,
62+
line: position.line,
4963
character: endCharacter,
5064
},
5165
},
5266
},
5367
}
68+
const { label } = item
69+
console.log({ label, sortText })
70+
console.log()
5471
return item
5572
})
5673
}

test/index/Index.test.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,15 @@ function verifyIndexContract(name: string, buildIndex: BuildIndex) {
1919
segments: ['I am a teapot'],
2020
matched: true,
2121
}
22+
23+
const s3: Suggestion = {
24+
label: '{word} can do it',
25+
segments: [['You', 'They'], 'can do it'],
26+
matched: true,
27+
}
2228
let index: Index
2329
beforeEach(() => {
24-
index = buildIndex([s1, s2])
30+
index = buildIndex([s1, s2, s3])
2531
})
2632

2733
it('matches two words in the beginning of an expression', () => {
@@ -39,6 +45,11 @@ function verifyIndexContract(name: string, buildIndex: BuildIndex) {
3945
assert.deepStrictEqual(suggestions, [s1])
4046
})
4147

48+
it('matches another word in a choice', () => {
49+
const suggestions = index('They')
50+
assert.deepStrictEqual(suggestions, [s3])
51+
})
52+
4253
it('matches nothing', () => {
4354
const suggestions = index('nope')
4455
assert.deepStrictEqual(suggestions, [])

test/service/getGherkinCompletionItems.test.ts

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,15 @@ describe('getGherkinCompletionItems', () => {
2323
Scenario: World
2424
Given cukes
2525
`
26-
const completions = getGherkinCompletionItems(gherkinSource, 2, index)
26+
const completions = getGherkinCompletionItems(gherkinSource, { line: 2, character: 15 }, index)
2727
const expectedCompletions: CompletionItem[] = [
2828
{
2929
label: 'I have {int} cukes in my belly',
3030
insertTextFormat: InsertTextFormat.Snippet,
3131
kind: CompletionItemKind.Text,
3232
labelDetails: {},
33+
filterText: 'cukes',
34+
sortText: '1000',
3335
textEdit: {
3436
newText: 'I have ${1|42,98|} cukes in my belly',
3537
range: {
@@ -65,7 +67,7 @@ describe('getGherkinCompletionItems', () => {
6567
Scenario: World
6668
Given teapot
6769
`
68-
const completions = getGherkinCompletionItems(gherkinSource, 2, index)
70+
const completions = getGherkinCompletionItems(gherkinSource, { line: 2, character: 16 }, index)
6971
const expectedCompletions: CompletionItem[] = [
7072
{
7173
label: 'I am a teapot',
@@ -74,6 +76,8 @@ describe('getGherkinCompletionItems', () => {
7476
labelDetails: {
7577
detail: ' (undefined step)',
7678
},
79+
filterText: 'teapot',
80+
sortText: '2000',
7781
textEdit: {
7882
newText: 'I am a teapot',
7983
range: {

0 commit comments

Comments
 (0)