Skip to content

Commit 8076f31

Browse files
asukaminato0721meta-codesync[bot]
authored andcommitted
fix [feature] treat deprecated functions differently in the IDE #716 (#1512)
Summary: fix #716 Introduced a completion post-processing tweak so any item carrying CompletionItemTag::DEPRECATED now receives a heavier sort_text, which pushes deprecated suggestions beneath non-deprecated ones while still keeping existing prioritization rules for auto-imports and private symbols intact. Pull Request resolved: #1512 Reviewed By: stroxler Differential Revision: D86419461 Pulled By: kinto0 fbshipit-source-id: be60ab209b87791ebd612c8e6bf49f3943f797df
1 parent 8a3945c commit 8076f31

File tree

2 files changed

+42
-3
lines changed

2 files changed

+42
-3
lines changed

pyrefly/lib/state/lsp.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2458,7 +2458,13 @@ impl<'a> Transaction<'a> {
24582458
}
24592459
}
24602460
for item in &mut result {
2461-
let sort_text = if item.additional_text_edits.is_some() {
2461+
let sort_text = if item
2462+
.tags
2463+
.as_ref()
2464+
.is_some_and(|tags| tags.contains(&CompletionItemTag::DEPRECATED))
2465+
{
2466+
"9"
2467+
} else if item.additional_text_edits.is_some() {
24622468
"4"
24632469
} else if item.label.starts_with("__") {
24642470
"3"

pyrefly/lib/test/lsp/completion.rs

Lines changed: 35 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -172,9 +172,42 @@ foo.
172172
11 | foo.
173173
^
174174
Completion Results:
175+
- (Field) x: int
175176
- (Field) [DEPRECATED] also_not_ok: int
176177
- (Method) [DEPRECATED] not_ok: def not_ok(self: Foo) -> None: ...
177-
- (Field) x: int
178+
"#
179+
.trim(),
180+
report.trim(),
181+
);
182+
}
183+
184+
#[test]
185+
fn completion_deprecated_top_level_function() {
186+
let code = r#"
187+
from typing import *
188+
from warnings import deprecated
189+
190+
@deprecated("this is deprecated")
191+
def test1() -> None:
192+
...
193+
194+
def test2() -> None:
195+
...
196+
197+
te
198+
# ^
199+
"#;
200+
let report =
201+
get_batched_lsp_operations_report_allow_error(&[("main", code)], get_default_test_report());
202+
assert_eq!(
203+
r#"
204+
# main.py
205+
12 | te
206+
^
207+
Completion Results:
208+
- (Class) deprecated: type[deprecated]
209+
- (Function) test2: () -> None
210+
- (Function) [DEPRECATED] test1: () -> None
178211
"#
179212
.trim(),
180213
report.trim(),
@@ -543,7 +576,6 @@ Completion Results:
543576
^
544577
Completion Results:
545578
- (Variable) deprecated
546-
- (Variable) [DEPRECATED] func_not_ok
547579
- (Variable) func_ok
548580
- (Variable) __annotations__
549581
- (Variable) __builtins__
@@ -557,6 +589,7 @@ Completion Results:
557589
- (Variable) __package__
558590
- (Variable) __path__
559591
- (Variable) __spec__
592+
- (Variable) [DEPRECATED] func_not_ok
560593
561594
562595
# foo.py

0 commit comments

Comments
 (0)