feat: copy `.erg`

This commit is contained in:
Shunsuke Shibayama 2023-09-10 13:10:16 +09:00
parent 75be1077db
commit 80ab984b6d
3 changed files with 43 additions and 0 deletions

38
src/copy.rs Normal file
View File

@ -0,0 +1,38 @@
use std::path::Path;
use std::fs::{copy, read_dir, create_dir_all};
use erg_common::env::{erg_path, python_site_packages};
fn copy_dir(from: impl AsRef<Path>, to: impl AsRef<Path>) -> std::io::Result<()> {
let from = from.as_ref();
let to = to.as_ref();
if !from.exists() {
return Ok(());
}
if !to.exists() {
create_dir_all(to)?;
}
for entry in read_dir(from)? {
let entry = entry?;
if entry.file_type()?.is_dir() {
copy_dir(entry.path(), to.join(entry.file_name()))?;
} else {
copy(entry.path(), to.join(entry.file_name()))?;
}
}
Ok(())
}
#[allow(unused)]
pub(crate) fn copy_dot_erg() {
if erg_path().exists() {
return;
}
for site_packages in python_site_packages() {
if site_packages.join(".erg").exists() {
println!("Copying site-package/.erg to {}", erg_path().display());
copy_dir(site_packages.join(".erg"), erg_path())
.expect("Failed to copy .erg");
}
}
}

View File

@ -1,5 +1,6 @@
mod analyze;
mod config;
mod handle_err;
mod copy;
pub use analyze::PythonAnalyzer;

View File

@ -1,13 +1,17 @@
mod analyze;
mod config;
mod handle_err;
mod copy;
use analyze::{PythonAnalyzer, SimplePythonParser};
use els::Server;
use erg_common::config::ErgMode;
use erg_common::spawn::exec_new_thread;
use crate::copy::copy_dot_erg;
fn run() {
copy_dot_erg();
let cfg = config::parse_args();
if cfg.mode == ErgMode::LanguageServer {
let mut lang_server = Server::<PythonAnalyzer, SimplePythonParser>::new(cfg, None);