Name the root file of every crate after the crate to ease navigation

Co-Authored-By: Max Brunsfeld <maxbrunsfeld@gmail.com>
This commit is contained in:
Nathan Sobo 2021-11-30 12:46:39 -07:00
parent 748b1ba602
commit 1445ce10b5
47 changed files with 133 additions and 79 deletions

View file

@ -1,15 +1,7 @@
mod highlight_map;
mod language;
pub mod proto;
#[cfg(test)]
mod tests;
pub use self::{
pub use crate::{
highlight_map::{HighlightId, HighlightMap},
language::{
BracketPair, Grammar, Language, LanguageConfig, LanguageRegistry, LanguageServerConfig,
PLAIN_TEXT,
},
proto, BracketPair, Grammar, Language, LanguageConfig, LanguageRegistry, LanguageServerConfig,
PLAIN_TEXT,
};
use anyhow::{anyhow, Result};
use clock::ReplicaId;
@ -73,7 +65,7 @@ pub struct Buffer {
diagnostics_update_count: usize,
language_server: Option<LanguageServerState>,
#[cfg(test)]
operations: Vec<Operation>,
pub(crate) operations: Vec<Operation>,
}
pub struct Snapshot {
@ -217,7 +209,7 @@ pub struct Chunk<'a> {
pub diagnostic: Option<DiagnosticSeverity>,
}
struct Diff {
pub(crate) struct Diff {
base_version: clock::Global,
new_text: Arc<str>,
changes: Vec<(ChangeTag, usize)>,
@ -573,7 +565,7 @@ impl Buffer {
self.parse_count
}
fn syntax_tree(&self) -> Option<Tree> {
pub(crate) fn syntax_tree(&self) -> Option<Tree> {
if let Some(syntax_tree) = self.syntax_tree.lock().as_mut() {
self.interpolate_tree(syntax_tree);
Some(syntax_tree.tree.clone())
@ -1094,7 +1086,7 @@ impl Buffer {
.min_by_key(|(open_range, close_range)| close_range.end - open_range.start)
}
fn diff(&self, new_text: Arc<str>, cx: &AppContext) -> Task<Diff> {
pub(crate) fn diff(&self, new_text: Arc<str>, cx: &AppContext) -> Task<Diff> {
// TODO: it would be nice to not allocate here.
let old_text = self.text();
let base_version = self.version();
@ -1111,7 +1103,7 @@ impl Buffer {
})
}
fn apply_diff(&mut self, diff: Diff, cx: &mut ModelContext<Self>) -> bool {
pub(crate) fn apply_diff(&mut self, diff: Diff, cx: &mut ModelContext<Self>) -> bool {
if self.version == diff.base_version {
self.start_transaction(None).unwrap();
let mut offset = 0;
@ -1153,7 +1145,7 @@ impl Buffer {
self.start_transaction_at(selection_set_ids, Instant::now())
}
fn start_transaction_at(
pub(crate) fn start_transaction_at(
&mut self,
selection_set_ids: impl IntoIterator<Item = SelectionSetId>,
now: Instant,
@ -1169,7 +1161,7 @@ impl Buffer {
self.end_transaction_at(selection_set_ids, Instant::now(), cx)
}
fn end_transaction_at(
pub(crate) fn end_transaction_at(
&mut self,
selection_set_ids: impl IntoIterator<Item = SelectionSetId>,
now: Instant,
@ -1995,7 +1987,7 @@ fn diagnostic_ranges<'a>(
))
}
fn contiguous_ranges(
pub fn contiguous_ranges(
values: impl IntoIterator<Item = u32>,
max_len: usize,
) -> impl Iterator<Item = Range<u32>> {

View file

@ -1,6 +1,14 @@
use crate::HighlightMap;
mod buffer;
mod highlight_map;
pub mod proto;
#[cfg(test)]
mod tests;
use anyhow::{anyhow, Result};
pub use buffer::Operation;
pub use buffer::*;
use gpui::{executor::Background, AppContext};
use highlight_map::HighlightMap;
use lazy_static::lazy_static;
use lsp::LanguageServer;
use parking_lot::Mutex;
@ -223,56 +231,3 @@ impl LanguageServerConfig {
)
}
}
#[cfg(test)]
mod tests {
use super::*;
#[test]
fn test_select_language() {
let registry = LanguageRegistry {
languages: vec![
Arc::new(Language::new(
LanguageConfig {
name: "Rust".to_string(),
path_suffixes: vec!["rs".to_string()],
..Default::default()
},
Some(tree_sitter_rust::language()),
)),
Arc::new(Language::new(
LanguageConfig {
name: "Make".to_string(),
path_suffixes: vec!["Makefile".to_string(), "mk".to_string()],
..Default::default()
},
Some(tree_sitter_rust::language()),
)),
],
};
// matching file extension
assert_eq!(
registry.select_language("zed/lib.rs").map(|l| l.name()),
Some("Rust")
);
assert_eq!(
registry.select_language("zed/lib.mk").map(|l| l.name()),
Some("Make")
);
// matching filename
assert_eq!(
registry.select_language("zed/Makefile").map(|l| l.name()),
Some("Make")
);
// matching suffix that is not the full file extension or filename
assert_eq!(registry.select_language("zed/cars").map(|l| l.name()), None);
assert_eq!(
registry.select_language("zed/a.cars").map(|l| l.name()),
None
);
assert_eq!(registry.select_language("zed/sumk").map(|l| l.name()), None);
}
}

View file

@ -1,8 +1,6 @@
use std::sync::Arc;
use crate::Diagnostic;
use super::Operation;
use crate::{Diagnostic, Operation};
use anyhow::{anyhow, Result};
use clock::ReplicaId;
use lsp::DiagnosticSeverity;

View file

@ -1,8 +1,56 @@
use super::*;
use gpui::{ModelHandle, MutableAppContext};
use std::{iter::FromIterator, rc::Rc};
use gpui::{ModelHandle, MutableAppContext, Task};
use std::{any::Any, cell::RefCell, ffi::OsString, iter::FromIterator, ops::Range, path::PathBuf, rc::Rc, time::{Duration, Instant, SystemTime}};
use unindent::Unindent as _;
#[test]
fn test_select_language() {
let registry = LanguageRegistry {
languages: vec![
Arc::new(Language::new(
LanguageConfig {
name: "Rust".to_string(),
path_suffixes: vec!["rs".to_string()],
..Default::default()
},
Some(tree_sitter_rust::language()),
)),
Arc::new(Language::new(
LanguageConfig {
name: "Make".to_string(),
path_suffixes: vec!["Makefile".to_string(), "mk".to_string()],
..Default::default()
},
Some(tree_sitter_rust::language()),
)),
],
};
// matching file extension
assert_eq!(
registry.select_language("zed/lib.rs").map(|l| l.name()),
Some("Rust")
);
assert_eq!(
registry.select_language("zed/lib.mk").map(|l| l.name()),
Some("Make")
);
// matching filename
assert_eq!(
registry.select_language("zed/Makefile").map(|l| l.name()),
Some("Make")
);
// matching suffix that is not the full file extension or filename
assert_eq!(registry.select_language("zed/cars").map(|l| l.name()), None);
assert_eq!(
registry.select_language("zed/a.cars").map(|l| l.name()),
None
);
assert_eq!(registry.select_language("zed/sumk").map(|l| l.name()), None);
}
#[gpui::test]
fn test_edit_events(cx: &mut gpui::MutableAppContext) {
let mut now = Instant::now();