Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 38 additions & 1 deletion crates/ty_ide/src/code_action.rs
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,10 @@ mod tests {
use ruff_diagnostics::Fix;
use ruff_text_size::{TextRange, TextSize};
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]
fn add_ignore() {
Expand Down Expand Up @@ -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) db: ty_project::TestDb,
pub(super) file: File,
Expand Down
36 changes: 0 additions & 36 deletions crates/ty_server/tests/e2e/code_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,42 +158,6 @@ x: Literal[1] = 1
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`
#[test]
fn code_action_undefined_decorator() -> Result<()> {
Expand Down

This file was deleted.

Loading