mirror of
https://github.com/rust-lang/rust-analyzer
synced 2025-01-13 13:48:50 +00:00
Merge #5273
5273: Refactor hover tests r=matklad a=matklad
bors r+
🤖
Co-authored-by: Aleksey Kladov <aleksey.kladov@gmail.com>
This commit is contained in:
commit
a61c848157
7 changed files with 1701 additions and 1651 deletions
File diff suppressed because it is too large
Load diff
|
@ -17,6 +17,7 @@ macro_rules! eprintln {
|
|||
|
||||
pub mod mock_analysis;
|
||||
|
||||
mod markup;
|
||||
mod prime_caches;
|
||||
mod status;
|
||||
mod completion;
|
||||
|
@ -68,6 +69,7 @@ pub use crate::{
|
|||
folding_ranges::{Fold, FoldKind},
|
||||
hover::{HoverAction, HoverConfig, HoverGotoTypeData, HoverResult},
|
||||
inlay_hints::{InlayHint, InlayHintsConfig, InlayKind},
|
||||
markup::Markup,
|
||||
references::{Declaration, Reference, ReferenceAccess, ReferenceKind, ReferenceSearchResult},
|
||||
runnables::{Runnable, RunnableKind, TestId},
|
||||
syntax_highlighting::{
|
||||
|
|
38
crates/ra_ide/src/markup.rs
Normal file
38
crates/ra_ide/src/markup.rs
Normal file
|
@ -0,0 +1,38 @@
|
|||
//! Markdown formatting.
|
||||
//!
|
||||
//! Sometimes, we want to display a "rich text" in the UI. At the moment, we use
|
||||
//! markdown for this purpose. It doesn't feel like a right option, but that's
|
||||
//! what is used by LSP, so let's keep it simple.
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Default, Debug)]
|
||||
pub struct Markup {
|
||||
text: String,
|
||||
}
|
||||
|
||||
impl From<Markup> for String {
|
||||
fn from(markup: Markup) -> Self {
|
||||
markup.text
|
||||
}
|
||||
}
|
||||
|
||||
impl fmt::Display for Markup {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
fmt::Display::fmt(&self.text, f)
|
||||
}
|
||||
}
|
||||
|
||||
impl Markup {
|
||||
pub fn as_str(&self) -> &str {
|
||||
self.text.as_str()
|
||||
}
|
||||
pub fn is_empty(&self) -> bool {
|
||||
self.text.is_empty()
|
||||
}
|
||||
pub fn push_section(&mut self, section: &str) {
|
||||
if !self.text.is_empty() {
|
||||
self.text.push_str("\n\n___\n");
|
||||
}
|
||||
self.text.push_str(section);
|
||||
}
|
||||
}
|
|
@ -12,10 +12,10 @@ use lsp_types::{
|
|||
CallHierarchyIncomingCall, CallHierarchyIncomingCallsParams, CallHierarchyItem,
|
||||
CallHierarchyOutgoingCall, CallHierarchyOutgoingCallsParams, CallHierarchyPrepareParams,
|
||||
CodeLens, Command, CompletionItem, Diagnostic, DocumentFormattingParams, DocumentHighlight,
|
||||
DocumentSymbol, FoldingRange, FoldingRangeParams, HoverContents, Location, MarkupContent,
|
||||
MarkupKind, Position, PrepareRenameResponse, Range, RenameParams, SemanticTokensParams,
|
||||
SemanticTokensRangeParams, SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation,
|
||||
TextDocumentIdentifier, Url, WorkspaceEdit,
|
||||
DocumentSymbol, FoldingRange, FoldingRangeParams, HoverContents, Location, Position,
|
||||
PrepareRenameResponse, Range, RenameParams, SemanticTokensParams, SemanticTokensRangeParams,
|
||||
SemanticTokensRangeResult, SemanticTokensResult, SymbolInformation, TextDocumentIdentifier,
|
||||
Url, WorkspaceEdit,
|
||||
};
|
||||
use ra_ide::{
|
||||
FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, NavigationTarget, Query,
|
||||
|
@ -584,13 +584,10 @@ pub(crate) fn handle_hover(
|
|||
let range = to_proto::range(&line_index, info.range);
|
||||
let hover = lsp_ext::Hover {
|
||||
hover: lsp_types::Hover {
|
||||
contents: HoverContents::Markup(MarkupContent {
|
||||
kind: MarkupKind::Markdown,
|
||||
value: crate::markdown::format_docs(&info.info.to_markup()),
|
||||
}),
|
||||
contents: HoverContents::Markup(to_proto::markup_content(info.info.markup)),
|
||||
range: Some(range),
|
||||
},
|
||||
actions: prepare_hover_actions(&snap, position.file_id, info.info.actions()),
|
||||
actions: prepare_hover_actions(&snap, position.file_id, &info.info.actions),
|
||||
};
|
||||
|
||||
Ok(Some(hover))
|
||||
|
|
|
@ -6,8 +6,8 @@ use ra_db::{FileId, FileRange};
|
|||
use ra_ide::{
|
||||
Assist, AssistKind, CompletionItem, CompletionItemKind, Documentation, FileSystemEdit, Fold,
|
||||
FoldKind, FunctionSignature, Highlight, HighlightModifier, HighlightTag, HighlightedRange,
|
||||
Indel, InlayHint, InlayKind, InsertTextFormat, LineIndex, NavigationTarget, ReferenceAccess,
|
||||
ResolvedAssist, Runnable, Severity, SourceChange, SourceFileEdit, TextEdit,
|
||||
Indel, InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget,
|
||||
ReferenceAccess, ResolvedAssist, Runnable, Severity, SourceChange, SourceFileEdit, TextEdit,
|
||||
};
|
||||
use ra_syntax::{SyntaxKind, TextRange, TextSize};
|
||||
|
||||
|
@ -696,6 +696,10 @@ pub(crate) fn runnable(
|
|||
})
|
||||
}
|
||||
|
||||
pub(crate) fn markup_content(markup: Markup) -> lsp_types::MarkupContent {
|
||||
lsp_types::MarkupContent { kind: lsp_types::MarkupKind::Markdown, value: markup.into() }
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use ra_ide::Analysis;
|
||||
|
|
|
@ -9,8 +9,8 @@ use paths::{RelPath, RelPathBuf};
|
|||
///
|
||||
/// It describes the set of files inside some directory.
|
||||
///
|
||||
/// The current implementation is very limited, it allows white-listing file
|
||||
/// globs and black-listing directories.
|
||||
/// The current implementation is very limited, it allows including file globs
|
||||
/// and recursively excluding directories.
|
||||
#[derive(Debug, Clone)]
|
||||
pub(crate) struct Include {
|
||||
include_files: GlobSet,
|
||||
|
|
|
@ -50,18 +50,19 @@ fn rust_files_are_tidy() {
|
|||
}
|
||||
|
||||
fn check_todo(path: &Path, text: &str) {
|
||||
let whitelist = &[
|
||||
// This file itself is whitelisted since this test itself contains matches.
|
||||
let need_todo = &[
|
||||
// This file itself obviously needs to use todo (<- like this!).
|
||||
"tests/cli.rs",
|
||||
// Some of our assists generate `todo!()` so those files are whitelisted.
|
||||
// Some of our assists generate `todo!()`.
|
||||
"tests/generated.rs",
|
||||
"handlers/add_missing_impl_members.rs",
|
||||
"handlers/add_turbo_fish.rs",
|
||||
"handlers/generate_function.rs",
|
||||
// To support generating `todo!()` in assists, we have `expr_todo()` in ast::make.
|
||||
// To support generating `todo!()` in assists, we have `expr_todo()` in
|
||||
// `ast::make`.
|
||||
"ast/make.rs",
|
||||
];
|
||||
if whitelist.iter().any(|p| path.ends_with(p)) {
|
||||
if need_todo.iter().any(|p| path.ends_with(p)) {
|
||||
return;
|
||||
}
|
||||
if text.contains("TODO") || text.contains("TOOD") || text.contains("todo!") {
|
||||
|
@ -139,7 +140,7 @@ impl TidyDocs {
|
|||
)
|
||||
}
|
||||
|
||||
let whitelist = [
|
||||
let poorly_documented = [
|
||||
"ra_hir",
|
||||
"ra_hir_expand",
|
||||
"ra_ide",
|
||||
|
@ -153,9 +154,9 @@ impl TidyDocs {
|
|||
];
|
||||
|
||||
let mut has_fixmes =
|
||||
whitelist.iter().map(|it| (*it, false)).collect::<HashMap<&str, bool>>();
|
||||
poorly_documented.iter().map(|it| (*it, false)).collect::<HashMap<&str, bool>>();
|
||||
'outer: for path in self.contains_fixme {
|
||||
for krate in whitelist.iter() {
|
||||
for krate in poorly_documented.iter() {
|
||||
if path.components().any(|it| it.as_os_str() == *krate) {
|
||||
has_fixmes.insert(krate, true);
|
||||
continue 'outer;
|
||||
|
@ -166,7 +167,7 @@ impl TidyDocs {
|
|||
|
||||
for (krate, has_fixme) in has_fixmes.iter() {
|
||||
if !has_fixme {
|
||||
panic!("crate {} is fully documented, remove it from the white list", krate)
|
||||
panic!("crate {} is fully documented :tada:, remove it from the list of poorly documented crates", krate)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue