-
Notifications
You must be signed in to change notification settings - Fork 53
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add "Find all References" for commands (#1085)
- Loading branch information
Showing
8 changed files
with
99 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use base_db::{semantics::Span, DocumentLocation}; | ||
use rowan::ast::AstNode; | ||
use rustc_hash::FxHashSet; | ||
use syntax::latex; | ||
|
||
use crate::{Reference, ReferenceContext, ReferenceKind}; | ||
|
||
pub(super) fn find_all(context: &mut ReferenceContext) -> Option<()> { | ||
let data = context.params.feature.document.data.as_tex()?; | ||
let token = data | ||
.root_node() | ||
.token_at_offset(context.params.offset) | ||
.find(|token| token.kind() == latex::COMMAND_NAME)?; | ||
|
||
let project = &context.params.feature.project; | ||
|
||
for document in &project.documents { | ||
if let Some(data) = document.data.as_tex() { | ||
let defs: FxHashSet<Span> = data | ||
.root_node() | ||
.descendants() | ||
.filter_map(|node| { | ||
latex::OldCommandDefinition::cast(node.clone()) | ||
.and_then(|node| node.name()) | ||
.or_else(|| { | ||
latex::NewCommandDefinition::cast(node) | ||
.and_then(|node| node.name()) | ||
.and_then(|group| group.command()) | ||
}) | ||
.map(|name| Span::command(&name)) | ||
}) | ||
.collect(); | ||
|
||
for command in &data.semantics.commands { | ||
if command.text == &token.text()[1..] { | ||
let kind = if defs.contains(command) { | ||
ReferenceKind::Definition | ||
} else { | ||
ReferenceKind::Reference | ||
}; | ||
|
||
context.results.push(Reference { | ||
location: DocumentLocation::new(document, command.range), | ||
kind, | ||
}); | ||
} | ||
} | ||
} | ||
} | ||
|
||
Some(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters