Skip to content

Commit

Permalink
testing inlay hints snapshot with default config
Browse files Browse the repository at this point in the history
  • Loading branch information
ascandone committed Sep 8, 2024
1 parent 668c44e commit f14e019
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 10 deletions.
11 changes: 2 additions & 9 deletions compiler-core/src/language_server/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::{
Expand Down Expand Up @@ -354,13 +354,6 @@ fn add_path_dep<B>(engine: &mut LanguageServerEngine<LanguageServerTestIO, B>, 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<LanguageServerTestIO, LanguageServerTestIO> {
Expand All @@ -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()
}
Expand Down
42 changes: 41 additions & 1 deletion compiler-core/src/language_server/tests/inlay_hints.rs
Original file line number Diff line number Diff line change
@@ -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]
Expand Down Expand Up @@ -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();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
source: compiler-core/src/language_server/tests/inlay_hints.rs
expression: hints
---
[]

0 comments on commit f14e019

Please sign in to comment.