Skip to content

Commit

Permalink
snapshot test all the things
Browse files Browse the repository at this point in the history
  • Loading branch information
giacomocavalieri committed Sep 11, 2024
1 parent afdefc6 commit 124821c
Show file tree
Hide file tree
Showing 24 changed files with 568 additions and 532 deletions.
31 changes: 30 additions & 1 deletion compiler-core/src/language_server/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ use ecow::EcoString;
use hexpm::version::{Range, Version};

use camino::{Utf8Path, Utf8PathBuf};
use itertools::Itertools;
use lsp_types::{Position, TextDocumentIdentifier, TextDocumentPositionParams, Url};

use crate::{
Expand Down Expand Up @@ -392,6 +393,34 @@ impl<'a> TestProject<'a> {
}
}

pub fn src_from_module_url(&self, url: Url) -> Option<&str> {
let module_name: EcoString = url
.path_segments()?
.skip_while(|segment| *segment != "src")
.skip(1)
.join("/")
.trim_end_matches(".gleam")
.into();

if module_name == "app" {
return Some(self.src);
}

let find_module = |modules: &Vec<(&'a str, &'a str)>| {
modules
.iter()
.find(|(name, _)| *name == module_name)
.map(|(_, src)| *src)
};

find_module(&self.root_package_modules)
.or(find_module(&self.dependency_modules))
.or(find_module(&self.test_modules))
.or(find_module(&self.hex_modules))
.or(find_module(&self.dev_hex_modules))
.or(find_module(&self.indirect_hex_modules))
}

pub fn add_module(mut self, name: &'a str, src: &'a str) -> Self {
self.root_package_modules.push((name, src));
self
Expand Down Expand Up @@ -565,7 +594,7 @@ impl<'a> TestProject<'a> {
}

pub fn at<T>(
self,
&self,
position: Position,
executor: impl FnOnce(
&mut LanguageServerEngine<LanguageServerTestIO, LanguageServerTestIO>,
Expand Down
Loading

0 comments on commit 124821c

Please sign in to comment.