Skip to content

fix(deps-cargo): feature completion textEdit has wrong range (0,0)-(0,0) #88

@bug-ops

Description

@bug-ops

Bug Report

Component: deps-cargo (feature name auto-completion, PR #83)
Severity: P1

Description

complete_features() passes Range::default() (= position (0,0)-(0,0)) as insert_range to build_feature_completion. This creates a textEdit with an empty range at the document start. Per LSP spec, textEdit takes precedence over insertText, so a strict client would insert the feature name at the beginning of the file instead of at the cursor, corrupting the manifest.

complete_versions_generic avoids this by passing None for the range, omitting textEdit entirely and letting the client use insertText at the cursor position.

Reproduction

[dependencies]
serde = { version = "1", features = ["de"] }
  1. Place cursor at position (6, 39) — inside "de"
  2. Trigger completion
  3. Apply the default completion item

Expected: features = ["default"]
Actual: default is prepended to line 0, char 0 — corrupting the manifest

LSP trace evidence

textEdit={"newText": "default", "range": {"end": {"character": 0, "line": 0}, "start": {"character": 0, "line": 0}}}

Root cause

crates/deps-cargo/src/ecosystem.rs:79:

let insert_range = tower_lsp_server::ls_types::Range::default();

Compare with the correct pattern in complete_versions_generic:

// Don't provide text_edit range - let LSP client insert at cursor position
.map(|item| build_version_completion(item, None))

Fix

Change build_feature_completion to accept Option<Range> (like build_version_completion) and omit textEdit when range is unknown. Pass None from complete_features.

Metadata

Metadata

Assignees

Labels

P1High: wrong behavior, broken featurebugSomething isn't working

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions