mirror of https://github.com/astral-sh/ruff
[ty] Fix reveal-type E2E test (#21865)
This commit is contained in:
parent
11901384b4
commit
a0b18bc153
|
|
@ -86,7 +86,10 @@ mod tests {
|
||||||
use ruff_diagnostics::Fix;
|
use ruff_diagnostics::Fix;
|
||||||
use ruff_text_size::{TextRange, TextSize};
|
use ruff_text_size::{TextRange, TextSize};
|
||||||
use ty_project::ProjectMetadata;
|
use ty_project::ProjectMetadata;
|
||||||
use ty_python_semantic::{lint::LintMetadata, types::UNRESOLVED_REFERENCE};
|
use ty_python_semantic::{
|
||||||
|
lint::LintMetadata,
|
||||||
|
types::{UNDEFINED_REVEAL, UNRESOLVED_REFERENCE},
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn add_ignore() {
|
fn add_ignore() {
|
||||||
|
|
@ -441,6 +444,40 @@ mod tests {
|
||||||
"#);
|
"#);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn undefined_reveal_type() {
|
||||||
|
let test = CodeActionTest::with_source(
|
||||||
|
r#"
|
||||||
|
<START>reveal_type<END>(1)
|
||||||
|
"#,
|
||||||
|
);
|
||||||
|
|
||||||
|
assert_snapshot!(test.code_actions(&UNDEFINED_REVEAL), @r"
|
||||||
|
info[code-action]: import typing.reveal_type
|
||||||
|
--> main.py:2:13
|
||||||
|
|
|
||||||
|
2 | reveal_type(1)
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
help: This is a preferred code action
|
||||||
|
1 + from typing import reveal_type
|
||||||
|
2 |
|
||||||
|
3 | reveal_type(1)
|
||||||
|
4 |
|
||||||
|
|
||||||
|
info[code-action]: Ignore 'undefined-reveal' for this line
|
||||||
|
--> main.py:2:13
|
||||||
|
|
|
||||||
|
2 | reveal_type(1)
|
||||||
|
| ^^^^^^^^^^^
|
||||||
|
|
|
||||||
|
1 |
|
||||||
|
- reveal_type(1)
|
||||||
|
2 + reveal_type(1) # ty:ignore[undefined-reveal]
|
||||||
|
3 |
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
pub(super) struct CodeActionTest {
|
pub(super) struct CodeActionTest {
|
||||||
pub(super) db: ty_project::TestDb,
|
pub(super) db: ty_project::TestDb,
|
||||||
pub(super) file: File,
|
pub(super) file: File,
|
||||||
|
|
|
||||||
|
|
@ -158,42 +158,6 @@ x: Literal[1] = 1
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
// `Literal` is available from two places so we should suggest two possible imports
|
|
||||||
#[test]
|
|
||||||
fn code_action_undefined_reveal_type() -> Result<()> {
|
|
||||||
let workspace_root = SystemPath::new("src");
|
|
||||||
let foo = SystemPath::new("src/foo.py");
|
|
||||||
let foo_content = "\
|
|
||||||
reveal_type(1)
|
|
||||||
";
|
|
||||||
|
|
||||||
let ty_toml = SystemPath::new("ty.toml");
|
|
||||||
let ty_toml_content = "";
|
|
||||||
|
|
||||||
let mut server = TestServerBuilder::new()?
|
|
||||||
.with_workspace(workspace_root, None)?
|
|
||||||
.with_file(ty_toml, ty_toml_content)?
|
|
||||||
.with_file(foo, foo_content)?
|
|
||||||
.enable_pull_diagnostics(true)
|
|
||||||
.build()
|
|
||||||
.wait_until_workspaces_are_initialized();
|
|
||||||
|
|
||||||
server.open_text_document(foo, foo_content, 1);
|
|
||||||
|
|
||||||
// Wait for diagnostics to be computed.
|
|
||||||
let diagnostics = server.document_diagnostic_request(foo, None);
|
|
||||||
let range = full_range(foo_content);
|
|
||||||
let code_action_params = code_actions_at(&server, diagnostics, foo, range);
|
|
||||||
|
|
||||||
// Get code actions
|
|
||||||
let code_action_id = server.send_request::<CodeActionRequest>(code_action_params);
|
|
||||||
let code_actions = server.await_response::<CodeActionRequest>(&code_action_id);
|
|
||||||
|
|
||||||
insta::assert_json_snapshot!(code_actions);
|
|
||||||
|
|
||||||
Ok(())
|
|
||||||
}
|
|
||||||
|
|
||||||
// Using an unimported decorator `@deprecated`
|
// Using an unimported decorator `@deprecated`
|
||||||
#[test]
|
#[test]
|
||||||
fn code_action_undefined_decorator() -> Result<()> {
|
fn code_action_undefined_decorator() -> Result<()> {
|
||||||
|
|
|
||||||
|
|
@ -1,98 +0,0 @@
|
||||||
---
|
|
||||||
source: crates/ty_server/tests/e2e/code_actions.rs
|
|
||||||
expression: code_actions
|
|
||||||
---
|
|
||||||
[
|
|
||||||
{
|
|
||||||
"title": "import typing.reveal_type",
|
|
||||||
"kind": "quickfix",
|
|
||||||
"diagnostics": [
|
|
||||||
{
|
|
||||||
"range": {
|
|
||||||
"start": {
|
|
||||||
"line": 0,
|
|
||||||
"character": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 0,
|
|
||||||
"character": 11
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"severity": 2,
|
|
||||||
"code": "undefined-reveal",
|
|
||||||
"codeDescription": {
|
|
||||||
"href": "https://ty.dev/rules#undefined-reveal"
|
|
||||||
},
|
|
||||||
"source": "ty",
|
|
||||||
"message": "`reveal_type` used without importing it",
|
|
||||||
"relatedInformation": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"edit": {
|
|
||||||
"changes": {
|
|
||||||
"file://<temp_dir>/src/foo.py": [
|
|
||||||
{
|
|
||||||
"range": {
|
|
||||||
"start": {
|
|
||||||
"line": 0,
|
|
||||||
"character": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 0,
|
|
||||||
"character": 0
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"newText": "from typing import reveal_type\n"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"isPreferred": true
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"title": "Ignore 'undefined-reveal' for this line",
|
|
||||||
"kind": "quickfix",
|
|
||||||
"diagnostics": [
|
|
||||||
{
|
|
||||||
"range": {
|
|
||||||
"start": {
|
|
||||||
"line": 0,
|
|
||||||
"character": 0
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 0,
|
|
||||||
"character": 11
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"severity": 2,
|
|
||||||
"code": "undefined-reveal",
|
|
||||||
"codeDescription": {
|
|
||||||
"href": "https://ty.dev/rules#undefined-reveal"
|
|
||||||
},
|
|
||||||
"source": "ty",
|
|
||||||
"message": "`reveal_type` used without importing it",
|
|
||||||
"relatedInformation": []
|
|
||||||
}
|
|
||||||
],
|
|
||||||
"edit": {
|
|
||||||
"changes": {
|
|
||||||
"file://<temp_dir>/src/foo.py": [
|
|
||||||
{
|
|
||||||
"range": {
|
|
||||||
"start": {
|
|
||||||
"line": 0,
|
|
||||||
"character": 14
|
|
||||||
},
|
|
||||||
"end": {
|
|
||||||
"line": 0,
|
|
||||||
"character": 14
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"newText": " # ty:ignore[undefined-reveal]"
|
|
||||||
}
|
|
||||||
]
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"isPreferred": false
|
|
||||||
}
|
|
||||||
]
|
|
||||||
Loading…
Reference in New Issue