Skip to content

[regression] Incorrect cursor position after nested completion using $0 placeholder #152837

@HighCommander4

Description

@HighCommander4

Notes

  • This is a regression introduced in vscode 1.67 (also affects 1.68 and insiders)
  • The reproduction steps require a language server that produces completion items using the $0 placeholder. The example steps use clangd

Steps to reproduce

(See also screen recordings below)

  1. Install the clangd C++ language server
  2. Start with the following C++ source file:
void moo(int, int);

int main() {
  
}
  1. On line 4, type mo and invoke completion.
  2. Accept the completion item for moo.
  3. Type decl and invoke completion
  4. Accept the completion item for decltype(expression)

Expected results

The cursor ends up at column 26, i.e. just before the closing ) of the inserted decltype(expression).

This is what happens with vscode 1.66:

good

Actual results

The cursor ends up at column 27, i.e. just after the closing ) of the inserted decltype(expression)

This is what happens with vscode 1.67 and later:

bad

Analysis

The bug seems to hinge on the second completion item containing a $0 placeholder -- in this case, the item's insertText is decltype(${0:expression}). If this is changed to decltype(${1:expression}), the bug goes away.

The interpretation of the $0 placeholder is explained in the LSP spec here: https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#insertTextFormat

Originally reported at clangd/clangd#1190.

Metadata

Metadata

Assignees

Labels

info-neededIssue requires more information from postersnippets

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions