More symbol usage

This commit is contained in:
Lukas Wirth 2024-07-16 12:05:16 +02:00
parent c30bdfcc84
commit df5f1777b8
50 changed files with 388 additions and 303 deletions

View file

@ -11,7 +11,8 @@ use stdx::format_to;
use url::Url;
use hir::{
db::HirDatabase, Adt, AsAssocItem, AssocItem, AssocItemContainer, DescendPreference, HasAttrs,
db::HirDatabase, sym, Adt, AsAssocItem, AssocItem, AssocItemContainer, DescendPreference,
HasAttrs,
};
use ide_db::{
base_db::{CrateOrigin, LangCrateOrigin, ReleaseChannel, SourceDatabase},
@ -593,12 +594,14 @@ fn filename_and_frag_for_def(
},
Definition::Module(m) => match m.name(db) {
// `#[doc(keyword = "...")]` is internal used only by rust compiler
Some(name) => match m.attrs(db).by_key("doc").find_string_value_in_tt("keyword") {
Some(kw) => {
format!("keyword.{}.html", kw.trim_matches('"'))
Some(name) => {
match m.attrs(db).by_key(&sym::doc).find_string_value_in_tt(&sym::keyword) {
Some(kw) => {
format!("keyword.{}.html", kw)
}
None => format!("{}/index.html", name.display(db.upcast())),
}
None => format!("{}/index.html", name.display(db.upcast())),
},
}
None => String::from("index.html"),
},
Definition::Trait(t) => format!("trait.{}.html", t.name(db).display(db.upcast())),

View file

@ -38,5 +38,5 @@ fn crate_info(data: &ide_db::base_db::CrateData) -> CrateInfo {
}
fn crate_name(data: &ide_db::base_db::CrateData) -> Option<String> {
data.display_name.as_ref().map(|it| it.canonical_name().to_owned())
data.display_name.as_ref().map(|it| it.canonical_name().as_str().to_owned())
}

View file

@ -408,7 +408,7 @@ pub(crate) fn def_to_moniker(
}),
),
};
PackageInformation { name, repo, version }
PackageInformation { name: name.as_str().to_owned(), repo, version }
},
})
}

View file

@ -3,7 +3,7 @@
use std::mem;
use either::Either;
use hir::{InFile, Semantics};
use hir::{sym, InFile, Semantics};
use ide_db::{
active_parameter::ActiveParameter, base_db::FileId, defs::Definition,
documentation::docs_with_rangemap, rust_doc::is_rust_fence, SymbolKind,
@ -153,7 +153,7 @@ pub(super) fn doc_comment(
let mut new_comments = Vec::new();
let mut string;
for attr in attributes.by_key("doc").attrs() {
for attr in attributes.by_key(&sym::doc).attrs() {
let InFile { file_id, value: src } = attrs_source_map.source_of(attr);
if file_id != src_file_id {
continue;
@ -271,7 +271,7 @@ fn find_doc_string_in_attr(attr: &hir::Attr, it: &ast::Attr) -> Option<ast::Stri
// #[cfg_attr(..., doc = "", ...)]
None => {
// We gotta hunt the string token manually here
let text = attr.string_value()?;
let text = attr.string_value()?.as_str();
// FIXME: We just pick the first string literal that has the same text as the doc attribute
// This means technically we might highlight the wrong one
it.syntax()