diff --git a/lapce-data/src/editor.rs b/lapce-data/src/editor.rs index 6bcab970..18ba28b3 100644 --- a/lapce-data/src/editor.rs +++ b/lapce-data/src/editor.rs @@ -34,7 +34,7 @@ use lapce_core::command::{ EditCommand, FocusCommand, MotionModeCommand, MultiSelectionCommand, }; -use lapce_core::mode::{Mode, MotionMode, VisualMode}; +use lapce_core::mode::{Mode, MotionMode}; pub use lapce_core::syntax::Syntax; use lsp_types::CompletionTextEdit; use lsp_types::{ @@ -1875,15 +1875,6 @@ pub struct TabRect { pub text_layout: PietTextLayout, } -#[derive(Clone)] -pub struct RegisterContent { - #[allow(dead_code)] - kind: VisualMode, - - #[allow(dead_code)] - content: Vec, -} - #[derive(Clone)] pub struct HighlightTextLayout { pub layout: PietTextLayout, diff --git a/lapce-data/src/lib.rs b/lapce-data/src/lib.rs index 897aeae0..020a5e65 100644 --- a/lapce-data/src/lib.rs +++ b/lapce-data/src/lib.rs @@ -11,7 +11,6 @@ pub mod history; pub mod hover; pub mod keypress; -pub mod lsp; pub mod menu; pub mod outline; pub mod palette; diff --git a/lapce-data/src/lsp.rs b/lapce-data/src/lsp.rs deleted file mode 100644 index e637f7ea..00000000 --- a/lapce-data/src/lsp.rs +++ /dev/null @@ -1,144 +0,0 @@ -use anyhow::{anyhow, Result}; -use druid::{WidgetId, WindowId}; -use jsonrpc_lite::Id; -use lapce_rpc::buffer::BufferId; -use parking_lot::Mutex; -use std::{collections::HashMap, io::BufRead, io::Write, process::Child, sync::Arc}; - -use lsp_types::*; -use serde_json::Value; - -pub type Callback = Box; -const HEADER_CONTENT_LENGTH: &str = "content-length"; -const HEADER_CONTENT_TYPE: &str = "content-type"; - -pub enum LspHeader { - ContentType, - ContentLength(usize), -} - -pub struct LspCatalog { - clients: HashMap>, -} - -impl LspCatalog { - pub fn new(_window_id: WindowId, _tab_id: WidgetId) -> LspCatalog { - LspCatalog { - clients: HashMap::new(), - } - } - - pub fn stop(&mut self) { - for (_, client) in self.clients.iter() { - let _ = client.state.lock().process.kill(); - } - self.clients.clear(); - } -} - -pub trait Callable: Send { - fn call(self: Box, client: &LspClient, result: Result); -} - -impl)> Callable for F { - fn call(self: Box, client: &LspClient, result: Result) { - (*self)(client, result) - } -} - -pub struct LspState { - #[allow(dead_code)] - next_id: u64, - - #[allow(dead_code)] - writer: Box, - process: Child, - - #[allow(dead_code)] - pending: HashMap, - - pub server_capabilities: Option, - pub opened_documents: HashMap, - pub is_initialized: bool, -} - -pub struct LspClient { - #[allow(dead_code)] - window_id: WindowId, - - #[allow(dead_code)] - tab_id: WidgetId, - - #[allow(dead_code)] - language_id: String, - - #[allow(dead_code)] - options: Option, - - state: Arc>, -} - -#[allow(dead_code)] -fn prepare_lsp_json(msg: &Value) -> Result { - let request = serde_json::to_string(&msg)?; - Ok(format!( - "Content-Length: {}\r\n\r\n{}", - request.len(), - request - )) -} - -fn parse_header(s: &str) -> Result { - let split: Vec = - s.splitn(2, ": ").map(|s| s.trim().to_lowercase()).collect(); - if split.len() != 2 { - return Err(anyhow!("Malformed")); - }; - match split[0].as_ref() { - HEADER_CONTENT_TYPE => Ok(LspHeader::ContentType), - HEADER_CONTENT_LENGTH => { - Ok(LspHeader::ContentLength(split[1].parse::()?)) - } - _ => Err(anyhow!("Unknown parse error occurred")), - } -} - -pub fn read_message(reader: &mut T) -> Result { - let mut buffer = String::new(); - let mut content_length: Option = None; - - loop { - buffer.clear(); - let _result = reader.read_line(&mut buffer); - // eprin - match &buffer { - s if s.trim().is_empty() => break, - s => { - match parse_header(s)? { - LspHeader::ContentLength(len) => content_length = Some(len), - LspHeader::ContentType => (), - }; - } - }; - } - - let content_length = content_length - .ok_or_else(|| anyhow!("missing content-length header: {}", buffer))?; - - let mut body_buffer = vec![0; content_length]; - reader.read_exact(&mut body_buffer)?; - - let body = String::from_utf8(body_buffer)?; - Ok(body) -} - -#[allow(dead_code)] -fn number_from_id(id: &Id) -> u64 { - match *id { - Id::Num(n) => n as u64, - Id::Str(ref s) => s - .parse::() - .expect("failed to convert string id to u64"), - _ => panic!("unexpected value for id: None"), - } -} diff --git a/lapce-proxy/src/dispatch.rs b/lapce-proxy/src/dispatch.rs index ed4f880a..4d5c26d3 100644 --- a/lapce-proxy/src/dispatch.rs +++ b/lapce-proxy/src/dispatch.rs @@ -759,77 +759,3 @@ fn file_get_head(workspace_path: &Path, path: &Path) -> Result<(String, String)> .to_string(); Ok((id, content)) } - -#[allow(dead_code)] -fn file_git_diff( - workspace_path: &Path, - path: &Path, - content: &str, -) -> Option<(Vec, HashMap)> { - let repo = Repository::open(workspace_path.to_str()?).ok()?; - let head = repo.head().ok()?; - let tree = head.peel_to_tree().ok()?; - let tree_entry = tree - .get_path(path.strip_prefix(workspace_path).ok()?) - .ok()?; - let blob = repo.find_blob(tree_entry.id()).ok()?; - let patch = git2::Patch::from_blob_and_buffer( - &blob, - None, - content.as_bytes(), - None, - None, - ) - .ok()?; - let mut line_changes = HashMap::new(); - Some(( - (0..patch.num_hunks()) - .into_iter() - .filter_map(|i| { - let hunk = patch.hunk(i).ok()?; - let hunk = DiffHunk { - old_start: hunk.0.old_start(), - old_lines: hunk.0.old_lines(), - new_start: hunk.0.new_start(), - new_lines: hunk.0.new_lines(), - header: String::from_utf8(hunk.0.header().to_vec()).ok()?, - }; - let mut line_diff = 0; - for line in 0..hunk.old_lines + hunk.new_lines { - if let Ok(diff_line) = patch.line_in_hunk(i, line as usize) { - match diff_line.origin() { - ' ' => { - let new_line = diff_line.new_lineno().unwrap(); - let old_line = diff_line.old_lineno().unwrap(); - line_diff = new_line as i32 - old_line as i32; - } - '-' => { - let old_line = diff_line.old_lineno().unwrap() - 1; - let new_line = - (old_line as i32 + line_diff) as usize; - line_changes.insert(new_line, '-'); - line_diff -= 1; - } - '+' => { - let new_line = - diff_line.new_lineno().unwrap() as usize - 1; - if let Some(c) = line_changes.get(&new_line) { - if c == &'-' { - line_changes.insert(new_line, 'm'); - } - } else { - line_changes.insert(new_line, '+'); - } - line_diff += 1; - } - _ => continue, - } - diff_line.origin(); - } - } - Some(hunk) - }) - .collect(), - line_changes, - )) -} diff --git a/lapce-ui/src/explorer.rs b/lapce-ui/src/explorer.rs index e214caeb..309a42c9 100644 --- a/lapce-ui/src/explorer.rs +++ b/lapce-ui/src/explorer.rs @@ -7,7 +7,6 @@ LifeCycle, LifeCycleCtx, PaintCtx, Point, Rect, RenderContext, Size, Target, UpdateCtx, Widget, WidgetExt, WidgetId, WidgetPod, }; -use include_dir::{include_dir, Dir}; use lapce_data::{ command::LapceUICommand, command::LAPCE_UI_COMMAND, @@ -24,9 +23,6 @@ svg::{file_svg_new, get_svg}, }; -#[allow(dead_code)] -const ICONS_DIR: Dir = include_dir!("../icons"); - #[allow(clippy::too_many_arguments)] pub fn paint_file_node_item( ctx: &mut PaintCtx, diff --git a/lapce-ui/src/lsp.rs b/lapce-ui/src/lsp.rs deleted file mode 100644 index 1216f94c..00000000 --- a/lapce-ui/src/lsp.rs +++ /dev/null @@ -1,153 +0,0 @@ -use anyhow::{anyhow, Result}; -use druid::{WidgetId, WindowId}; -use jsonrpc_lite::Id; -use parking_lot::Mutex; -use std::{collections::HashMap, io::BufRead, io::Write, process::Child, sync::Arc}; - -use lsp_types::*; -use serde_json::Value; - -use crate::buffer::BufferId; - -pub type Callback = Box; -const HEADER_CONTENT_LENGTH: &str = "content-length"; -const HEADER_CONTENT_TYPE: &str = "content-type"; - -pub enum LspHeader { - ContentType, - ContentLength(usize), -} - -pub struct LspCatalog { - #[allow(dead_code)] - window_id: WindowId, - - #[allow(dead_code)] - tab_id: WidgetId, - - clients: HashMap>, -} - -impl LspCatalog { - pub fn new(window_id: WindowId, tab_id: WidgetId) -> LspCatalog { - LspCatalog { - window_id, - tab_id, - clients: HashMap::new(), - } - } - - pub fn stop(&mut self) { - for (_, client) in self.clients.iter() { - let _ = client.state.lock().process.kill(); - } - self.clients.clear(); - } -} - -pub trait Callable: Send { - fn call(self: Box, client: &LspClient, result: Result); -} - -impl)> Callable for F { - fn call(self: Box, client: &LspClient, result: Result) { - (*self)(client, result) - } -} - -pub struct LspState { - #[allow(dead_code)] - next_id: u64, - - #[allow(dead_code)] - writer: Box, - process: Child, - - #[allow(dead_code)] - pending: HashMap, - - pub server_capabilities: Option, - pub opened_documents: HashMap, - pub is_initialized: bool, -} - -pub struct LspClient { - #[allow(dead_code)] - window_id: WindowId, - - #[allow(dead_code)] - tab_id: WidgetId, - - #[allow(dead_code)] - language_id: String, - - #[allow(dead_code)] - options: Option, - - state: Arc>, -} - -#[allow(dead_code)] -fn prepare_lsp_json(msg: &Value) -> Result { - let request = serde_json::to_string(&msg)?; - Ok(format!( - "Content-Length: {}\r\n\r\n{}", - request.len(), - request - )) -} - -fn parse_header(s: &str) -> Result { - let split: Vec = - s.splitn(2, ": ").map(|s| s.trim().to_lowercase()).collect(); - if split.len() != 2 { - return Err(anyhow!("Malformed")); - }; - match split[0].as_ref() { - HEADER_CONTENT_TYPE => Ok(LspHeader::ContentType), - HEADER_CONTENT_LENGTH => { - Ok(LspHeader::ContentLength(split[1].parse::()?)) - } - _ => Err(anyhow!("Unknown parse error occurred")), - } -} - -pub fn read_message(reader: &mut T) -> Result { - let mut buffer = String::new(); - let mut content_length: Option = None; - - loop { - buffer.clear(); - let _result = reader.read_line(&mut buffer); - // eprin - match &buffer { - s if s.trim().is_empty() => break, - s => { - match parse_header(s)? { - LspHeader::ContentLength(len) => content_length = Some(len), - LspHeader::ContentType => (), - }; - } - }; - } - - let content_length = content_length - .ok_or_else(|| anyhow!("missing content-length header: {}", buffer))?; - - let mut body_buffer = vec![0; content_length]; - reader.read_exact(&mut body_buffer)?; - - let body = String::from_utf8(body_buffer)?; - Ok(body) -} - -#[allow(dead_code)] -fn number_from_id(id: &Id) -> u64 { - match *id { - Id::Num(n) => n as u64, - Id::Str(ref s) => s - .parse::() - .expect("failed to convert string id to u64"), - _ => panic!("unexpected value for id: None"), - } -}