Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 899ba6b

Browse files
authoredSep 12, 2022
fix: only use optionalReplacementSpan if client supports InsertReplace (typescript-language-server#584)
1 parent 0960a6b commit 899ba6b

File tree

3 files changed

+28
-12
lines changed

3 files changed

+28
-12
lines changed
 

‎src/completion.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ export function asCompletionItem(entry: tsp.CompletionEntry, optionalReplacement
6363
}
6464

6565
let insertText = entry.insertText;
66-
const replacementSpan = entry.replacementSpan || optionalReplacementSpan;
66+
const replacementSpan = entry.replacementSpan || (features.completionInsertReplaceSupport ? optionalReplacementSpan : undefined);
6767
let replacementRange = replacementSpan && Range.fromTextSpan(replacementSpan);
6868
// Make sure we only replace a single line at most
6969
if (replacementRange && replacementRange.start.line !== replacementRange.end.line) {

‎src/lsp-server.spec.ts

Lines changed: 26 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ describe('completion', () => {
201201
server.didCloseTextDocument({ textDocument: doc });
202202
});
203203

204-
it('completions for clients that do not support insertReplaceSupport', async () => {
204+
it('completions for clients that support insertReplaceSupport', async () => {
205205
const doc = {
206206
uri: uri('bar.ts'),
207207
languageId: 'typescript',
@@ -221,16 +221,16 @@ describe('completion', () => {
221221
const completion = proposals!.items.find(completion => completion.label === 'getById');
222222
assert.isDefined(completion);
223223
assert.isDefined(completion!.textEdit);
224-
assert.containsAllKeys(completion!.textEdit, ['newText', 'range']);
224+
assert.containsAllKeys(completion!.textEdit, ['newText', 'insert', 'replace']);
225225
server.didCloseTextDocument({ textDocument: doc });
226226
});
227227

228-
it('completions for clients that support insertReplaceSupport', async () => {
228+
it('completions for clients that do not support insertReplaceSupport', async () => {
229229
const clientCapabilitiesOverride: lsp.ClientCapabilities = {
230230
textDocument: {
231231
completion: {
232232
completionItem: {
233-
insertReplaceSupport: true,
233+
insertReplaceSupport: false,
234234
},
235235
},
236236
},
@@ -258,8 +258,7 @@ describe('completion', () => {
258258
assert.isNotNull(proposals);
259259
const completion = proposals!.items.find(completion => completion.label === 'getById');
260260
assert.isDefined(completion);
261-
assert.isDefined(completion!.textEdit);
262-
assert.containsAllKeys(completion!.textEdit, ['newText', 'insert', 'replace']);
261+
assert.isUndefined(completion!.textEdit);
263262
localServer.didCloseTextDocument({ textDocument: doc });
264263
localServer.closeAll();
265264
localServer.shutdown();
@@ -401,7 +400,7 @@ describe('completion', () => {
401400
return true;
402401
}
403402
404-
test("fs/")
403+
test("fs/r")
405404
`,
406405
};
407406
server.didOpenTextDocument({ textDocument: doc });
@@ -417,11 +416,27 @@ describe('completion', () => {
417416
const completion = proposals!.items.find(completion => completion.label === 'fs/read');
418417
assert.strictEqual(completion!.label, 'fs/read');
419418
assert.deepStrictEqual(completion!.textEdit, {
420-
range: {
421-
start: { line: 5, character: 20 },
422-
end: { line: 5, character: 23 },
423-
},
424419
newText: 'fs/read',
420+
insert: {
421+
start: {
422+
line: 5,
423+
character: 20,
424+
},
425+
end: {
426+
line: 5,
427+
character: 23,
428+
},
429+
},
430+
replace: {
431+
start: {
432+
line: 5,
433+
character: 20,
434+
},
435+
end: {
436+
line: 5,
437+
character: 24,
438+
},
439+
},
425440
});
426441
});
427442

‎src/test-utils.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ const DEFAULT_TEST_CLIENT_CAPABILITIES: lsp.ClientCapabilities = {
2626
textDocument: {
2727
completion: {
2828
completionItem: {
29+
insertReplaceSupport: true,
2930
snippetSupport: true,
3031
labelDetailsSupport: true,
3132
},

0 commit comments

Comments
 (0)
Please sign in to comment.