Skip to content

Commit

Permalink
run.toml on remote fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dzhou121 committed Nov 8, 2023
1 parent d3e8ea8 commit bbe431a
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 24 deletions.
5 changes: 4 additions & 1 deletion lapce-app/src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2730,7 +2730,9 @@ fn completion(window_tab_data: Rc<WindowTabData>) -> impl View {
)
.style(move |s| {
let config = config.get();
s.width(config.editor.line_height() as f32)
let width = config.editor.line_height() as f32;
s.width(width)
.min_width(width)
.height_full()
.align_items(Some(AlignItems::Center))
.font_weight(Weight::BOLD)
Expand All @@ -2749,6 +2751,7 @@ fn completion(window_tab_data: Rc<WindowTabData>) -> impl View {
.style(move |s| {
let config = config.get();
s.padding_horiz(5.0)
.min_width(0.0)
.align_items(Some(AlignItems::Center))
.size_full()
.apply_if(active.get() == i, |s| {
Expand Down
19 changes: 1 addition & 18 deletions lapce-app/src/debug.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use std::{
collections::{BTreeMap, HashMap},
fmt::Display,
path::{Path, PathBuf},
path::PathBuf,
rc::Rc,
time::Instant,
};
Expand All @@ -27,8 +27,6 @@ use crate::{
window_tab::CommonData,
};

const DEFAULT_RUN_TOML: &str = include_str!("../../defaults/run.toml");

#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)]
pub enum RunDebugMode {
Run,
Expand Down Expand Up @@ -59,21 +57,6 @@ pub struct RunDebugConfigs {
pub configs: Vec<RunDebugConfig>,
}

pub fn run_configs(workspace: Option<&Path>) -> Option<RunDebugConfigs> {
let workspace = workspace?;
let run_toml = workspace.join(".lapce").join("run.toml");
if !run_toml.exists() {
if !workspace.join(".lapce").exists() {
let _ = std::fs::create_dir_all(workspace.join(".lapce"));
}
let _ = std::fs::write(&run_toml, DEFAULT_RUN_TOML);
return None;
}
let content = std::fs::read_to_string(run_toml).ok()?;
let configs: RunDebugConfigs = toml::from_str(&content).ok()?;
Some(configs)
}

#[derive(Clone)]
pub struct RunDebugData {
pub active_term: RwSignal<Option<TermId>>,
Expand Down
39 changes: 35 additions & 4 deletions lapce-app/src/palette.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ use crate::{
CommandExecuted, CommandKind, InternalCommand, LapceCommand, WindowCommand,
},
db::LapceDb,
debug::{run_configs, RunDebugMode},
debug::{RunDebugConfigs, RunDebugMode},
editor::{
location::{EditorLocation, EditorPosition},
EditorData,
Expand All @@ -55,6 +55,8 @@ use crate::{
pub mod item;
pub mod kind;

const DEFAULT_RUN_TOML: &str = include_str!("../../defaults/run.toml");

#[derive(Clone, PartialEq, Eq)]
pub enum PaletteStatus {
Inactive,
Expand Down Expand Up @@ -736,8 +738,8 @@ impl PaletteData {
self.items.set(items);
}

fn get_run_configs(&self) {
let configs = run_configs(self.common.workspace.path.as_deref());
fn set_run_configs(&self, content: String) {
let configs: Option<RunDebugConfigs> = toml::from_str(&content).ok();
if configs.is_none() {
if let Some(path) = self.workspace.path.as_ref() {
let path = path.join(".lapce").join("run.toml");
Expand All @@ -746,8 +748,8 @@ impl PaletteData {
.send(InternalCommand::OpenFile { path });
}
}
let executed_run_configs = self.executed_run_configs.borrow();

let executed_run_configs = self.executed_run_configs.borrow();
let mut items = Vec::new();
if let Some(configs) = configs.as_ref() {
for config in &configs.configs {
Expand Down Expand Up @@ -797,6 +799,35 @@ impl PaletteData {
.set(items.into_iter().map(|(_, item)| item).collect());
}

fn get_run_configs(&self) {
if let Some(workspace) = self.common.workspace.path.as_deref() {
let run_toml = workspace.join(".lapce").join("run.toml");
let (doc, new_doc) = self.main_split.get_doc(run_toml.clone());
if !new_doc {
let content = doc.buffer.with_untracked(|b| b.to_string());
self.set_run_configs(content);
} else {
let loaded = doc.loaded;
let palette = self.clone();
self.common.scope.create_effect(move |prev_loaded| {
if prev_loaded == Some(true) {
return true;
}

let loaded = loaded.get();
if loaded {
let content = doc.buffer.with_untracked(|b| b.to_string());
if content.is_empty() {
doc.reload(Rope::from(DEFAULT_RUN_TOML), false);
}
palette.set_run_configs(content);
}
loaded
});
}
}
}

fn get_color_themes(&self) {
let config = self.common.config.get_untracked();
let items = config
Expand Down
2 changes: 1 addition & 1 deletion lapce-proxy/src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ impl Buffer {
std::io::ErrorKind::PermissionDenied => {
("Permission Denied".to_string(), true)
}
std::io::ErrorKind::NotFound => ("Not Found".to_string(), false),
std::io::ErrorKind::NotFound => ("".to_string(), false),
_ => ("Not Supported".to_string(), true),
},
None => ("Not Supported".to_string(), true),
Expand Down

0 comments on commit bbe431a

Please sign in to comment.