Fork of daniellemaywood.uk/gleam — Wasm codegen work
1.5 kB
57 lines
1mod code_action;
2mod compiler;
3mod engine;
4mod feedback;
5mod files;
6mod messages;
7mod progress;
8mod router;
9mod server;
10
11#[cfg(test)]
12mod tests;
13
14pub use server::LanguageServer;
15
16use crate::{
17 ast::SrcSpan, build::Target, line_numbers::LineNumbers, manifest::Manifest,
18 paths::ProjectPaths, Result,
19};
20use camino::Utf8PathBuf;
21use lsp_types::{Position, Range, Url};
22use std::any::Any;
23
24#[derive(Debug)]
25pub struct LockGuard(pub Box<dyn Any>);
26
27pub trait Locker {
28 fn lock_for_build(&self) -> LockGuard;
29}
30
31pub trait MakeLocker {
32 fn make_locker(&self, paths: &ProjectPaths, target: Target) -> Result<Box<dyn Locker>>;
33}
34
35pub trait DownloadDependencies {
36 fn download_dependencies(&self, paths: &ProjectPaths) -> Result<Manifest>;
37}
38
39pub fn src_span_to_lsp_range(location: SrcSpan, line_numbers: &LineNumbers) -> Range {
40 let start = line_numbers.line_and_column_number(location.start);
41 let end = line_numbers.line_and_column_number(location.end);
42
43 Range::new(
44 Position::new(start.line - 1, start.column - 1),
45 Position::new(end.line - 1, end.column - 1),
46 )
47}
48
49fn path(uri: &Url) -> Utf8PathBuf {
50 // The to_file_path method is available on these platforms
51 #[cfg(any(unix, windows, target_os = "redox", target_os = "wasi"))]
52 return Utf8PathBuf::from_path_buf(uri.to_file_path().expect("URL file"))
53 .expect("Non Utf8 Path");
54
55 #[cfg(not(any(unix, windows, target_os = "redox", target_os = "wasi")))]
56 return Utf8PathBuf::from_path_buf(uri.path().into()).expect("Non Utf8 Path");
57}