|
1 | 1 | //! This module generates [moniker](https://microsoft.github.io/language-server-protocol/specifications/lsif/0.6.0/specification/#exportsImports)
|
2 | 2 | //! for LSIF and LSP.
|
3 | 3 |
|
4 |
| -use hir::{db::DefDatabase, AsAssocItem, AssocItemContainer, Crate, Name, Semantics}; |
| 4 | +use hir::{AsAssocItem, AssocItemContainer, Crate, Name, Semantics}; |
5 | 5 | use ide_db::{
|
6 |
| - base_db::{CrateOrigin, FileId, FileLoader, FilePosition, LangCrateOrigin}, |
| 6 | + base_db::{CrateOrigin, FilePosition, LangCrateOrigin}, |
7 | 7 | defs::{Definition, IdentClass},
|
8 | 8 | helpers::pick_best_token,
|
9 | 9 | RootDatabase,
|
10 | 10 | };
|
11 | 11 | use itertools::Itertools;
|
12 | 12 | use syntax::{AstNode, SyntaxKind::*, T};
|
13 | 13 |
|
14 |
| -use crate::{doc_links::token_as_doc_comment, RangeInfo}; |
| 14 | +use crate::{doc_links::token_as_doc_comment, parent_module::crates_for, RangeInfo}; |
15 | 15 |
|
16 | 16 | #[derive(Debug, Clone, PartialEq, Eq, PartialOrd, Ord, Hash)]
|
17 | 17 | pub enum MonikerDescriptorKind {
|
@@ -77,25 +77,13 @@ pub struct PackageInformation {
|
77 | 77 | pub version: Option<String>,
|
78 | 78 | }
|
79 | 79 |
|
80 |
| -pub(crate) fn crate_for_file(db: &RootDatabase, file_id: FileId) -> Option<Crate> { |
81 |
| - for &krate in db.relevant_crates(file_id).iter() { |
82 |
| - let crate_def_map = db.crate_def_map(krate); |
83 |
| - for (_, data) in crate_def_map.modules() { |
84 |
| - if data.origin.file_id() == Some(file_id) { |
85 |
| - return Some(krate.into()); |
86 |
| - } |
87 |
| - } |
88 |
| - } |
89 |
| - None |
90 |
| -} |
91 |
| - |
92 | 80 | pub(crate) fn moniker(
|
93 | 81 | db: &RootDatabase,
|
94 | 82 | FilePosition { file_id, offset }: FilePosition,
|
95 | 83 | ) -> Option<RangeInfo<Vec<MonikerResult>>> {
|
96 | 84 | let sema = &Semantics::new(db);
|
97 | 85 | let file = sema.parse(file_id).syntax().clone();
|
98 |
| - let current_crate = crate_for_file(db, file_id)?; |
| 86 | + let current_crate: hir::Crate = crates_for(db, file_id).pop()?.into(); |
99 | 87 | let original_token = pick_best_token(file.token_at_offset(offset), |kind| match kind {
|
100 | 88 | IDENT
|
101 | 89 | | INT_NUMBER
|
|
0 commit comments