summaryrefslogtreecommitdiff
path: root/support/texlab/src/syntax/text.rs
diff options
context:
space:
mode:
Diffstat (limited to 'support/texlab/src/syntax/text.rs')
-rw-r--r--support/texlab/src/syntax/text.rs42
1 files changed, 18 insertions, 24 deletions
diff --git a/support/texlab/src/syntax/text.rs b/support/texlab/src/syntax/text.rs
index df38635940..17d6876126 100644
--- a/support/texlab/src/syntax/text.rs
+++ b/support/texlab/src/syntax/text.rs
@@ -1,6 +1,6 @@
-use lsp_types::{Position, Range};
-use std::iter::Peekable;
-use std::str::CharIndices;
+use crate::protocol::{Position, Range};
+use serde::{Deserialize, Serialize};
+use std::{iter::Peekable, str::CharIndices};
pub trait SyntaxNode {
fn range(&self) -> Range;
@@ -14,7 +14,8 @@ pub trait SyntaxNode {
}
}
-#[derive(Debug, PartialEq, Eq, Clone)]
+#[derive(Debug, PartialEq, Eq, Clone, Serialize, Deserialize)]
+#[serde(rename_all = "camelCase")]
pub struct Span {
pub range: Range,
pub text: String,
@@ -22,7 +23,7 @@ pub struct Span {
impl Span {
pub fn new(range: Range, text: String) -> Self {
- Span { range, text }
+ Self { range, text }
}
}
@@ -32,6 +33,7 @@ impl SyntaxNode for Span {
}
}
+#[derive(Debug)]
pub struct CharStream<'a> {
text: &'a str,
chars: Peekable<CharIndices<'a>>,
@@ -43,7 +45,7 @@ pub struct CharStream<'a> {
impl<'a> CharStream<'a> {
pub fn new(text: &'a str) -> Self {
- CharStream {
+ Self {
text,
chars: text.char_indices().peekable(),
current_position: Position::new(0, 0),
@@ -149,21 +151,13 @@ fn is_command_char(c: char) -> bool {
c >= 'a' && c <= 'z' || c >= 'A' && c <= 'Z' || c == '@'
}
-pub fn titlelize(string: &str) -> String {
- let mut chars = string.chars();
- match chars.next() {
- None => String::new(),
- Some(c) => c.to_uppercase().chain(chars).collect(),
- }
-}
-
#[cfg(test)]
mod tests {
use super::*;
- use crate::range::RangeExt;
+ use crate::protocol::RangeExt;
#[test]
- fn test_peek() {
+ fn peek() {
let mut stream = CharStream::new("ab\nc");
assert_eq!(Some('a'), stream.peek());
assert_eq!(Some('a'), stream.next());
@@ -178,7 +172,7 @@ mod tests {
}
#[test]
- fn test_span() {
+ fn span() {
let mut stream = CharStream::new("abc\ndef");
stream.next();
stream.start_span();
@@ -194,7 +188,7 @@ mod tests {
}
#[test]
- fn test_span_unicode() {
+ fn span_unicode() {
let mut stream = CharStream::new("😀😃😄😁");
stream.next();
stream.start_span();
@@ -208,7 +202,7 @@ mod tests {
}
#[test]
- fn test_satifies() {
+ fn satifies() {
let mut stream = CharStream::new("aBc");
assert_eq!(true, stream.satifies(|c| c.is_lowercase()));
stream.next();
@@ -216,7 +210,7 @@ mod tests {
}
#[test]
- fn test_skip_rest_of_line() {
+ fn skip_rest_of_line() {
let mut stream = CharStream::new("abc\ndef");
stream.skip_rest_of_line();
assert_eq!(Some('d'), stream.next());
@@ -227,7 +221,7 @@ mod tests {
}
#[test]
- fn test_seek() {
+ fn seek() {
let mut stream = CharStream::new("abc\ndefghi");
let pos = Position::new(1, 2);
stream.seek(pos);
@@ -235,7 +229,7 @@ mod tests {
}
#[test]
- fn test_command_basic() {
+ fn command_basic() {
let mut stream = CharStream::new("\\foo@bar");
let span = stream.command();
assert_eq!(
@@ -245,7 +239,7 @@ mod tests {
}
#[test]
- fn test_command_star() {
+ fn command_star() {
let mut stream = CharStream::new("\\foo*");
let span = stream.command();
assert_eq!(
@@ -255,7 +249,7 @@ mod tests {
}
#[test]
- fn test_command_escape() {
+ fn command_escape() {
let mut stream = CharStream::new("\\**");
let span = stream.command();
assert_eq!(