From f14e01964271849d1efe87dd311d29556efe9bb9 Mon Sep 17 00:00:00 2001 From: ascandone Date: Sun, 8 Sep 2024 14:24:01 +0200 Subject: [PATCH] testing inlay hints snapshot with default config --- compiler-core/src/language_server/tests.rs | 11 +---- .../src/language_server/tests/inlay_hints.rs | 42 ++++++++++++++++++- ...y_hints__do_not_show_hints_by_default.snap | 5 +++ 3 files changed, 48 insertions(+), 10 deletions(-) create mode 100644 compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__inlay_hints__do_not_show_hints_by_default.snap diff --git a/compiler-core/src/language_server/tests.rs b/compiler-core/src/language_server/tests.rs index 4f1d4abff35..e14f27664d9 100644 --- a/compiler-core/src/language_server/tests.rs +++ b/compiler-core/src/language_server/tests.rs @@ -7,7 +7,7 @@ mod hover; mod inlay_hints; mod signature_help; -use super::configuration::{Configuration, InlayHintsConfig}; +use super::configuration::Configuration; use crate::{ config::PackageConfig, io::{ @@ -354,13 +354,6 @@ fn add_path_dep(engine: &mut LanguageServerEngine, n ) } -/// For testing purposes, turn all the flags on -fn default_test_config() -> Configuration { - Configuration { - inlay_hints: InlayHintsConfig { pipelines: true }, - } -} - fn setup_engine( io: &LanguageServerTestIO, ) -> LanguageServerEngine { @@ -371,7 +364,7 @@ fn setup_engine( io.clone(), FileSystemProxy::new(io.clone()), io.paths.clone(), - Arc::new(RwLock::new(default_test_config())), + Arc::new(RwLock::new(Configuration::default())), ) .unwrap() } diff --git a/compiler-core/src/language_server/tests/inlay_hints.rs b/compiler-core/src/language_server/tests/inlay_hints.rs index 377d857dd4d..b0562eb52d1 100644 --- a/compiler-core/src/language_server/tests/inlay_hints.rs +++ b/compiler-core/src/language_server/tests/inlay_hints.rs @@ -1,4 +1,7 @@ -use crate::language_server::tests::{setup_engine, LanguageServerTestIO}; +use crate::language_server::{ + configuration::{Configuration, InlayHintsConfig}, + tests::{setup_engine, LanguageServerTestIO}, +}; use lsp_types::{InlayHintParams, Position, Range}; #[test] @@ -137,9 +140,46 @@ fn hints_in_use() { insta::assert_snapshot!(hints); } +#[test] +fn do_not_show_hints_by_default() { + let src = r#" + const int_val = 0 + + fn identity(x) { + x + } + + fn ret_str(_x) { + "abc" + } + + pub fn example_pipe() { + int_val + |> ret_str() + |> identity() + } + "#; + + let hints = inlay_hints_for_config(src, Configuration::default()); + insta::assert_snapshot!(hints); +} + fn inlay_hints(src: &str) -> String { + inlay_hints_for_config( + src, + Configuration { + inlay_hints: InlayHintsConfig { pipelines: true }, + }, + ) +} + +fn inlay_hints_for_config(src: &str, user_config: Configuration) -> String { let io = LanguageServerTestIO::new(); let mut engine = setup_engine(&io); + { + let mut config = engine.user_config.write().expect("cannot write config"); + *config = user_config; + } _ = io.src_module("app", src); let response = engine.compile_please(); diff --git a/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__inlay_hints__do_not_show_hints_by_default.snap b/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__inlay_hints__do_not_show_hints_by_default.snap new file mode 100644 index 00000000000..0aa0353f9aa --- /dev/null +++ b/compiler-core/src/language_server/tests/snapshots/gleam_core__language_server__tests__inlay_hints__do_not_show_hints_by_default.snap @@ -0,0 +1,5 @@ +--- +source: compiler-core/src/language_server/tests/inlay_hints.rs +expression: hints +--- +[]