editor: Fix double $ sign on completion accept in PHP (#34726)
Closes #33510 https://github.com/zed-extensions/php/issues/29 If certain language servers do not provide an insert/replace range, we use `surrounding_word` as a fallback for that range, which internally uses `word_characters`. It makes sense to use `completion_query_characters` instead of `word_characters` to get that range, because we use `completion_query_characters` to query completions in the first place. That means, for some hypothetical reason (e.g., if the Tailwind server stops providing insert/replace ranges), we would correctly fall back to the range "bg-blue-200^" instead of "200^", because `completion_query_characters` includes "-" in this case. For this particular fix, right now the default PHP language server `phpactor` does not provide an insert/replace range, and hence completion query character is used, which is `$` in this case. Note that `$` isn't in word characters for reasons mentioned here: https://github.com/zed-extensions/php/issues/14 Release Notes: - Fixed an issue where accepting variable completion in PHP would result in a double $ sign in the prefix.
This commit is contained in:
parent
8bc8d61fa6
commit
1dd470ca48
3 changed files with 14 additions and 8 deletions
|
@ -350,7 +350,7 @@ impl LspCommand for PrepareRename {
|
|||
}
|
||||
Some(lsp::PrepareRenameResponse::DefaultBehavior { .. }) => {
|
||||
let snapshot = buffer.snapshot();
|
||||
let (range, _) = snapshot.surrounding_word(self.position);
|
||||
let (range, _) = snapshot.surrounding_word(self.position, false);
|
||||
let range = snapshot.anchor_after(range.start)..snapshot.anchor_before(range.end);
|
||||
Ok(PrepareRenameResponse::Success(range))
|
||||
}
|
||||
|
@ -2297,7 +2297,7 @@ impl LspCommand for GetCompletions {
|
|||
range_for_token
|
||||
.get_or_insert_with(|| {
|
||||
let offset = self.position.to_offset(&snapshot);
|
||||
let (range, kind) = snapshot.surrounding_word(offset);
|
||||
let (range, kind) = snapshot.surrounding_word(offset, true);
|
||||
let range = if kind == Some(CharKind::Word) {
|
||||
range
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue