Skip to content

Commit 651f796

Browse files
BurntSushiMichaReiserAlexWaygood
authored
[ty] Add some completion ranking improvements (#20807)
Co-authored-by: Micha Reiser <micha@reiser.io> Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
1 parent 4fc7dd3 commit 651f796

File tree

20 files changed

+753
-93
lines changed

20 files changed

+753
-93
lines changed

.github/workflows/ci.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -721,7 +721,7 @@ jobs:
721721
- name: "Install Rust toolchain"
722722
run: rustup show
723723
- name: "Run ty completion evaluation"
724-
run: cargo run --release --package ty_completion_eval -- all --threshold 0.1 --tasks /tmp/completion-evaluation-tasks.csv
724+
run: cargo run --release --package ty_completion_eval -- all --threshold 0.4 --tasks /tmp/completion-evaluation-tasks.csv
725725
- name: "Ensure there are no changes"
726726
run: diff ./crates/ty_completion_eval/completion-evaluation-tasks.csv /tmp/completion-evaluation-tasks.csv
727727

crates/ty_completion_eval/README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ To run a full evaluation, run the `ty_completion_eval` crate with the
77
`all` command from the root of this repository:
88

99
```console
10-
cargo run --release --package ty_completion_eval -- all
10+
cargo run --profile profiling --package ty_completion_eval -- all
1111
```
1212

1313
The output should look like this:
@@ -24,7 +24,7 @@ you can ask the evaluation to write CSV data that contains the rank of
2424
the expected answer in each completion request:
2525

2626
```console
27-
cargo r -r -p ty_completion_eval -- all --tasks ./crates/ty_completion_eval/completion-evaluation-tasks.csv
27+
cargo r --profile profiling -p ty_completion_eval -- all --tasks ./crates/ty_completion_eval/completion-evaluation-tasks.csv
2828
```
2929

3030
To debug a _specific_ task and look at the actual results, use the `show-one`
@@ -133,7 +133,7 @@ CI will also fail if the individual task results have changed.
133133
To make CI pass, you can just re-run the evaluation locally and commit the results:
134134

135135
```console
136-
cargo r -r -p ty_completion_eval -- all --tasks ./crates/ty_completion_eval/completion-evaluation-tasks.csv
136+
cargo r --profile profiling -p ty_completion_eval -- all --tasks ./crates/ty_completion_eval/completion-evaluation-tasks.csv
137137
```
138138

139139
CI fails in this case because it would be best to scrutinize the differences here.
Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,20 @@
11
name,file,index,rank
2+
fstring-completions,main.py,0,1
23
higher-level-symbols-preferred,main.py,0,
34
higher-level-symbols-preferred,main.py,1,1
4-
import-deprioritizes-dunder,main.py,0,195
5-
import-deprioritizes-sunder,main.py,0,195
6-
internal-typeshed-hidden,main.py,0,43
5+
import-deprioritizes-dunder,main.py,0,1
6+
import-deprioritizes-sunder,main.py,0,1
7+
internal-typeshed-hidden,main.py,0,4
8+
none-completion,main.py,0,11
79
numpy-array,main.py,0,
8-
numpy-array,main.py,1,32
9-
object-attr-instance-methods,main.py,0,7
10+
numpy-array,main.py,1,1
11+
object-attr-instance-methods,main.py,0,1
1012
object-attr-instance-methods,main.py,1,1
11-
raise-uses-base-exception,main.py,0,42
12-
scope-existing-over-new-import,main.py,0,495
13-
scope-prioritize-closer,main.py,0,152
14-
scope-simple-long-identifier,main.py,0,140
15-
ty-extensions-lower-stdlib,main.py,0,142
16-
type-var-typing-over-ast,main.py,0,65
17-
type-var-typing-over-ast,main.py,1,353
13+
raise-uses-base-exception,main.py,0,2
14+
scope-existing-over-new-import,main.py,0,474
15+
scope-prioritize-closer,main.py,0,2
16+
scope-simple-long-identifier,main.py,0,1
17+
tstring-completions,main.py,0,1
18+
ty-extensions-lower-stdlib,main.py,0,7
19+
type-var-typing-over-ast,main.py,0,3
20+
type-var-typing-over-ast,main.py,1,270

crates/ty_completion_eval/src/main.rs

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,9 @@ use regex::bytes::Regex;
1515
use ruff_db::files::system_path_to_file;
1616
use ruff_db::system::{OsSystem, SystemPath, SystemPathBuf};
1717
use ty_ide::Completion;
18+
use ty_project::metadata::Options;
19+
use ty_project::metadata::options::EnvironmentOptions;
20+
use ty_project::metadata::value::RelativePathBuf;
1821
use ty_project::{ProjectDatabase, ProjectMetadata};
1922
use ty_python_semantic::ModuleName;
2023

@@ -117,8 +120,8 @@ impl ShowOneCommand {
117120
&& self
118121
.file_name
119122
.as_ref()
120-
.is_some_and(|name| name == task.cursor_name())
121-
&& self.index.is_some_and(|index| index == task.cursor.index)
123+
.is_none_or(|name| name == task.cursor_name())
124+
&& self.index.is_none_or(|index| index == task.cursor.index)
122125
}
123126
}
124127

@@ -278,6 +281,14 @@ impl Task {
278281

279282
let system = OsSystem::new(project_path);
280283
let mut project_metadata = ProjectMetadata::discover(project_path, &system)?;
284+
// Explicitly point ty to the .venv to avoid any set VIRTUAL_ENV variable to take precedence.
285+
project_metadata.apply_options(Options {
286+
environment: Some(EnvironmentOptions {
287+
python: Some(RelativePathBuf::cli(".venv")),
288+
..EnvironmentOptions::default()
289+
}),
290+
..Options::default()
291+
});
281292
project_metadata.apply_configuration_files(&system)?;
282293
let db = ProjectDatabase::new(project_metadata, system)?;
283294
Ok(Task {
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
auto-import = false
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
zqzqzq_identifier = 1
2+
3+
print(f"{zqzqzq_<CURSOR: zqzqzq_identifier>}")
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
[project]
2+
name = "test"
3+
version = "0.1.0"
4+
requires-python = ">=3.13"
5+
dependencies = []

crates/ty_completion_eval/truth/fstring-completions/uv.lock

Lines changed: 8 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[settings]
2+
auto-import = false
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
x = Non<CURSOR: None>

0 commit comments

Comments
 (0)