mirror of https://github.com/lapce/lapce.git
Merge pull request #788 from ImajinDevon/master
Utilize the `fs` module
This commit is contained in:
commit
7744f76ce6
|
@ -1,14 +1,12 @@
|
||||||
use anyhow::{anyhow, Result};
|
use anyhow::{anyhow, Result};
|
||||||
use lapce_rpc::buffer::BufferId;
|
use lapce_rpc::buffer::BufferId;
|
||||||
|
use lsp_types::*;
|
||||||
use std::ffi::OsString;
|
use std::ffi::OsString;
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::fs::File;
|
use std::fs::File;
|
||||||
use std::io::Read;
|
|
||||||
use std::io::Write;
|
use std::io::Write;
|
||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
use std::{borrow::Cow, path::Path, time::SystemTime};
|
use std::{borrow::Cow, path::Path, time::SystemTime};
|
||||||
|
|
||||||
use lsp_types::*;
|
|
||||||
use xi_rope::{interval::IntervalBounds, rope::Rope, RopeDelta};
|
use xi_rope::{interval::IntervalBounds, rope::Rope, RopeDelta};
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
@ -81,15 +79,13 @@ pub fn update(
|
||||||
self.rev += 1;
|
self.rev += 1;
|
||||||
let content_change = get_document_content_changes(delta, self);
|
let content_change = get_document_content_changes(delta, self);
|
||||||
self.rope = delta.apply(&self.rope);
|
self.rope = delta.apply(&self.rope);
|
||||||
let content_change = match content_change {
|
Some(
|
||||||
Some(content_change) => content_change,
|
content_change.unwrap_or_else(|| TextDocumentContentChangeEvent {
|
||||||
None => TextDocumentContentChangeEvent {
|
|
||||||
range: None,
|
range: None,
|
||||||
range_length: None,
|
range_length: None,
|
||||||
text: self.get_document(),
|
text: self.get_document(),
|
||||||
},
|
}),
|
||||||
};
|
)
|
||||||
Some(content_change)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn get_document(&self) -> String {
|
pub fn get_document(&self) -> String {
|
||||||
|
@ -131,17 +127,11 @@ pub fn is_empty(&self) -> bool {
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn load_file(path: &Path) -> Result<String> {
|
pub fn load_file(path: &Path) -> Result<String> {
|
||||||
let mut f = File::open(path)?;
|
Ok(fs::read_to_string(path)?)
|
||||||
let mut bytes = Vec::new();
|
|
||||||
f.read_to_end(&mut bytes)?;
|
|
||||||
Ok(std::str::from_utf8(&bytes)?.to_string())
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn load_rope(path: &Path) -> Result<Rope> {
|
fn load_rope(path: &Path) -> Result<Rope> {
|
||||||
let mut f = File::open(path)?;
|
Ok(Rope::from(fs::read_to_string(path)?))
|
||||||
let mut bytes = Vec::new();
|
|
||||||
f.read_to_end(&mut bytes)?;
|
|
||||||
Ok(Rope::from(std::str::from_utf8(&bytes)?))
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn language_id_from_path(path: &Path) -> Option<&str> {
|
fn language_id_from_path(path: &Path) -> Option<&str> {
|
||||||
|
|
Loading…
Reference in New Issue