mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-27 04:19:13 +00:00
Merge #7353
7353: Add LifetimeParam and ConstParam to CompletionItemKind r=matklad a=Veykril Adds `LifetimeParam` and `ConstParam` to `CompletionItemKind` and maps them both to `TypeParam` in the protocol conversion as there are no equivalents, so nothing really changes there. `ConstParam` could be mapped to `Const` I guess but I'm split on whether that would be better? Additions were solely inspired by (the single) test output for const params. Also sorts the variants of `CompletionItemKind` and its to_proto match. Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
This commit is contained in:
commit
0c37b3a0fc
23 changed files with 227 additions and 166 deletions
|
@ -6,7 +6,7 @@ use syntax::{
|
||||||
match_ast, AstNode,
|
match_ast, AstNode,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{CompletionContext, CompletionItem, CompletionKind, Completions};
|
use crate::{CompletionContext, CompletionItem, CompletionItemKind, CompletionKind, Completions};
|
||||||
|
|
||||||
/// Complete repeated parameters, both name and type. For example, if all
|
/// Complete repeated parameters, both name and type. For example, if all
|
||||||
/// functions in a file have a `spam: &mut Spam` parameter, a completion with
|
/// functions in a file have a `spam: &mut Spam` parameter, a completion with
|
||||||
|
@ -58,7 +58,7 @@ pub(crate) fn complete_fn_param(acc: &mut Completions, ctx: &CompletionContext)
|
||||||
})
|
})
|
||||||
.for_each(|(label, lookup)| {
|
.for_each(|(label, lookup)| {
|
||||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
|
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), label)
|
||||||
.kind(crate::CompletionItemKind::Binding)
|
.kind(CompletionItemKind::Binding)
|
||||||
.lookup_by(lookup)
|
.lookup_by(lookup)
|
||||||
.add_to(acc)
|
.add_to(acc)
|
||||||
});
|
});
|
||||||
|
|
|
@ -3,11 +3,13 @@
|
||||||
use std::iter;
|
use std::iter;
|
||||||
|
|
||||||
use hir::{Module, ModuleSource};
|
use hir::{Module, ModuleSource};
|
||||||
use ide_db::base_db::{SourceDatabaseExt, VfsPath};
|
use ide_db::{
|
||||||
use ide_db::RootDatabase;
|
base_db::{SourceDatabaseExt, VfsPath},
|
||||||
|
RootDatabase, SymbolKind,
|
||||||
|
};
|
||||||
use rustc_hash::FxHashSet;
|
use rustc_hash::FxHashSet;
|
||||||
|
|
||||||
use crate::{CompletionItem, CompletionItemKind};
|
use crate::CompletionItem;
|
||||||
|
|
||||||
use crate::{context::CompletionContext, item::CompletionKind, Completions};
|
use crate::{context::CompletionContext, item::CompletionKind, Completions};
|
||||||
|
|
||||||
|
@ -79,7 +81,7 @@ pub(crate) fn complete_mod(acc: &mut Completions, ctx: &CompletionContext) -> Op
|
||||||
label.push(';');
|
label.push(';');
|
||||||
}
|
}
|
||||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label)
|
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), &label)
|
||||||
.kind(CompletionItemKind::Module)
|
.kind(SymbolKind::Module)
|
||||||
.add_to(acc)
|
.add_to(acc)
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
|
@ -1,10 +1,8 @@
|
||||||
//! Complete fields in record literals and patterns.
|
//! Complete fields in record literals and patterns.
|
||||||
use ide_db::helpers::FamousDefs;
|
use ide_db::{helpers::FamousDefs, SymbolKind};
|
||||||
use syntax::ast::Expr;
|
use syntax::ast::Expr;
|
||||||
|
|
||||||
use crate::{
|
use crate::{item::CompletionKind, CompletionContext, CompletionItem, Completions};
|
||||||
item::CompletionKind, CompletionContext, CompletionItem, CompletionItemKind, Completions,
|
|
||||||
};
|
|
||||||
|
|
||||||
pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) -> Option<()> {
|
||||||
let missing_fields = match (ctx.record_pat_syntax.as_ref(), ctx.record_lit_syntax.as_ref()) {
|
let missing_fields = match (ctx.record_pat_syntax.as_ref(), ctx.record_lit_syntax.as_ref()) {
|
||||||
|
@ -31,7 +29,7 @@ pub(crate) fn complete_record(acc: &mut Completions, ctx: &CompletionContext) ->
|
||||||
"..Default::default()",
|
"..Default::default()",
|
||||||
)
|
)
|
||||||
.insert_text(completion_text)
|
.insert_text(completion_text)
|
||||||
.kind(CompletionItemKind::Field)
|
.kind(SymbolKind::Field)
|
||||||
.build(),
|
.build(),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -32,7 +32,7 @@
|
||||||
//! ```
|
//! ```
|
||||||
|
|
||||||
use hir::{self, HasAttrs, HasSource};
|
use hir::{self, HasAttrs, HasSource};
|
||||||
use ide_db::traits::get_missing_assoc_items;
|
use ide_db::{traits::get_missing_assoc_items, SymbolKind};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, edit, Impl},
|
ast::{self, edit, Impl},
|
||||||
display::function_declaration,
|
display::function_declaration,
|
||||||
|
@ -152,7 +152,7 @@ fn add_function_impl(
|
||||||
let completion_kind = if func.self_param(ctx.db).is_some() {
|
let completion_kind = if func.self_param(ctx.db).is_some() {
|
||||||
CompletionItemKind::Method
|
CompletionItemKind::Method
|
||||||
} else {
|
} else {
|
||||||
CompletionItemKind::Function
|
CompletionItemKind::SymbolKind(SymbolKind::Function)
|
||||||
};
|
};
|
||||||
let range = TextRange::new(fn_def_node.text_range().start(), ctx.source_range().end());
|
let range = TextRange::new(fn_def_node.text_range().start(), ctx.source_range().end());
|
||||||
|
|
||||||
|
@ -188,7 +188,7 @@ fn add_type_alias_impl(
|
||||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
||||||
.text_edit(TextEdit::replace(range, snippet))
|
.text_edit(TextEdit::replace(range, snippet))
|
||||||
.lookup_by(alias_name)
|
.lookup_by(alias_name)
|
||||||
.kind(CompletionItemKind::TypeAlias)
|
.kind(SymbolKind::TypeAlias)
|
||||||
.set_documentation(type_alias.docs(ctx.db))
|
.set_documentation(type_alias.docs(ctx.db))
|
||||||
.add_to(acc);
|
.add_to(acc);
|
||||||
}
|
}
|
||||||
|
@ -211,7 +211,7 @@ fn add_const_impl(
|
||||||
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
CompletionItem::new(CompletionKind::Magic, ctx.source_range(), snippet.clone())
|
||||||
.text_edit(TextEdit::replace(range, snippet))
|
.text_edit(TextEdit::replace(range, snippet))
|
||||||
.lookup_by(const_name)
|
.lookup_by(const_name)
|
||||||
.kind(CompletionItemKind::Const)
|
.kind(SymbolKind::Const)
|
||||||
.set_documentation(const_.docs(ctx.db))
|
.set_documentation(const_.docs(ctx.db))
|
||||||
.add_to(acc);
|
.add_to(acc);
|
||||||
}
|
}
|
||||||
|
|
|
@ -165,8 +165,8 @@ fn quux(x: i32) {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
bn y i32
|
lc y i32
|
||||||
bn x i32
|
lc x i32
|
||||||
fn quux(…) fn quux(x: i32)
|
fn quux(…) fn quux(x: i32)
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -187,8 +187,8 @@ fn quux() {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
bn b i32
|
lc b i32
|
||||||
bn a
|
lc a
|
||||||
fn quux() fn quux()
|
fn quux() fn quux()
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -203,7 +203,7 @@ fn quux() {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
bn x
|
lc x
|
||||||
fn quux() fn quux()
|
fn quux() fn quux()
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -241,7 +241,7 @@ fn main() {
|
||||||
check(
|
check(
|
||||||
r#"fn quux<const C: usize>() { $0 }"#,
|
r#"fn quux<const C: usize>() { $0 }"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
tp C
|
cp C
|
||||||
fn quux() fn quux<const C: usize>()
|
fn quux() fn quux<const C: usize>()
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -263,7 +263,7 @@ fn main() {
|
||||||
check(
|
check(
|
||||||
r#"struct S<T> { x: $0}"#,
|
r#"struct S<T> { x: $0}"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
tp Self
|
sp Self
|
||||||
tp T
|
tp T
|
||||||
st S<…>
|
st S<…>
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -275,7 +275,7 @@ fn main() {
|
||||||
check(
|
check(
|
||||||
r#"enum X { Y($0) }"#,
|
r#"enum X { Y($0) }"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
tp Self
|
sp Self
|
||||||
en X
|
en X
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -378,8 +378,8 @@ fn foo() {
|
||||||
"#,
|
"#,
|
||||||
// FIXME: should be only one bar here
|
// FIXME: should be only one bar here
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
bn bar i32
|
lc bar i32
|
||||||
bn bar i32
|
lc bar i32
|
||||||
fn foo() fn foo()
|
fn foo() fn foo()
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
|
@ -390,8 +390,8 @@ fn foo() {
|
||||||
check(
|
check(
|
||||||
r#"impl S { fn foo(&self) { $0 } }"#,
|
r#"impl S { fn foo(&self) { $0 } }"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
bn self &{unknown}
|
lc self &{unknown}
|
||||||
tp Self
|
sp Self
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -575,8 +575,8 @@ fn quux(x: i32) {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
bn y i32
|
lc y i32
|
||||||
bn x i32
|
lc x i32
|
||||||
fn quux(…) fn quux(x: i32)
|
fn quux(…) fn quux(x: i32)
|
||||||
ma m!(…) macro_rules! m
|
ma m!(…) macro_rules! m
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -594,8 +594,8 @@ fn quux(x: i32) {
|
||||||
}
|
}
|
||||||
",
|
",
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
bn y i32
|
lc y i32
|
||||||
bn x i32
|
lc x i32
|
||||||
fn quux(…) fn quux(x: i32)
|
fn quux(…) fn quux(x: i32)
|
||||||
ma m!(…) macro_rules! m
|
ma m!(…) macro_rules! m
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -613,8 +613,8 @@ fn quux(x: i32) {
|
||||||
}
|
}
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
bn y i32
|
lc y i32
|
||||||
bn x i32
|
lc x i32
|
||||||
fn quux(…) fn quux(x: i32)
|
fn quux(…) fn quux(x: i32)
|
||||||
ma m!(…) macro_rules! m
|
ma m!(…) macro_rules! m
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -750,7 +750,7 @@ struct MyStruct {}
|
||||||
impl My$0
|
impl My$0
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
tp Self
|
sp Self
|
||||||
tt MyTrait
|
tt MyTrait
|
||||||
st MyStruct
|
st MyStruct
|
||||||
"#]],
|
"#]],
|
||||||
|
|
|
@ -3,11 +3,14 @@
|
||||||
use std::fmt;
|
use std::fmt;
|
||||||
|
|
||||||
use hir::{Documentation, ModPath, Mutability};
|
use hir::{Documentation, ModPath, Mutability};
|
||||||
use ide_db::helpers::{
|
use ide_db::{
|
||||||
insert_use::{self, ImportScope, MergeBehavior},
|
helpers::{
|
||||||
mod_path_to_ast, SnippetCap,
|
insert_use::{self, ImportScope, MergeBehavior},
|
||||||
|
mod_path_to_ast, SnippetCap,
|
||||||
|
},
|
||||||
|
SymbolKind,
|
||||||
};
|
};
|
||||||
use stdx::assert_never;
|
use stdx::{assert_never, impl_from};
|
||||||
use syntax::{algo, TextRange};
|
use syntax::{algo, TextRange};
|
||||||
use text_edit::TextEdit;
|
use text_edit::TextEdit;
|
||||||
|
|
||||||
|
@ -117,49 +120,50 @@ pub enum CompletionScore {
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||||
pub enum CompletionItemKind {
|
pub enum CompletionItemKind {
|
||||||
Snippet,
|
SymbolKind(SymbolKind),
|
||||||
Keyword,
|
|
||||||
Module,
|
|
||||||
Function,
|
|
||||||
BuiltinType,
|
|
||||||
Struct,
|
|
||||||
Enum,
|
|
||||||
EnumVariant,
|
|
||||||
Binding,
|
|
||||||
Field,
|
|
||||||
Static,
|
|
||||||
Const,
|
|
||||||
Trait,
|
|
||||||
TypeAlias,
|
|
||||||
Method,
|
|
||||||
TypeParam,
|
|
||||||
Macro,
|
|
||||||
Attribute,
|
Attribute,
|
||||||
|
Binding,
|
||||||
|
BuiltinType,
|
||||||
|
Keyword,
|
||||||
|
Method,
|
||||||
|
Snippet,
|
||||||
UnresolvedReference,
|
UnresolvedReference,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl_from!(SymbolKind for CompletionItemKind);
|
||||||
|
|
||||||
impl CompletionItemKind {
|
impl CompletionItemKind {
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
pub(crate) fn tag(&self) -> &'static str {
|
pub(crate) fn tag(&self) -> &'static str {
|
||||||
match self {
|
match self {
|
||||||
|
CompletionItemKind::SymbolKind(kind) => match kind {
|
||||||
|
SymbolKind::Const => "ct",
|
||||||
|
SymbolKind::ConstParam => "cp",
|
||||||
|
SymbolKind::Enum => "en",
|
||||||
|
SymbolKind::Field => "fd",
|
||||||
|
SymbolKind::Function => "fn",
|
||||||
|
SymbolKind::Impl => "im",
|
||||||
|
SymbolKind::Label => "lb",
|
||||||
|
SymbolKind::LifetimeParam => "lt",
|
||||||
|
SymbolKind::Local => "lc",
|
||||||
|
SymbolKind::Macro => "ma",
|
||||||
|
SymbolKind::Module => "md",
|
||||||
|
SymbolKind::SelfParam => "sp",
|
||||||
|
SymbolKind::Static => "sc",
|
||||||
|
SymbolKind::Struct => "st",
|
||||||
|
SymbolKind::Trait => "tt",
|
||||||
|
SymbolKind::TypeAlias => "ta",
|
||||||
|
SymbolKind::TypeParam => "tp",
|
||||||
|
SymbolKind::Union => "un",
|
||||||
|
SymbolKind::ValueParam => "vp",
|
||||||
|
SymbolKind::Variant => "ev",
|
||||||
|
},
|
||||||
CompletionItemKind::Attribute => "at",
|
CompletionItemKind::Attribute => "at",
|
||||||
CompletionItemKind::Binding => "bn",
|
CompletionItemKind::Binding => "bn",
|
||||||
CompletionItemKind::BuiltinType => "bt",
|
CompletionItemKind::BuiltinType => "bt",
|
||||||
CompletionItemKind::Const => "ct",
|
|
||||||
CompletionItemKind::Enum => "en",
|
|
||||||
CompletionItemKind::EnumVariant => "ev",
|
|
||||||
CompletionItemKind::Field => "fd",
|
|
||||||
CompletionItemKind::Function => "fn",
|
|
||||||
CompletionItemKind::Keyword => "kw",
|
CompletionItemKind::Keyword => "kw",
|
||||||
CompletionItemKind::Macro => "ma",
|
|
||||||
CompletionItemKind::Method => "me",
|
CompletionItemKind::Method => "me",
|
||||||
CompletionItemKind::Module => "md",
|
|
||||||
CompletionItemKind::Snippet => "sn",
|
CompletionItemKind::Snippet => "sn",
|
||||||
CompletionItemKind::Static => "sc",
|
|
||||||
CompletionItemKind::Struct => "st",
|
|
||||||
CompletionItemKind::Trait => "tt",
|
|
||||||
CompletionItemKind::TypeAlias => "ta",
|
|
||||||
CompletionItemKind::TypeParam => "tp",
|
|
||||||
CompletionItemKind::UnresolvedReference => "??",
|
CompletionItemKind::UnresolvedReference => "??",
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -382,8 +386,8 @@ impl Builder {
|
||||||
self.insert_text_format = InsertTextFormat::Snippet;
|
self.insert_text_format = InsertTextFormat::Snippet;
|
||||||
self.insert_text(snippet)
|
self.insert_text(snippet)
|
||||||
}
|
}
|
||||||
pub(crate) fn kind(mut self, kind: CompletionItemKind) -> Builder {
|
pub(crate) fn kind(mut self, kind: impl Into<CompletionItemKind>) -> Builder {
|
||||||
self.kind = Some(kind);
|
self.kind = Some(kind.into());
|
||||||
self
|
self
|
||||||
}
|
}
|
||||||
pub(crate) fn text_edit(mut self, edit: TextEdit) -> Builder {
|
pub(crate) fn text_edit(mut self, edit: TextEdit) -> Builder {
|
||||||
|
|
|
@ -13,7 +13,7 @@ mod builder_ext;
|
||||||
use hir::{
|
use hir::{
|
||||||
AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type,
|
AsAssocItem, Documentation, HasAttrs, HirDisplay, ModuleDef, Mutability, ScopeDef, Type,
|
||||||
};
|
};
|
||||||
use ide_db::{helpers::SnippetCap, RootDatabase};
|
use ide_db::{helpers::SnippetCap, RootDatabase, SymbolKind};
|
||||||
use syntax::TextRange;
|
use syntax::TextRange;
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
|
@ -146,7 +146,7 @@ impl<'a> Render<'a> {
|
||||||
self.ctx.source_range(),
|
self.ctx.source_range(),
|
||||||
name.to_string(),
|
name.to_string(),
|
||||||
)
|
)
|
||||||
.kind(CompletionItemKind::Field)
|
.kind(SymbolKind::Field)
|
||||||
.detail(ty.display(self.ctx.db()).to_string())
|
.detail(ty.display(self.ctx.db()).to_string())
|
||||||
.set_documentation(field.docs(self.ctx.db()))
|
.set_documentation(field.docs(self.ctx.db()))
|
||||||
.set_deprecated(is_deprecated);
|
.set_deprecated(is_deprecated);
|
||||||
|
@ -160,7 +160,7 @@ impl<'a> Render<'a> {
|
||||||
|
|
||||||
fn add_tuple_field(&mut self, field: usize, ty: &Type) -> CompletionItem {
|
fn add_tuple_field(&mut self, field: usize, ty: &Type) -> CompletionItem {
|
||||||
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), field.to_string())
|
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), field.to_string())
|
||||||
.kind(CompletionItemKind::Field)
|
.kind(SymbolKind::Field)
|
||||||
.detail(ty.display(self.ctx.db()).to_string())
|
.detail(ty.display(self.ctx.db()).to_string())
|
||||||
.build()
|
.build()
|
||||||
}
|
}
|
||||||
|
@ -187,7 +187,7 @@ impl<'a> Render<'a> {
|
||||||
if self.ctx.completion.is_pat_binding_or_const
|
if self.ctx.completion.is_pat_binding_or_const
|
||||||
| self.ctx.completion.is_irrefutable_pat_binding =>
|
| self.ctx.completion.is_irrefutable_pat_binding =>
|
||||||
{
|
{
|
||||||
CompletionItemKind::EnumVariant
|
CompletionItemKind::SymbolKind(SymbolKind::Variant)
|
||||||
}
|
}
|
||||||
ScopeDef::ModuleDef(Variant(var)) => {
|
ScopeDef::ModuleDef(Variant(var)) => {
|
||||||
let item = render_variant(self.ctx, import_to_add, Some(local_name), *var, None);
|
let item = render_variant(self.ctx, import_to_add, Some(local_name), *var, None);
|
||||||
|
@ -198,20 +198,29 @@ impl<'a> Render<'a> {
|
||||||
return item;
|
return item;
|
||||||
}
|
}
|
||||||
|
|
||||||
ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::Module,
|
ScopeDef::ModuleDef(Module(..)) => CompletionItemKind::SymbolKind(SymbolKind::Module),
|
||||||
ScopeDef::ModuleDef(Adt(hir::Adt::Struct(_))) => CompletionItemKind::Struct,
|
ScopeDef::ModuleDef(Adt(adt)) => CompletionItemKind::SymbolKind(match adt {
|
||||||
// FIXME: add CompletionItemKind::Union
|
hir::Adt::Struct(_) => SymbolKind::Struct,
|
||||||
ScopeDef::ModuleDef(Adt(hir::Adt::Union(_))) => CompletionItemKind::Struct,
|
// FIXME: add CompletionItemKind::Union
|
||||||
ScopeDef::ModuleDef(Adt(hir::Adt::Enum(_))) => CompletionItemKind::Enum,
|
hir::Adt::Union(_) => SymbolKind::Struct,
|
||||||
ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::Const,
|
hir::Adt::Enum(_) => SymbolKind::Enum,
|
||||||
ScopeDef::ModuleDef(Static(..)) => CompletionItemKind::Static,
|
}),
|
||||||
ScopeDef::ModuleDef(Trait(..)) => CompletionItemKind::Trait,
|
ScopeDef::ModuleDef(Const(..)) => CompletionItemKind::SymbolKind(SymbolKind::Const),
|
||||||
ScopeDef::ModuleDef(TypeAlias(..)) => CompletionItemKind::TypeAlias,
|
ScopeDef::ModuleDef(Static(..)) => CompletionItemKind::SymbolKind(SymbolKind::Static),
|
||||||
|
ScopeDef::ModuleDef(Trait(..)) => CompletionItemKind::SymbolKind(SymbolKind::Trait),
|
||||||
|
ScopeDef::ModuleDef(TypeAlias(..)) => {
|
||||||
|
CompletionItemKind::SymbolKind(SymbolKind::TypeAlias)
|
||||||
|
}
|
||||||
ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
|
ScopeDef::ModuleDef(BuiltinType(..)) => CompletionItemKind::BuiltinType,
|
||||||
ScopeDef::GenericParam(..) => CompletionItemKind::TypeParam,
|
ScopeDef::GenericParam(param) => CompletionItemKind::SymbolKind(match param {
|
||||||
ScopeDef::Local(..) => CompletionItemKind::Binding,
|
hir::GenericParam::TypeParam(_) => SymbolKind::TypeParam,
|
||||||
// (does this need its own kind?)
|
hir::GenericParam::LifetimeParam(_) => SymbolKind::LifetimeParam,
|
||||||
ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => CompletionItemKind::TypeParam,
|
hir::GenericParam::ConstParam(_) => SymbolKind::ConstParam,
|
||||||
|
}),
|
||||||
|
ScopeDef::Local(..) => CompletionItemKind::SymbolKind(SymbolKind::Local),
|
||||||
|
ScopeDef::AdtSelfType(..) | ScopeDef::ImplSelfType(..) => {
|
||||||
|
CompletionItemKind::SymbolKind(SymbolKind::SelfParam)
|
||||||
|
}
|
||||||
ScopeDef::Unknown => {
|
ScopeDef::Unknown => {
|
||||||
let item = CompletionItem::new(
|
let item = CompletionItem::new(
|
||||||
CompletionKind::Reference,
|
CompletionKind::Reference,
|
||||||
|
@ -400,7 +409,9 @@ fn main() { Foo::Fo$0 }
|
||||||
source_range: 54..56,
|
source_range: 54..56,
|
||||||
delete: 54..56,
|
delete: 54..56,
|
||||||
insert: "Foo",
|
insert: "Foo",
|
||||||
kind: EnumVariant,
|
kind: SymbolKind(
|
||||||
|
Variant,
|
||||||
|
),
|
||||||
detail: "{ x: i32, y: i32 }",
|
detail: "{ x: i32, y: i32 }",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -423,7 +434,9 @@ fn main() { Foo::Fo$0 }
|
||||||
source_range: 46..48,
|
source_range: 46..48,
|
||||||
delete: 46..48,
|
delete: 46..48,
|
||||||
insert: "Foo($0)",
|
insert: "Foo($0)",
|
||||||
kind: EnumVariant,
|
kind: SymbolKind(
|
||||||
|
Variant,
|
||||||
|
),
|
||||||
lookup: "Foo",
|
lookup: "Foo",
|
||||||
detail: "(i32, i32)",
|
detail: "(i32, i32)",
|
||||||
trigger_call_info: true,
|
trigger_call_info: true,
|
||||||
|
@ -448,7 +461,9 @@ fn main() { Foo::Fo$0 }
|
||||||
source_range: 35..37,
|
source_range: 35..37,
|
||||||
delete: 35..37,
|
delete: 35..37,
|
||||||
insert: "Foo",
|
insert: "Foo",
|
||||||
kind: EnumVariant,
|
kind: SymbolKind(
|
||||||
|
Variant,
|
||||||
|
),
|
||||||
detail: "()",
|
detail: "()",
|
||||||
},
|
},
|
||||||
]
|
]
|
||||||
|
@ -472,7 +487,9 @@ fn main() { let _: m::Spam = S$0 }
|
||||||
source_range: 75..76,
|
source_range: 75..76,
|
||||||
delete: 75..76,
|
delete: 75..76,
|
||||||
insert: "Spam::Bar($0)",
|
insert: "Spam::Bar($0)",
|
||||||
kind: EnumVariant,
|
kind: SymbolKind(
|
||||||
|
Variant,
|
||||||
|
),
|
||||||
lookup: "Spam::Bar",
|
lookup: "Spam::Bar",
|
||||||
detail: "(i32)",
|
detail: "(i32)",
|
||||||
trigger_call_info: true,
|
trigger_call_info: true,
|
||||||
|
@ -482,14 +499,18 @@ fn main() { let _: m::Spam = S$0 }
|
||||||
source_range: 75..76,
|
source_range: 75..76,
|
||||||
delete: 75..76,
|
delete: 75..76,
|
||||||
insert: "m",
|
insert: "m",
|
||||||
kind: Module,
|
kind: SymbolKind(
|
||||||
|
Module,
|
||||||
|
),
|
||||||
},
|
},
|
||||||
CompletionItem {
|
CompletionItem {
|
||||||
label: "m::Spam::Foo",
|
label: "m::Spam::Foo",
|
||||||
source_range: 75..76,
|
source_range: 75..76,
|
||||||
delete: 75..76,
|
delete: 75..76,
|
||||||
insert: "m::Spam::Foo",
|
insert: "m::Spam::Foo",
|
||||||
kind: EnumVariant,
|
kind: SymbolKind(
|
||||||
|
Variant,
|
||||||
|
),
|
||||||
lookup: "Spam::Foo",
|
lookup: "Spam::Foo",
|
||||||
detail: "()",
|
detail: "()",
|
||||||
},
|
},
|
||||||
|
@ -498,7 +519,9 @@ fn main() { let _: m::Spam = S$0 }
|
||||||
source_range: 75..76,
|
source_range: 75..76,
|
||||||
delete: 75..76,
|
delete: 75..76,
|
||||||
insert: "main()$0",
|
insert: "main()$0",
|
||||||
kind: Function,
|
kind: SymbolKind(
|
||||||
|
Function,
|
||||||
|
),
|
||||||
lookup: "main",
|
lookup: "main",
|
||||||
detail: "fn main()",
|
detail: "fn main()",
|
||||||
},
|
},
|
||||||
|
@ -525,7 +548,9 @@ fn main() { som$0 }
|
||||||
source_range: 127..130,
|
source_range: 127..130,
|
||||||
delete: 127..130,
|
delete: 127..130,
|
||||||
insert: "main()$0",
|
insert: "main()$0",
|
||||||
kind: Function,
|
kind: SymbolKind(
|
||||||
|
Function,
|
||||||
|
),
|
||||||
lookup: "main",
|
lookup: "main",
|
||||||
detail: "fn main()",
|
detail: "fn main()",
|
||||||
},
|
},
|
||||||
|
@ -534,7 +559,9 @@ fn main() { som$0 }
|
||||||
source_range: 127..130,
|
source_range: 127..130,
|
||||||
delete: 127..130,
|
delete: 127..130,
|
||||||
insert: "something_deprecated()$0",
|
insert: "something_deprecated()$0",
|
||||||
kind: Function,
|
kind: SymbolKind(
|
||||||
|
Function,
|
||||||
|
),
|
||||||
lookup: "something_deprecated",
|
lookup: "something_deprecated",
|
||||||
detail: "fn something_deprecated()",
|
detail: "fn something_deprecated()",
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
|
@ -544,7 +571,9 @@ fn main() { som$0 }
|
||||||
source_range: 127..130,
|
source_range: 127..130,
|
||||||
delete: 127..130,
|
delete: 127..130,
|
||||||
insert: "something_else_deprecated()$0",
|
insert: "something_else_deprecated()$0",
|
||||||
kind: Function,
|
kind: SymbolKind(
|
||||||
|
Function,
|
||||||
|
),
|
||||||
lookup: "something_else_deprecated",
|
lookup: "something_else_deprecated",
|
||||||
detail: "fn something_else_deprecated()",
|
detail: "fn something_else_deprecated()",
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
|
@ -565,7 +594,9 @@ fn foo() { A { the$0 } }
|
||||||
source_range: 57..60,
|
source_range: 57..60,
|
||||||
delete: 57..60,
|
delete: 57..60,
|
||||||
insert: "the_field",
|
insert: "the_field",
|
||||||
kind: Field,
|
kind: SymbolKind(
|
||||||
|
Field,
|
||||||
|
),
|
||||||
detail: "u32",
|
detail: "u32",
|
||||||
deprecated: true,
|
deprecated: true,
|
||||||
},
|
},
|
||||||
|
@ -605,7 +636,9 @@ impl S {
|
||||||
source_range: 94..94,
|
source_range: 94..94,
|
||||||
delete: 94..94,
|
delete: 94..94,
|
||||||
insert: "foo",
|
insert: "foo",
|
||||||
kind: Field,
|
kind: SymbolKind(
|
||||||
|
Field,
|
||||||
|
),
|
||||||
detail: "{unknown}",
|
detail: "{unknown}",
|
||||||
documentation: Documentation(
|
documentation: Documentation(
|
||||||
"Field docs",
|
"Field docs",
|
||||||
|
@ -636,7 +669,9 @@ use self::E::*;
|
||||||
source_range: 10..12,
|
source_range: 10..12,
|
||||||
delete: 10..12,
|
delete: 10..12,
|
||||||
insert: "E",
|
insert: "E",
|
||||||
kind: Enum,
|
kind: SymbolKind(
|
||||||
|
Enum,
|
||||||
|
),
|
||||||
documentation: Documentation(
|
documentation: Documentation(
|
||||||
"enum docs",
|
"enum docs",
|
||||||
),
|
),
|
||||||
|
@ -646,7 +681,9 @@ use self::E::*;
|
||||||
source_range: 10..12,
|
source_range: 10..12,
|
||||||
delete: 10..12,
|
delete: 10..12,
|
||||||
insert: "V",
|
insert: "V",
|
||||||
kind: EnumVariant,
|
kind: SymbolKind(
|
||||||
|
Variant,
|
||||||
|
),
|
||||||
detail: "()",
|
detail: "()",
|
||||||
documentation: Documentation(
|
documentation: Documentation(
|
||||||
"variant docs",
|
"variant docs",
|
||||||
|
@ -657,7 +694,9 @@ use self::E::*;
|
||||||
source_range: 10..12,
|
source_range: 10..12,
|
||||||
delete: 10..12,
|
delete: 10..12,
|
||||||
insert: "my",
|
insert: "my",
|
||||||
kind: Module,
|
kind: SymbolKind(
|
||||||
|
Module,
|
||||||
|
),
|
||||||
documentation: Documentation(
|
documentation: Documentation(
|
||||||
"mod docs",
|
"mod docs",
|
||||||
),
|
),
|
||||||
|
@ -883,7 +922,7 @@ struct WorldSnapshot { _f: () };
|
||||||
fn go(world: &WorldSnapshot) { go(w$0) }
|
fn go(world: &WorldSnapshot) { go(w$0) }
|
||||||
"#,
|
"#,
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
bn world [type+name]
|
lc world [type+name]
|
||||||
st WorldSnapshot []
|
st WorldSnapshot []
|
||||||
fn go(…) []
|
fn go(…) []
|
||||||
"#]],
|
"#]],
|
||||||
|
@ -900,7 +939,7 @@ fn f(foo: &Foo) { f(foo, w$0) }
|
||||||
expect![[r#"
|
expect![[r#"
|
||||||
st Foo []
|
st Foo []
|
||||||
fn f(…) []
|
fn f(…) []
|
||||||
bn foo []
|
lc foo []
|
||||||
"#]],
|
"#]],
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
//! Renderer for `const` fields.
|
//! Renderer for `const` fields.
|
||||||
|
|
||||||
use hir::HasSource;
|
use hir::HasSource;
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{Const, NameOwner},
|
ast::{Const, NameOwner},
|
||||||
display::const_label,
|
display::const_label,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
item::{CompletionItem, CompletionItemKind, CompletionKind},
|
item::{CompletionItem, CompletionKind},
|
||||||
render::RenderContext,
|
render::RenderContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ impl<'a> ConstRender<'a> {
|
||||||
let detail = self.detail();
|
let detail = self.detail();
|
||||||
|
|
||||||
let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name)
|
let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name)
|
||||||
.kind(CompletionItemKind::Const)
|
.kind(SymbolKind::Const)
|
||||||
.set_documentation(self.ctx.docs(self.const_))
|
.set_documentation(self.ctx.docs(self.const_))
|
||||||
.set_deprecated(
|
.set_deprecated(
|
||||||
self.ctx.is_deprecated(self.const_)
|
self.ctx.is_deprecated(self.const_)
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
//! Renderer for `enum` variants.
|
//! Renderer for `enum` variants.
|
||||||
|
|
||||||
use hir::{HasAttrs, HirDisplay, ModPath, StructKind};
|
use hir::{HasAttrs, HirDisplay, ModPath, StructKind};
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
item::{CompletionItem, CompletionItemKind, CompletionKind, ImportEdit},
|
item::{CompletionItem, CompletionKind, ImportEdit},
|
||||||
render::{builder_ext::Params, RenderContext},
|
render::{builder_ext::Params, RenderContext},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -60,7 +61,7 @@ impl<'a> EnumRender<'a> {
|
||||||
self.ctx.source_range(),
|
self.ctx.source_range(),
|
||||||
self.qualified_name.clone(),
|
self.qualified_name.clone(),
|
||||||
)
|
)
|
||||||
.kind(CompletionItemKind::EnumVariant)
|
.kind(SymbolKind::Variant)
|
||||||
.set_documentation(self.variant.docs(self.ctx.db()))
|
.set_documentation(self.variant.docs(self.ctx.db()))
|
||||||
.set_deprecated(self.ctx.is_deprecated(self.variant))
|
.set_deprecated(self.ctx.is_deprecated(self.variant))
|
||||||
.add_import(import_to_add)
|
.add_import(import_to_add)
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
//! Renderer for function calls.
|
//! Renderer for function calls.
|
||||||
|
|
||||||
use hir::{HasSource, Type};
|
use hir::{HasSource, Type};
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use syntax::{ast::Fn, display::function_declaration};
|
use syntax::{ast::Fn, display::function_declaration};
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
|
@ -105,7 +106,7 @@ impl<'a> FunctionRender<'a> {
|
||||||
if self.func.self_param(self.ctx.db()).is_some() {
|
if self.func.self_param(self.ctx.db()).is_some() {
|
||||||
CompletionItemKind::Method
|
CompletionItemKind::Method
|
||||||
} else {
|
} else {
|
||||||
CompletionItemKind::Function
|
SymbolKind::Function.into()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,11 +1,12 @@
|
||||||
//! Renderer for macro invocations.
|
//! Renderer for macro invocations.
|
||||||
|
|
||||||
use hir::{Documentation, HasSource};
|
use hir::{Documentation, HasSource};
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use syntax::display::macro_label;
|
use syntax::display::macro_label;
|
||||||
use test_utils::mark;
|
use test_utils::mark;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
item::{CompletionItem, CompletionItemKind, CompletionKind, ImportEdit},
|
item::{CompletionItem, CompletionKind, ImportEdit},
|
||||||
render::RenderContext,
|
render::RenderContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -41,7 +42,7 @@ impl<'a> MacroRender<'a> {
|
||||||
fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> {
|
fn render(&self, import_to_add: Option<ImportEdit>) -> Option<CompletionItem> {
|
||||||
let mut builder =
|
let mut builder =
|
||||||
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label())
|
CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), &self.label())
|
||||||
.kind(CompletionItemKind::Macro)
|
.kind(SymbolKind::Macro)
|
||||||
.set_documentation(self.docs.clone())
|
.set_documentation(self.docs.clone())
|
||||||
.set_deprecated(self.ctx.is_deprecated(self.macro_))
|
.set_deprecated(self.ctx.is_deprecated(self.macro_))
|
||||||
.add_import(import_to_add)
|
.add_import(import_to_add)
|
||||||
|
|
|
@ -1,13 +1,14 @@
|
||||||
//! Renderer for type aliases.
|
//! Renderer for type aliases.
|
||||||
|
|
||||||
use hir::HasSource;
|
use hir::HasSource;
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{NameOwner, TypeAlias},
|
ast::{NameOwner, TypeAlias},
|
||||||
display::type_label,
|
display::type_label,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
item::{CompletionItem, CompletionItemKind, CompletionKind},
|
item::{CompletionItem, CompletionKind},
|
||||||
render::RenderContext,
|
render::RenderContext,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -36,7 +37,7 @@ impl<'a> TypeAliasRender<'a> {
|
||||||
let detail = self.detail();
|
let detail = self.detail();
|
||||||
|
|
||||||
let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name)
|
let item = CompletionItem::new(CompletionKind::Reference, self.ctx.source_range(), name)
|
||||||
.kind(CompletionItemKind::TypeAlias)
|
.kind(SymbolKind::TypeAlias)
|
||||||
.set_documentation(self.ctx.docs(self.type_alias))
|
.set_documentation(self.ctx.docs(self.type_alias))
|
||||||
.set_deprecated(
|
.set_deprecated(
|
||||||
self.ctx.is_deprecated(self.type_alias)
|
self.ctx.is_deprecated(self.type_alias)
|
||||||
|
|
|
@ -7,6 +7,7 @@ use hir::{AssocItem, Documentation, FieldSource, HasAttrs, HasSource, InFile, Mo
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
base_db::{FileId, FileRange, SourceDatabase},
|
base_db::{FileId, FileRange, SourceDatabase},
|
||||||
symbol_index::FileSymbolKind,
|
symbol_index::FileSymbolKind,
|
||||||
|
SymbolKind,
|
||||||
};
|
};
|
||||||
use ide_db::{defs::Definition, RootDatabase};
|
use ide_db::{defs::Definition, RootDatabase};
|
||||||
use syntax::{
|
use syntax::{
|
||||||
|
@ -18,30 +19,6 @@ use crate::FileSymbol;
|
||||||
|
|
||||||
use super::short_label::ShortLabel;
|
use super::short_label::ShortLabel;
|
||||||
|
|
||||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
|
||||||
pub enum SymbolKind {
|
|
||||||
Module,
|
|
||||||
Impl,
|
|
||||||
Field,
|
|
||||||
TypeParam,
|
|
||||||
ConstParam,
|
|
||||||
LifetimeParam,
|
|
||||||
ValueParam,
|
|
||||||
SelfParam,
|
|
||||||
Local,
|
|
||||||
Label,
|
|
||||||
Function,
|
|
||||||
Const,
|
|
||||||
Static,
|
|
||||||
Struct,
|
|
||||||
Enum,
|
|
||||||
Variant,
|
|
||||||
Union,
|
|
||||||
TypeAlias,
|
|
||||||
Trait,
|
|
||||||
Macro,
|
|
||||||
}
|
|
||||||
|
|
||||||
/// `NavigationTarget` represents and element in the editor's UI which you can
|
/// `NavigationTarget` represents and element in the editor's UI which you can
|
||||||
/// click on to navigate to a particular piece of code.
|
/// click on to navigate to a particular piece of code.
|
||||||
///
|
///
|
||||||
|
|
|
@ -1,10 +1,9 @@
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AttrsOwner, GenericParamsOwner, NameOwner},
|
ast::{self, AttrsOwner, GenericParamsOwner, NameOwner},
|
||||||
match_ast, AstNode, SourceFile, SyntaxNode, TextRange, WalkEvent,
|
match_ast, AstNode, SourceFile, SyntaxNode, TextRange, WalkEvent,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::SymbolKind;
|
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
pub struct StructureNode {
|
pub struct StructureNode {
|
||||||
pub parent: Option<usize>,
|
pub parent: Option<usize>,
|
||||||
|
|
|
@ -65,7 +65,7 @@ use crate::display::ToNav;
|
||||||
pub use crate::{
|
pub use crate::{
|
||||||
call_hierarchy::CallItem,
|
call_hierarchy::CallItem,
|
||||||
diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity},
|
diagnostics::{Diagnostic, DiagnosticsConfig, Fix, Severity},
|
||||||
display::navigation_target::{NavigationTarget, SymbolKind},
|
display::navigation_target::NavigationTarget,
|
||||||
expand_macro::ExpandedMacro,
|
expand_macro::ExpandedMacro,
|
||||||
file_structure::StructureNode,
|
file_structure::StructureNode,
|
||||||
folding_ranges::{Fold, FoldKind},
|
folding_ranges::{Fold, FoldKind},
|
||||||
|
|
|
@ -3,7 +3,7 @@ use std::fmt;
|
||||||
use assists::utils::test_related_attribute;
|
use assists::utils::test_related_attribute;
|
||||||
use cfg::CfgExpr;
|
use cfg::CfgExpr;
|
||||||
use hir::{AsAssocItem, HasAttrs, HasSource, Semantics};
|
use hir::{AsAssocItem, HasAttrs, HasSource, Semantics};
|
||||||
use ide_db::{defs::Definition, RootDatabase};
|
use ide_db::{defs::Definition, RootDatabase, SymbolKind};
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, AstNode, AttrsOwner},
|
ast::{self, AstNode, AttrsOwner},
|
||||||
|
@ -13,7 +13,7 @@ use test_utils::mark;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
display::{ToNav, TryToNav},
|
display::{ToNav, TryToNav},
|
||||||
FileId, NavigationTarget, SymbolKind,
|
FileId, NavigationTarget,
|
||||||
};
|
};
|
||||||
|
|
||||||
#[derive(Debug, Clone)]
|
#[derive(Debug, Clone)]
|
||||||
|
|
|
@ -13,7 +13,7 @@ mod html;
|
||||||
mod tests;
|
mod tests;
|
||||||
|
|
||||||
use hir::{Name, Semantics};
|
use hir::{Name, Semantics};
|
||||||
use ide_db::RootDatabase;
|
use ide_db::{RootDatabase, SymbolKind};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, HasFormatSpecifier},
|
ast::{self, HasFormatSpecifier},
|
||||||
|
@ -27,7 +27,7 @@ use crate::{
|
||||||
format::highlight_format_string, highlights::Highlights,
|
format::highlight_format_string, highlights::Highlights,
|
||||||
macro_rules::MacroRulesHighlighter, tags::Highlight,
|
macro_rules::MacroRulesHighlighter, tags::Highlight,
|
||||||
},
|
},
|
||||||
FileId, HlMod, HlTag, SymbolKind,
|
FileId, HlMod, HlTag,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub(crate) use html::highlight_as_html;
|
pub(crate) use html::highlight_as_html;
|
||||||
|
|
|
@ -1,10 +1,11 @@
|
||||||
//! Syntax highlighting for format macro strings.
|
//! Syntax highlighting for format macro strings.
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
ast::{self, FormatSpecifier, HasFormatSpecifier},
|
ast::{self, FormatSpecifier, HasFormatSpecifier},
|
||||||
AstNode, AstToken, TextRange,
|
AstNode, AstToken, TextRange,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag, SymbolKind};
|
use crate::{syntax_highlighting::highlights::Highlights, HlRange, HlTag};
|
||||||
|
|
||||||
pub(super) fn highlight_format_string(
|
pub(super) fn highlight_format_string(
|
||||||
stack: &mut Highlights,
|
stack: &mut Highlights,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
use hir::{AsAssocItem, Semantics, VariantDef};
|
use hir::{AsAssocItem, Semantics, VariantDef};
|
||||||
use ide_db::{
|
use ide_db::{
|
||||||
defs::{Definition, NameClass, NameRefClass},
|
defs::{Definition, NameClass, NameRefClass},
|
||||||
RootDatabase,
|
RootDatabase, SymbolKind,
|
||||||
};
|
};
|
||||||
use rustc_hash::FxHashMap;
|
use rustc_hash::FxHashMap;
|
||||||
use syntax::{
|
use syntax::{
|
||||||
|
@ -12,7 +12,7 @@ use syntax::{
|
||||||
SyntaxNode, SyntaxToken, T,
|
SyntaxNode, SyntaxToken, T,
|
||||||
};
|
};
|
||||||
|
|
||||||
use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag, SymbolKind};
|
use crate::{syntax_highlighting::tags::HlPunct, Highlight, HlMod, HlTag};
|
||||||
|
|
||||||
pub(super) fn element(
|
pub(super) fn element(
|
||||||
sema: &Semantics<RootDatabase>,
|
sema: &Semantics<RootDatabase>,
|
||||||
|
|
|
@ -3,7 +3,7 @@
|
||||||
|
|
||||||
use std::{fmt, ops};
|
use std::{fmt, ops};
|
||||||
|
|
||||||
use crate::SymbolKind;
|
use ide_db::SymbolKind;
|
||||||
|
|
||||||
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
pub struct Highlight {
|
pub struct Highlight {
|
||||||
|
|
|
@ -134,3 +134,27 @@ fn line_index(db: &dyn LineIndexDatabase, file_id: FileId) -> Arc<LineIndex> {
|
||||||
let text = db.file_text(file_id);
|
let text = db.file_text(file_id);
|
||||||
Arc::new(LineIndex::new(&*text))
|
Arc::new(LineIndex::new(&*text))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, PartialOrd, Ord)]
|
||||||
|
pub enum SymbolKind {
|
||||||
|
Const,
|
||||||
|
ConstParam,
|
||||||
|
Enum,
|
||||||
|
Field,
|
||||||
|
Function,
|
||||||
|
Impl,
|
||||||
|
Label,
|
||||||
|
LifetimeParam,
|
||||||
|
Local,
|
||||||
|
Macro,
|
||||||
|
Module,
|
||||||
|
SelfParam,
|
||||||
|
Static,
|
||||||
|
Struct,
|
||||||
|
Trait,
|
||||||
|
TypeAlias,
|
||||||
|
TypeParam,
|
||||||
|
Union,
|
||||||
|
ValueParam,
|
||||||
|
Variant,
|
||||||
|
}
|
||||||
|
|
|
@ -10,8 +10,9 @@ use std::{
|
||||||
|
|
||||||
use ide::{
|
use ide::{
|
||||||
FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, LineIndex, NavigationTarget,
|
FileId, FilePosition, FileRange, HoverAction, HoverGotoTypeData, LineIndex, NavigationTarget,
|
||||||
Query, RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, SymbolKind, TextEdit,
|
Query, RangeInfo, Runnable, RunnableKind, SearchScope, SourceChange, TextEdit,
|
||||||
};
|
};
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
use lsp_server::ErrorCode;
|
use lsp_server::ErrorCode;
|
||||||
use lsp_types::{
|
use lsp_types::{
|
||||||
|
|
|
@ -8,8 +8,9 @@ use ide::{
|
||||||
Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId,
|
Assist, AssistKind, CallInfo, CompletionItem, CompletionItemKind, Documentation, FileId,
|
||||||
FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlPunct, HlRange, HlTag, Indel,
|
FileRange, FileSystemEdit, Fold, FoldKind, Highlight, HlMod, HlPunct, HlRange, HlTag, Indel,
|
||||||
InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess,
|
InlayHint, InlayKind, InsertTextFormat, LineIndex, Markup, NavigationTarget, ReferenceAccess,
|
||||||
RenameError, Runnable, Severity, SourceChange, SymbolKind, TextEdit, TextRange, TextSize,
|
RenameError, Runnable, Severity, SourceChange, TextEdit, TextRange, TextSize,
|
||||||
};
|
};
|
||||||
|
use ide_db::SymbolKind;
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
|
@ -87,25 +88,35 @@ pub(crate) fn completion_item_kind(
|
||||||
completion_item_kind: CompletionItemKind,
|
completion_item_kind: CompletionItemKind,
|
||||||
) -> lsp_types::CompletionItemKind {
|
) -> lsp_types::CompletionItemKind {
|
||||||
match completion_item_kind {
|
match completion_item_kind {
|
||||||
CompletionItemKind::Keyword => lsp_types::CompletionItemKind::Keyword,
|
|
||||||
CompletionItemKind::Snippet => lsp_types::CompletionItemKind::Snippet,
|
|
||||||
CompletionItemKind::Module => lsp_types::CompletionItemKind::Module,
|
|
||||||
CompletionItemKind::Function => lsp_types::CompletionItemKind::Function,
|
|
||||||
CompletionItemKind::Struct => lsp_types::CompletionItemKind::Struct,
|
|
||||||
CompletionItemKind::Enum => lsp_types::CompletionItemKind::Enum,
|
|
||||||
CompletionItemKind::EnumVariant => lsp_types::CompletionItemKind::EnumMember,
|
|
||||||
CompletionItemKind::BuiltinType => lsp_types::CompletionItemKind::Struct,
|
|
||||||
CompletionItemKind::Binding => lsp_types::CompletionItemKind::Variable,
|
|
||||||
CompletionItemKind::Field => lsp_types::CompletionItemKind::Field,
|
|
||||||
CompletionItemKind::Trait => lsp_types::CompletionItemKind::Interface,
|
|
||||||
CompletionItemKind::TypeAlias => lsp_types::CompletionItemKind::Struct,
|
|
||||||
CompletionItemKind::Const => lsp_types::CompletionItemKind::Constant,
|
|
||||||
CompletionItemKind::Static => lsp_types::CompletionItemKind::Value,
|
|
||||||
CompletionItemKind::Method => lsp_types::CompletionItemKind::Method,
|
|
||||||
CompletionItemKind::TypeParam => lsp_types::CompletionItemKind::TypeParameter,
|
|
||||||
CompletionItemKind::Macro => lsp_types::CompletionItemKind::Method,
|
|
||||||
CompletionItemKind::Attribute => lsp_types::CompletionItemKind::EnumMember,
|
CompletionItemKind::Attribute => lsp_types::CompletionItemKind::EnumMember,
|
||||||
|
CompletionItemKind::Binding => lsp_types::CompletionItemKind::Variable,
|
||||||
|
CompletionItemKind::BuiltinType => lsp_types::CompletionItemKind::Struct,
|
||||||
|
CompletionItemKind::Keyword => lsp_types::CompletionItemKind::Keyword,
|
||||||
|
CompletionItemKind::Method => lsp_types::CompletionItemKind::Method,
|
||||||
|
CompletionItemKind::Snippet => lsp_types::CompletionItemKind::Snippet,
|
||||||
CompletionItemKind::UnresolvedReference => lsp_types::CompletionItemKind::Reference,
|
CompletionItemKind::UnresolvedReference => lsp_types::CompletionItemKind::Reference,
|
||||||
|
CompletionItemKind::SymbolKind(symbol) => match symbol {
|
||||||
|
SymbolKind::Const => lsp_types::CompletionItemKind::Constant,
|
||||||
|
SymbolKind::ConstParam => lsp_types::CompletionItemKind::TypeParameter,
|
||||||
|
SymbolKind::Enum => lsp_types::CompletionItemKind::Enum,
|
||||||
|
SymbolKind::Field => lsp_types::CompletionItemKind::Field,
|
||||||
|
SymbolKind::Function => lsp_types::CompletionItemKind::Function,
|
||||||
|
SymbolKind::Impl => lsp_types::CompletionItemKind::Text,
|
||||||
|
SymbolKind::Label => lsp_types::CompletionItemKind::Variable,
|
||||||
|
SymbolKind::LifetimeParam => lsp_types::CompletionItemKind::TypeParameter,
|
||||||
|
SymbolKind::Local => lsp_types::CompletionItemKind::Variable,
|
||||||
|
SymbolKind::Macro => lsp_types::CompletionItemKind::Method,
|
||||||
|
SymbolKind::Module => lsp_types::CompletionItemKind::Module,
|
||||||
|
SymbolKind::SelfParam => lsp_types::CompletionItemKind::Value,
|
||||||
|
SymbolKind::Static => lsp_types::CompletionItemKind::Value,
|
||||||
|
SymbolKind::Struct => lsp_types::CompletionItemKind::Struct,
|
||||||
|
SymbolKind::Trait => lsp_types::CompletionItemKind::Interface,
|
||||||
|
SymbolKind::TypeAlias => lsp_types::CompletionItemKind::Struct,
|
||||||
|
SymbolKind::TypeParam => lsp_types::CompletionItemKind::TypeParameter,
|
||||||
|
SymbolKind::Union => lsp_types::CompletionItemKind::Struct,
|
||||||
|
SymbolKind::ValueParam => lsp_types::CompletionItemKind::Value,
|
||||||
|
SymbolKind::Variant => lsp_types::CompletionItemKind::EnumMember,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue