summaryrefslogtreecommitdiff
path: root/support/texlab/src/util/cursor.rs
diff options
context:
space:
mode:
Diffstat (limited to 'support/texlab/src/util/cursor.rs')
-rw-r--r--support/texlab/src/util/cursor.rs27
1 files changed, 21 insertions, 6 deletions
diff --git a/support/texlab/src/util/cursor.rs b/support/texlab/src/util/cursor.rs
index 63579c433c..d3168155da 100644
--- a/support/texlab/src/util/cursor.rs
+++ b/support/texlab/src/util/cursor.rs
@@ -24,7 +24,7 @@ impl Cursor {
let left = left?;
let right = right?;
- if left.kind().is_command_name() {
+ if left.kind() == latex::COMMAND_NAME {
return Some(Self::Tex(left));
}
@@ -36,7 +36,7 @@ impl Cursor {
return Some(Self::Tex(left));
}
- if right.kind().is_command_name() {
+ if right.kind() == latex::COMMAND_NAME {
return Some(Self::Tex(right));
}
@@ -105,7 +105,7 @@ impl Cursor {
pub fn command_range(&self, offset: TextSize) -> Option<TextRange> {
self.as_tex()
- .filter(|token| token.kind().is_command_name())
+ .filter(|token| token.kind() == latex::COMMAND_NAME)
.filter(|token| token.text_range().start() != offset)
.map(|token| token.text_range())
.map(|range| TextRange::new(range.start() + TextSize::from(1), range.end()))
@@ -135,7 +135,7 @@ impl<'db, T> CursorContext<'db, T> {
pub fn new(db: &'db dyn Db, uri: &Url, position: Position, params: T) -> Option<Self> {
let workspace = Workspace::get(db);
let document = workspace.lookup_uri(db, uri)?;
- let line_index = document.contents(db).line_index(db);
+ let line_index = document.line_index(db);
let offset = line_index.offset_lsp(position);
let cursor = match document.parse(db) {
@@ -251,6 +251,22 @@ impl<'db, T> CursorContext<'db, T> {
Some((name, range))
}
+ pub fn find_environment(&self) -> Option<(latex::Key, latex::Key)> {
+ let token = self.cursor.as_tex()?;
+
+ for env in token
+ .parent_ancestors()
+ .filter_map(latex::Environment::cast)
+ {
+ let beg = env.begin()?.name()?.key()?;
+ let end = env.end()?.name()?.key()?;
+
+ return Some((beg, end));
+ }
+
+ None
+ }
+
pub fn find_curly_group_word(&self) -> Option<(String, TextRange, latex::CurlyGroupWord)> {
let token = self.cursor.as_tex()?;
let key = latex::Key::cast(token.parent()?);
@@ -285,8 +301,7 @@ impl<'db, T> CursorContext<'db, T> {
let range = if group
.syntax()
.last_token()
- .filter(|tok| tok.kind() == latex::MISSING)
- .is_some()
+ .map_or(false, |tok| tok.kind() != latex::R_CURLY)
{
TextRange::new(latex::small_range(&key).start(), token.text_range().end())
} else {