Skip to content

Commit

Permalink
feat: copy .erg
Browse files Browse the repository at this point in the history
  • Loading branch information
mtshiba committed Sep 10, 2023
1 parent 75be107 commit 80ab984
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 0 deletions.
38 changes: 38 additions & 0 deletions src/copy.rs
Original file line number Diff line number Diff line change
@@ -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");
}
}
}
1 change: 1 addition & 0 deletions src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
mod analyze;
mod config;
mod handle_err;
mod copy;

pub use analyze::PythonAnalyzer;
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -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);
Expand Down

0 comments on commit 80ab984

Please sign in to comment.