Skip to content

Don’t require fourslash completions tests to specify replacementSpan when it’s zero-length #42013

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

Merged
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
12 changes: 7 additions & 5 deletions src/harness/fourslashImpl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -907,11 +907,13 @@ namespace FourSlash {
this.raiseError(`Expected completion insert text to be ${expected.insertText}, got ${actual.insertText}`);
}
const convertedReplacementSpan = expected.replacementSpan && ts.createTextSpanFromRange(expected.replacementSpan);
try {
assert.deepEqual(actual.replacementSpan, convertedReplacementSpan);
}
catch {
this.raiseError(`Expected completion replacementSpan to be ${stringify(convertedReplacementSpan)}, got ${stringify(actual.replacementSpan)}`);
if (convertedReplacementSpan?.length) {
try {
assert.deepEqual(actual.replacementSpan, convertedReplacementSpan);
}
catch {
this.raiseError(`Expected completion replacementSpan to be ${stringify(convertedReplacementSpan)}, got ${stringify(actual.replacementSpan)}`);
}
}

if (expected.kind !== undefined || expected.kindModifiers !== undefined) {
Expand Down
7 changes: 2 additions & 5 deletions tests/cases/fourslash/completionsWithGenericStringLiteral.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@
// @strict: true

//// declare function get<T, K extends keyof T>(obj: T, key: K): T[K];
//// get({ hello: 123, world: 456 }, "[|/**/|]");
//// get({ hello: 123, world: 456 }, "/**/");

verify.completions({
marker: "",
includes: [
{ name: 'hello', replacementSpan: test.ranges()[0] },
{ name: 'world', replacementSpan: test.ranges()[0] }
]
includes: ["hello", "world"]
});