Clean up inlay_hints

This commit is contained in:
Lukas Wirth
2020-10-07 13:14:12 +02:00
parent e106857e80
commit 783af171f7
2 changed files with 26 additions and 19 deletions

View File

@@ -3,7 +3,7 @@ pub(crate) mod insert_use;
use std::{iter, ops};
use hir::{Adt, Crate, Enum, ScopeDef, Semantics, Trait, Type};
use hir::{Adt, Crate, Enum, Module, ScopeDef, Semantics, Trait, Type};
use ide_db::RootDatabase;
use itertools::Itertools;
use rustc_hash::FxHashSet;
@@ -373,6 +373,10 @@ pub use prelude::*;
self.find_trait("core:iter:traits:iterator:Iterator")
}
pub fn core_iter(&self) -> Option<Module> {
self.find_module("core:iter")
}
fn find_trait(&self, path: &str) -> Option<Trait> {
match self.find_def(path)? {
hir::ScopeDef::ModuleDef(hir::ModuleDef::Trait(it)) => Some(it),
@@ -387,6 +391,13 @@ pub use prelude::*;
}
}
fn find_module(&self, path: &str) -> Option<Module> {
match self.find_def(path)? {
hir::ScopeDef::ModuleDef(hir::ModuleDef::Module(it)) => Some(it),
_ => None,
}
}
fn find_def(&self, path: &str) -> Option<ScopeDef> {
let db = self.0.db;
let mut path = path.split(':');