diff --git a/pyrefly/lib/error/error.rs b/pyrefly/lib/error/error.rs index c6989c755b..63ed836883 100644 --- a/pyrefly/lib/error/error.rs +++ b/pyrefly/lib/error/error.rs @@ -14,6 +14,7 @@ use std::path::Path; use itertools::Itertools; use lsp_types::CodeDescription; use lsp_types::Diagnostic; +use lsp_types::DiagnosticTag; use lsp_types::Url; use pyrefly_python::ignore::Tool; use pyrefly_python::module::Module; @@ -199,7 +200,11 @@ impl Error { message: self.msg().to_owned(), code: Some(lsp_types::NumberOrString::String(code)), code_description, - tags: None, + tags: if self.error_kind() == ErrorKind::Deprecated { + Some(vec![DiagnosticTag::DEPRECATED]) + } else { + None + }, ..Default::default() } } diff --git a/pyrefly/lib/test/lsp/lsp_interaction/diagnostic.rs b/pyrefly/lib/test/lsp/lsp_interaction/diagnostic.rs index 3de6866812..1a646771a4 100644 --- a/pyrefly/lib/test/lsp/lsp_interaction/diagnostic.rs +++ b/pyrefly/lib/test/lsp/lsp_interaction/diagnostic.rs @@ -1672,3 +1672,54 @@ fn test_no_diagnostics_for_non_open_files_in_open_files_only_mode() { non_open_file.display() ); } + +#[test] +fn test_deprecated_diagnostic_tag() { + let test_files_root = get_test_files_root(); + let mut interaction = LspInteraction::new(); + interaction.set_root(test_files_root.path().to_path_buf()); + interaction + .initialize(InitializeSettings { + configuration: Some(None), + ..Default::default() + }) + .unwrap(); + + interaction.client.did_change_configuration(); + + interaction + .client + .expect_configuration_request(None) + .unwrap() + .send_configuration_response(json!([ + {"pyrefly": {"displayTypeErrors": "force-on"}} + ])); + + interaction.client.did_open("deprecated_function.py"); + + interaction + .client + .diagnostic("deprecated_function.py") + .expect_response(json!({ + "items": [ + { + "code": "deprecated", + "codeDescription": { + "href": "https://pyrefly.org/en/docs/error-kinds/#deprecated" + }, + "message": "`old_function` is deprecated\n use new_function instead", + "range": { + "start": {"line": 10, "character": 0}, + "end": {"line": 10, "character": 12} + }, + "severity": 2, + "source": "Pyrefly", + "tags": [2] + } + ], + "kind": "full" + })) + .unwrap(); + + interaction.shutdown().unwrap(); +} diff --git a/pyrefly/lib/test/lsp/lsp_interaction/test_files/deprecated_function.py b/pyrefly/lib/test/lsp/lsp_interaction/test_files/deprecated_function.py new file mode 100644 index 0000000000..717adc1f3a --- /dev/null +++ b/pyrefly/lib/test/lsp/lsp_interaction/test_files/deprecated_function.py @@ -0,0 +1,11 @@ +# Copyright (c) Meta Platforms, Inc. and affiliates. +# +# This source code is licensed under the MIT license found in the +# LICENSE file in the root directory of this source tree. + +from warnings import deprecated + +@deprecated("use new_function instead") +def old_function() -> None: ... + +old_function()