Skip to content

Incorrect completion inside interpolated string when prefix contains Unicode characters #4180

Description

@COOLIRON2311

Description

Completion inside a Ruby interpolated string behaves incorrectly when the string prefix contains Unicode characters (e.g., emoji).
The completion inserts duplicated/garbled text instead of replacing the identifier prefix correctly.

Ruby LSP Information

VS Code Version

1.130.0

Ruby LSP Extension Version

0.10.4

Ruby LSP Server Version

0.26.9

Ruby LSP Add-ons

  • Standard Ruby (unknown)
  • Ruby LSP RSpec (0.26.9)
  • Ruby LSP Rails (0.4.8)
  • RuboCop (1.84.2)

Ruby Version

3.4.8

Ruby Version Manager

rbenv

Installed Extensions

Click to expand
  • code-spell-checker (4.5.6)
  • codesnap (1.3.4)
  • opencode (0.0.13)
  • ruby-lsp (0.10.4)
  • vscode-pgsql (1.26.0)
  • vscode-yaml (1.24.0)

Ruby LSP Settings

Click to expand
Workspace
{
  "formatter": "standard"
}
User
{
  "enabledFeatures": {
    "codeActions": true,
    "diagnostics": false,
    "documentHighlights": true,
    "documentLink": true,
    "documentSymbols": true,
    "foldingRanges": true,
    "formatting": true,
    "hover": true,
    "inlayHint": true,
    "onTypeFormatting": true,
    "selectionRanges": true,
    "semanticHighlighting": true,
    "completion": true,
    "codeLens": true,
    "definition": true,
    "workspaceSymbol": true,
    "signatureHelp": true,
    "typeHierarchy": true
  },
  "featuresConfiguration": {},
  "addonSettings": {},
  "rubyVersionManager": {
    "identifier": "auto"
  },
  "customRubyCommand": "",
  "formatter": "standard",
  "linters": null,
  "bundleGemfile": "",
  "testTimeout": 30,
  "pullDiagnosticsOn": "both",
  "useBundlerCompose": false,
  "bypassTypechecker": false,
  "rubyExecutablePath": "",
  "indexing": {},
  "erbSupport": true,
  "featureFlags": {},
  "sigOpacityLevel": "1"
}

Reproduction steps

  1. Start the Ruby LSP using Visual Studio Code

  2. Create a Ruby file

  3. Write a minimal example

    test = "moo"
    "🐮 says #{te}"
  4. Trigger completion on te and select test

Expected behavior

"🐮 says #{test}"

Actual behavior

"🐮 says #{tetest

Notice that the last " is overwritten

Notes

It looks like the replacement range/offset for completion in interpolated string content is calculated incorrectly when Unicode characters appear earlier in the same string. The same issue also occurs outside of interpolated string declarations if the source code line is prefixed with Unicode characters.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions