editor: Fix TypeScript auto-import breaking generic function calls (#30312)
Closes #29982 When auto-importing TypeScript functions with generic type arguments (like `useRef<HTMLDivElement>(null)`), the language server returns snippets with placeholders (e.g., `useRef(${1:initialValue})$0`). While useful for new function calls, this behavior breaks existing code when renaming functions that already have parameters. For example, completing `useR^<HTMLDivElement>(null)` incorrectly results in `useRef(initialValue)^<HTMLDivElement>(null)`. Related upstream issue: https://github.com/microsoft/TypeScript/issues/51758 Similar workaround fix: https://github.com/pmizio/typescript-tools.nvim/pull/147 Release Notes: - Fixed TypeScript auto-import behavior where functions with generic type arguments (like `useRef<HTMLDivElement>(null)`) would incorrectly insert snippet placeholders, breaking the syntax.
This commit is contained in:
@@ -5187,15 +5187,25 @@ impl ProjectItem for Buffer {
|
||||
}
|
||||
|
||||
impl Completion {
|
||||
pub fn kind(&self) -> Option<CompletionItemKind> {
|
||||
self.source
|
||||
// `lsp::CompletionListItemDefaults` has no `kind` field
|
||||
.lsp_completion(false)
|
||||
.and_then(|lsp_completion| lsp_completion.kind)
|
||||
}
|
||||
|
||||
pub fn label(&self) -> Option<String> {
|
||||
self.source
|
||||
.lsp_completion(false)
|
||||
.map(|lsp_completion| lsp_completion.label.clone())
|
||||
}
|
||||
|
||||
/// A key that can be used to sort completions when displaying
|
||||
/// them to the user.
|
||||
pub fn sort_key(&self) -> (usize, &str) {
|
||||
const DEFAULT_KIND_KEY: usize = 3;
|
||||
let kind_key = self
|
||||
.source
|
||||
// `lsp::CompletionListItemDefaults` has no `kind` field
|
||||
.lsp_completion(false)
|
||||
.and_then(|lsp_completion| lsp_completion.kind)
|
||||
.kind()
|
||||
.and_then(|lsp_completion_kind| match lsp_completion_kind {
|
||||
lsp::CompletionItemKind::KEYWORD => Some(0),
|
||||
lsp::CompletionItemKind::VARIABLE => Some(1),
|
||||
|
||||
Reference in New Issue
Block a user