mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-29 13:25:09 +00:00
Optimize inlay hints
This commit is contained in:
parent
11d6b9dadd
commit
4194e5c88c
1 changed files with 6 additions and 5 deletions
|
@ -1,6 +1,6 @@
|
||||||
//! FIXME: write short doc here
|
//! FIXME: write short doc here
|
||||||
|
|
||||||
use hir::{HirDisplay, SourceAnalyzer};
|
use hir::{HirDisplay, SourceAnalyzer, SourceBinder};
|
||||||
use once_cell::unsync::Lazy;
|
use once_cell::unsync::Lazy;
|
||||||
use ra_prof::profile;
|
use ra_prof::profile;
|
||||||
use ra_syntax::{
|
use ra_syntax::{
|
||||||
|
@ -29,22 +29,23 @@ pub(crate) fn inlay_hints(
|
||||||
file: &SourceFile,
|
file: &SourceFile,
|
||||||
max_inlay_hint_length: Option<usize>,
|
max_inlay_hint_length: Option<usize>,
|
||||||
) -> Vec<InlayHint> {
|
) -> Vec<InlayHint> {
|
||||||
|
let mut sb = SourceBinder::new(db);
|
||||||
file.syntax()
|
file.syntax()
|
||||||
.descendants()
|
.descendants()
|
||||||
.flat_map(|node| get_inlay_hints(db, file_id, &node, max_inlay_hint_length))
|
.flat_map(|node| get_inlay_hints(&mut sb, file_id, &node, max_inlay_hint_length))
|
||||||
.flatten()
|
.flatten()
|
||||||
.collect()
|
.collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
fn get_inlay_hints(
|
fn get_inlay_hints(
|
||||||
db: &RootDatabase,
|
sb: &mut SourceBinder<RootDatabase>,
|
||||||
file_id: FileId,
|
file_id: FileId,
|
||||||
node: &SyntaxNode,
|
node: &SyntaxNode,
|
||||||
max_inlay_hint_length: Option<usize>,
|
max_inlay_hint_length: Option<usize>,
|
||||||
) -> Option<Vec<InlayHint>> {
|
) -> Option<Vec<InlayHint>> {
|
||||||
let _p = profile("get_inlay_hints");
|
let _p = profile("get_inlay_hints");
|
||||||
let analyzer =
|
let db = sb.db;
|
||||||
Lazy::new(|| SourceAnalyzer::new(db, hir::InFile::new(file_id.into(), node), None));
|
let analyzer = Lazy::new(move || sb.analyze(hir::InFile::new(file_id.into(), node), None));
|
||||||
match_ast! {
|
match_ast! {
|
||||||
match node {
|
match node {
|
||||||
ast::LetStmt(it) => {
|
ast::LetStmt(it) => {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue