Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
450 commits
Select commit Hold shift + click to select a range
7135008
Typo fix
Aug 3, 2020
e5430cd
Another typo fix
Aug 3, 2020
07d5806
Merge pull request #3 from jmg-duarte/patch-1
matklad Aug 3, 2020
047f7c2
Make type in Param optional
Apanatshka Aug 7, 2020
5342bd6
Merge pull request #4 from Apanatshka/patch-1
matklad Aug 7, 2020
fe7ac06
Allow pipes in parameters
matklad Aug 21, 2020
01ab701
Name MethodCall's receiver
matklad Aug 21, 2020
f9a230c
v1.1.2
matklad Aug 21, 2020
ebf2403
Allow type aliases in extern blocks
jonas-schievink Aug 24, 2020
4640b2e
Bump to 1.1.3
jonas-schievink Aug 24, 2020
b12bd65
Merge #10
bors[bot] Aug 24, 2020
b6d0d74
Continious release
matklad Aug 24, 2020
84597d4
Allow both const & async modifiers
matklad Aug 24, 2020
af86e92
Merge #11
bors[bot] Aug 24, 2020
aa77837
Fix .gitignore
matklad Aug 24, 2020
6cb8e68
Merge #12
bors[bot] Aug 24, 2020
c30083d
Add new_inline const-fn constructor
matklad Sep 20, 2020
e61b5ac
:arrow_up: proptest
matklad Sep 20, 2020
1150aa9
Switch CI to actions
matklad Sep 20, 2020
639343b
Bump major version
matklad Sep 20, 2020
2455319
Drop benchmarking
matklad Sep 20, 2020
52a34ff
Merge #23
bors[bot] Sep 20, 2020
de2c360
Document MSRV
matklad Sep 21, 2020
45a50fd
Update CI badge in readme to point to Github Actions
ComputerDruid Oct 7, 2020
784f345
Minor
matklad Oct 24, 2020
eb7e474
Link post
matklad Oct 24, 2020
9f9a6f0
Move towards upstream `macro_rules!` model
jonas-schievink Nov 27, 2020
0b1776c
Merge pull request #14 from jonas-schievink/macros
Dec 14, 2020
fab6162
Bump to 1.2.0
jonas-schievink Dec 14, 2020
d41a411
Fixup MacroRules to work with xtask codegen
jonas-schievink Dec 14, 2020
143cc52
Roll back `MacroArm` change
jonas-schievink Dec 15, 2020
7282477
Add `MacroDef` for "Macros 2.0"
jonas-schievink Dec 15, 2020
a188a93
Fix labels missing the colon token in rust ungrammar
Veykril Dec 14, 2020
9e81b8b
Node-ify lifetime
Veykril Dec 14, 2020
e250a93
Merge #16
bors[bot] Dec 16, 2020
ccc54ed
Bump to 1.3.0
Dec 16, 2020
3ff83b0
Merge #15
bors[bot] Dec 16, 2020
c87f01e
Bump to 1.4.0
Dec 16, 2020
a2900d2
Add inline const expression and pattern
Veykril Dec 15, 2020
5670143
Merge #17
bors[bot] Dec 23, 2020
fe4a8e6
Rename tail_expr
matklad Jan 5, 2021
57cc080
Merge #18
bors[bot] Jan 5, 2021
bf2dc99
Add YieldExpr
sasurau4 Jan 11, 2021
c332d9d
Bump to 1.7.0
sasurau4 Jan 12, 2021
7c5f3f9
Merge #19
bors[bot] Jan 12, 2021
e4d0f2b
Allow binary-searching an array of disjoint ranges
matklad Jan 13, 2021
8ba7ead
Replace self/super/crate in PathSegment with NameRef
Veykril Jan 15, 2021
6ae4892
Merge #20
bors[bot] Jan 15, 2021
54df3c1
Replace other self/super/crate usages with NameRef
Veykril Jan 15, 2021
a2167cb
Merge #21
bors[bot] Jan 15, 2021
af30e7c
`Type` can also be `MacroCall`
jonas-schievink Jan 18, 2021
09007af
Merge pull request #22 from jonas-schievink/ty-macro
Jan 18, 2021
1959fdf
Wrap type macro in new `MacroType` node
jonas-schievink Jan 18, 2021
45d4794
Merge pull request #23 from jonas-schievink/ty-macro-2
Jan 18, 2021
075778d
Swap RecordExprField optional part
Veykril Jan 18, 2021
effe644
Correct `const` keyword position in `Impl` rule
Veykril Jan 18, 2021
3e99ee1
Merge #24
bors[bot] Jan 18, 2021
66763c8
Derive more for Node and Token
azdavis Jan 22, 2021
d873e88
Add a tokens iterator
azdavis Jan 22, 2021
3beaff7
Write docs
azdavis Jan 22, 2021
6361741
Reorder
azdavis Jan 22, 2021
02be057
Fix typo
azdavis Jan 22, 2021
ab160cd
Pluralize
azdavis Jan 22, 2021
e4ab990
Add more doc
azdavis Jan 22, 2021
b82d2fc
Fix typo
azdavis Jan 22, 2021
e4e81fe
Bump minor version
azdavis Jan 22, 2021
5846451
Merge #25
bors[bot] Jan 22, 2021
d0d1fc0
adt
matklad Feb 7, 2021
723a57a
Split out macro calls in item position
jonas-schievink Feb 18, 2021
496bf95
Merge #27
bors[bot] Feb 18, 2021
190981d
Make ExternItem and AssocItem use MacroItem
jonas-schievink Feb 18, 2021
4a6a83e
Merge #28
bors[bot] Feb 18, 2021
49294fe
Macro Statements should be expr
edwin0cheng Mar 8, 2021
928c645
Revert "Make ExternItem and AssocItem use MacroItem"
jonas-schievink Mar 15, 2021
113a7ac
Revert "Split out macro calls in item position"
jonas-schievink Mar 15, 2021
fab562a
Restore current version
jonas-schievink Mar 15, 2021
ffc3dc9
Merge #30
bors[bot] Mar 15, 2021
6cf7007
Merge #29
bors[bot] Mar 15, 2021
9abe645
extended_key_value_attributes
Veykril Mar 18, 2021
222f4d2
Merge #31
bors[bot] Mar 18, 2021
0f5b22f
Report 1-based indices in Error's Display impl
CAD97 May 2, 2021
9f24a24
Merge #32
bors[bot] May 2, 2021
3c3095f
Add a `Meta` node representing attribute contents
jonas-schievink Jun 11, 2021
b344c9a
Bump to 1.14.0
jonas-schievink Jun 11, 2021
0ee885c
Merge #33
bors[bot] Jun 11, 2021
bcb24cd
fix indentation
matklad Jun 19, 2021
29ab704
More specific error for leading pipes
ammkrn Jun 19, 2021
3207f95
Merge #35
bors[bot] Jun 19, 2021
538c29e
Implement arbitrary behind a feature flag
Jun 26, 2021
cd87249
Merge #35
bors[bot] Jun 26, 2021
683747f
Add GenericParamList to AssocTypeArg
Veykril Jul 17, 2021
0602315
Merge #36
bors[bot] Jul 17, 2021
c306ed3
Add `#![no_std]` support
ark0f Aug 12, 2021
a9b5875
Merge #36
bors[bot] Aug 12, 2021
19176cd
Add syntax elements for `if let` match guards
jonas-schievink Aug 12, 2021
074b255
Merge #38
bors[bot] Aug 12, 2021
50019ba
Add both variants of half open range patterns to the grammar
lf- Aug 4, 2021
1fec3b1
Bump version and remove soft-deprecated authors field
lf- Aug 5, 2021
1c7a5c8
Merge #37
bors[bot] Aug 13, 2021
f613f52
Merge #26
bors[bot] Sep 13, 2021
81876f7
Add ungrammar extensions
azdavis Sep 14, 2021
32088df
Merge #39
bors[bot] Sep 14, 2021
1523dde
avoid attribute ambiguity in ExprStmt
matklad Sep 26, 2021
2da46ff
canonical grammar for block expressions
matklad Sep 26, 2021
91eb93c
bump version
matklad Sep 26, 2021
7eb9cab
Merge #40
bors[bot] Sep 26, 2021
aee806c
add Attr to RestPat
xffxff Oct 3, 2021
06abbb8
Merge #41
bors[bot] Oct 3, 2021
7fdea9f
Add support for `let ... else`
jonas-schievink Oct 6, 2021
2cd7d33
Merge #42
bors[bot] Oct 6, 2021
f1db2ca
Make `LetElse` its own node
jonas-schievink Oct 7, 2021
2497896
Merge #43
bors[bot] Oct 7, 2021
c0478a4
Add `~const` bounds to rust grammar
Veykril Oct 19, 2021
42810d7
Merge #44
bors[bot] Oct 19, 2021
e3edb41
implement FromStr
matklad Nov 1, 2021
56eaef5
Merge #39
bors[bot] Nov 1, 2021
2cdb8d7
fix no_std support
matklad Nov 1, 2021
229f799
Merge #40
bors[bot] Nov 1, 2021
c46ffc9
Remove unnecessary Into<String> bound from From<T> impl
Veykril Nov 4, 2021
0c2244e
Merge #41
bors[bot] Nov 4, 2021
7479c18
Support if- and while-let chains
ChayimFriedman2 Jan 24, 2022
4b6c84d
Merge #45
bors[bot] Jan 31, 2022
800de58
Fix some rust.ungram inconsistencies
Veykril Feb 8, 2022
deb3600
Merge #46
bors[bot] Feb 20, 2022
11206f1
Revert the visibility removal of macro_rules visibility (#46)
ChayimFriedman2 Feb 24, 2022
c391a33
Merge #48
bors[bot] Feb 24, 2022
039a274
Support destructuring assignments (RFC 2909)
ChayimFriedman2 Feb 24, 2022
61e218c
Merge #47
bors[bot] Feb 26, 2022
6d2f3ec
Include `Self` specifically in NameRef
Veykril Mar 5, 2022
814f047
Merge #50
bors[bot] Mar 5, 2022
6edb525
Add a new test for bad size hint
Dr-Emann Jul 7, 2020
e197fd1
Use ASCII to get the "too big" char iterator
Dr-Emann Mar 11, 2022
5a828d4
Merge #21
bors[bot] Mar 11, 2022
31fc606
Merge #18
bors[bot] Apr 3, 2022
b8248e2
Clarify what `WS` is
Veykril Apr 3, 2022
074f986
Merge #43
bors[bot] Apr 3, 2022
756fa7d
Bump dependencies
Veykril Apr 3, 2022
09b4f68
Merge #44
bors[bot] Apr 3, 2022
3d05659
Use new optional dependency feature syntax making serde truly optional
Veykril Apr 8, 2022
b771ae7
Merge #46
bors[bot] Apr 8, 2022
d6b8d67
Revert usage of optional dependency feature syntax
Veykril Apr 26, 2022
8651ce0
One more byte for inlined
Austaras Jan 22, 2023
14badf1
0.1.24
Austaras Jan 23, 2023
10dcf6b
Update README.MD
Austaras Jan 23, 2023
e3b4ae9
Remove redundant enum value
Austaras Jan 24, 2023
8a35102
Update test
Austaras Feb 5, 2023
9cb9f3b
Merge pull request #53 from Austaras/master
Veykril Feb 5, 2023
456160c
Use optional dependency feature syntax to make serde actually optional
Veykril Mar 30, 2023
77436f8
Merge pull request #54 from rust-analyzer/opt-dep-feat
Veykril Mar 30, 2023
2a2b7df
Implement AsRef<str> in favor of generic From impls
Veykril Mar 31, 2023
6009117
Clarify size of SmolStr better
Veykril Mar 31, 2023
aeae719
Release 0.2.0
Veykril Mar 31, 2023
f927bdb
Merge pull request #55 from rust-analyzer/as-ref
Veykril Apr 11, 2023
11fecff
Update ungrammar.ungram with proper labeled rule
eliben Jun 19, 2023
8a85cde
Merge pull request #52 from eliben/patch-1
matklad Jun 19, 2023
5289a56
implement `Clone` for `Rule`
aDotInTheVoid Jun 29, 2023
5f22fbe
Constify some constructors
Veykril Jun 30, 2023
8b792e9
Merge pull request #52 from rust-analyzer/constify
Veykril Jun 30, 2023
1d4189c
Update repo link in Cargo.toml
tisonkun Jul 1, 2023
20bc271
Merge pull request #54 from tisonkun/patch-1
lnicola Jul 2, 2023
37f3991
Implementing `From<Arc<str>> for SmolStr` and `From<SmolStr> for Arc<…
msdrigg Aug 25, 2023
2c54bb6
Enforcing stack if can be put on stack
msdrigg Sep 5, 2023
7d1b60c
Merge pull request #58 from msdrigg/master
Veykril Sep 10, 2023
0b0514b
docs: fix missing codeblock backtick
MultisampledNight Sep 20, 2023
8734783
Merge pull request #59 from MultisampledNight/fix-missing-backtick
Veykril Sep 22, 2023
f8ed961
feat: Add `SmolStr::from_static`
moulins Jan 2, 2024
1192514
Add Writer and ToSmolStr
novacrazy Jan 15, 2024
0ca4ff7
Cleanup
novacrazy Jan 16, 2024
69ff33c
Fix new_inline codegen
novacrazy Jan 16, 2024
01114d2
Publish 0.2.1
Veykril Jan 16, 2024
14cbe54
add benchmarks
AntonSol919 Jan 17, 2024
d5994d5
fix clone regression
AntonSol919 Jan 17, 2024
e1a98b1
Manually impl clone
AntonSol919 Jan 17, 2024
a063f40
remove nightly benchmark feature
AntonSol919 Jan 17, 2024
0fb3a13
reformat
AntonSol919 Jan 31, 2024
fe7064e
Add StrExt, to_lowercase_smolstr & friends
alexheretic Jan 30, 2024
0078fdf
Add must_use to StrExt methods
alexheretic Feb 8, 2024
9971a3f
Add `PartialEq` shortcut for `ptr_eq` strings
Swatinem Jan 17, 2024
1e2145d
Add StrExt::replace_smolstr, replacen_smolstr
alexheretic Feb 8, 2024
73678ce
Update rust.ungram
Veykril Apr 18, 2024
673755b
Document unsafe blocks
Veykril May 14, 2024
aea39b4
Publish 0.2.2
Veykril May 14, 2024
2a02189
Document crate feature guards
robjtede Jun 1, 2024
fde86a5
Migrate CI to actions-rust-lang/setup-rust-toolchain
robjtede Jun 1, 2024
5e7b3c4
Bump deps
Veykril Sep 2, 2024
eb00f33
Various cleanups
Veykril Sep 2, 2024
593d89f
Add more trait impls
Veykril Sep 2, 2024
de2af0d
Expose SmolStrBuilder
Veykril Sep 3, 2024
5ee1057
Add support for borsh
corvusrabus Apr 17, 2024
db4d3c0
Drop unstable__schema
Veykril Sep 3, 2024
24bec15
SmolStrBuilder::push
Veykril Sep 3, 2024
b38a973
Publish 0.3.0
Veykril Sep 3, 2024
68bc4ed
Make SmolStrBuilder fields private
Veykril Sep 3, 2024
91e9581
Publish 0.3.1
Veykril Sep 3, 2024
4a25cbe
Add CHANGELOG.md
Veykril Sep 3, 2024
32e8936
Add 0.2.2 changelog & fix lints
alexheretic Sep 3, 2024
811ac43
Update CHANGELOG.md
alexheretic Sep 3, 2024
f680abc
Merge pull request #87 from alexheretic/changelog++
lnicola Sep 3, 2024
7235aa1
Fix SmoLStrBuilder pushing null bytes on heap spill
Veykril Oct 23, 2024
5ffc900
Publish 0.3.2
Veykril Oct 23, 2024
53bc777
Merge pull request #53 from aDotInTheVoid/patch-1
Veykril Oct 27, 2024
484153d
Fix lints
alexheretic Sep 14, 2025
cb35228
Merge pull request #99 from alexheretic/fix-lints
lnicola Sep 15, 2025
0e432a0
Use serde_core over serde
james7132 Sep 22, 2025
4f0658f
Optimise to_ascii_{upper,lower}case_smolstr
alexheretic Sep 13, 2025
b3ac1b5
Update changelog
alexheretic Sep 14, 2025
df41c50
Add SmolStr vs String benchmarks
alexheretic Sep 13, 2025
b4220df
Only bench smol_str stuff
alexheretic Sep 13, 2025
81c8790
CI: Add TEST_BENCHES
alexheretic Sep 14, 2025
3122a9a
Optimise `to_{lower,upper}case_smolstr`
alexheretic Sep 14, 2025
22feb5f
Update changelog
alexheretic Sep 14, 2025
08a9dc8
Add test from_buf_and_chars_size_hinted_heap & fix
alexheretic Sep 15, 2025
104784a
Optimise replacen_smolstr for single ascii replace
alexheretic Sep 15, 2025
026103b
Optimise replacen 1-ascii when count >= len
alexheretic Sep 15, 2025
97ef5f3
Mark replacen_1_ascii as unsafe
alexheretic Sep 15, 2025
8f4deab
Update changelog
alexheretic Sep 15, 2025
bf2e3d7
Publish 0.3.3
Veykril Oct 23, 2025
02336c5
Publish 0.3.4
Veykril Oct 23, 2025
291cc5d
Rename `downcast_[ref|mut]_unchecked` -> `downcast_unchecked_[ref|mut]`
taj-p Oct 24, 2025
e92e679
Fix not parse never type in inherent impl
A4-Tacks Nov 5, 2025
f96a01b
Add guard support for replace_if_let_with_match
A4-Tacks Aug 26, 2025
f46ac05
Subtree smol_str
Veykril Nov 7, 2025
f48b2f6
Subtree ungrammar
Veykril Nov 7, 2025
6f83cee
Subtree text-size
Veykril Nov 7, 2025
3c741d5
Update Cargo.toml and lockfile
Veykril Nov 7, 2025
f12388c
Reformat
Veykril Nov 7, 2025
3efda63
Merge pull request #20991 from Veykril/push-rrpwmvnskstu
Veykril Nov 8, 2025
df009ee
Reformat
Veykril Nov 7, 2025
ed2ae23
Merge pull request #20990 from Veykril/push-zzrzusnvwpzp
Veykril Nov 8, 2025
64b00e7
Reformat
Veykril Nov 7, 2025
4cea939
Merge pull request #20988 from Veykril/push-rutmxykksupu
Veykril Nov 8, 2025
6ba7d24
Replace `SmolStr` usage with `Symbol` in `FileSymbol`
Veykril Nov 8, 2025
abf2e3e
Replace more smol strings with symbols
Veykril Nov 8, 2025
1efe8b6
Merge pull request #20994 from Veykril/push-npvyklkuxnlr
Veykril Nov 8, 2025
3c19ebf
Disassemble `SymbolsDatabase`
Veykril Nov 8, 2025
d26e4b2
Merge pull request #20995 from Veykril/push-kysxxnruzslp
Veykril Nov 8, 2025
0788e84
Merge pull request #20909 from taj-p/master
Veykril Nov 9, 2025
7f82691
perf: Only populate public items in dependency symbol index
Veykril Nov 8, 2025
2bbbc61
Merge pull request #20997 from Veykril/push-zsuorxrkpupr
Veykril Nov 9, 2025
c012ee9
lib: Bump editions to 2024 and remove legacy files
Veykril Nov 9, 2025
6b10d39
Merge pull request #21002 from Veykril/veykril/push-nztxvpnntmrx
Veykril Nov 9, 2025
db86a00
Fix .const missing block on with modifier block
A4-Tacks Nov 9, 2025
0c593be
Typos and distracting word choices
fgamador Nov 9, 2025
21f8445
Merge pull request #21005 from fgamador/book-testing
ChayimFriedman2 Nov 9, 2025
99bfa4a
Merge pull request #21003 from A4-Tacks/missing-curly-postfix-with-mo…
ShoyuVanilla Nov 10, 2025
d7b5e0b
Merge pull request #20972 from A4-Tacks/impl-never-type
ShoyuVanilla Nov 10, 2025
73f565e
Merge pull request #20542 from A4-Tacks/if-let-to-match-guard
ShoyuVanilla Nov 10, 2025
ef05935
support rename after adding label
Natural-selection1 Nov 7, 2025
f3cbd0e
Merge pull request #20985 from Natural-selection1/rename
ChayimFriedman2 Nov 10, 2025
c58810b
Provide a gdb pretty printer for smol_str::SmolStr
dfaure-kdab Nov 10, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
568 changes: 542 additions & 26 deletions Cargo.lock

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["xtask/", "lib/*", "crates/*"]
members = ["xtask/", "lib/*", "lib/ungrammar/ungrammar2json", "crates/*"]
exclude = ["crates/proc-macro-srv/proc-macro-test/imp"]
resolver = "2"

Expand Down Expand Up @@ -42,7 +42,7 @@ debug = 2
# lsp-server = { path = "lib/lsp-server" }


# ungrammar = { path = "../ungrammar" }
# ungrammar = { path = "lin/ungrammar" }

# salsa = { path = "../salsa" }
# salsa-macros = { path = "../salsa/components/salsa-macros" }
Expand Down
7 changes: 5 additions & 2 deletions crates/hir/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ pub mod term_search;

mod display;

#[doc(hidden)]
pub use hir_def::ModuleId;

use std::{
fmt,
mem::discriminant,
Expand All @@ -48,8 +51,8 @@ use hir_def::{
AdtId, AssocItemId, AssocItemLoc, AttrDefId, CallableDefId, ConstId, ConstParamId,
CrateRootModuleId, DefWithBodyId, EnumId, EnumVariantId, ExternBlockId, ExternCrateId,
FunctionId, GenericDefId, GenericParamId, HasModule, ImplId, ItemContainerId, LifetimeParamId,
LocalFieldId, Lookup, MacroExpander, MacroId, ModuleId, StaticId, StructId, SyntheticSyntax,
TupleId, TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
LocalFieldId, Lookup, MacroExpander, MacroId, StaticId, StructId, SyntheticSyntax, TupleId,
TypeAliasId, TypeOrConstParamId, TypeParamId, UnionId,
expr_store::{ExpressionStoreDiagnostics, ExpressionStoreSourceMap},
hir::{
BindingAnnotation, BindingId, Expr, ExprId, ExprOrPatId, LabelId, Pat,
Expand Down
54 changes: 39 additions & 15 deletions crates/hir/src/symbols.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ use hir_ty::{
};
use intern::Symbol;
use rustc_hash::FxHashMap;
use syntax::{AstNode, AstPtr, SmolStr, SyntaxNode, SyntaxNodePtr, ToSmolStr, ast::HasName};
use syntax::{AstNode, AstPtr, SyntaxNode, SyntaxNodePtr, ToSmolStr, ast::HasName};

use crate::{HasCrate, Module, ModuleDef, Semantics};

Expand All @@ -29,7 +29,7 @@ pub struct FileSymbol {
pub name: Symbol,
pub def: ModuleDef,
pub loc: DeclarationLocation,
pub container_name: Option<SmolStr>,
pub container_name: Option<Symbol>,
/// Whether this symbol is a doc alias for the original symbol.
pub is_alias: bool,
pub is_assoc: bool,
Expand Down Expand Up @@ -65,23 +65,29 @@ pub struct SymbolCollector<'a> {
db: &'a dyn HirDatabase,
symbols: FxIndexSet<FileSymbol>,
work: Vec<SymbolCollectorWork>,
current_container_name: Option<SmolStr>,
current_container_name: Option<Symbol>,
collect_pub_only: bool,
}

/// Given a [`ModuleId`] and a [`HirDatabase`], use the DefMap for the module's crate to collect
/// all symbols that should be indexed for the given module.
impl<'a> SymbolCollector<'a> {
pub fn new(db: &'a dyn HirDatabase) -> Self {
pub fn new(db: &'a dyn HirDatabase, collect_pub_only: bool) -> Self {
SymbolCollector {
db,
symbols: Default::default(),
work: Default::default(),
current_container_name: None,
collect_pub_only,
}
}

pub fn new_module(db: &dyn HirDatabase, module: Module) -> Box<[FileSymbol]> {
let mut symbol_collector = SymbolCollector::new(db);
pub fn new_module(
db: &dyn HirDatabase,
module: Module,
collect_pub_only: bool,
) -> Box<[FileSymbol]> {
let mut symbol_collector = SymbolCollector::new(db, collect_pub_only);
symbol_collector.collect(module);
symbol_collector.finish()
}
Expand All @@ -108,12 +114,16 @@ impl<'a> SymbolCollector<'a> {
tracing::info!(?work, "SymbolCollector::do_work");
self.db.unwind_if_revision_cancelled();

let parent_name = work.parent.map(|name| name.as_str().to_smolstr());
let parent_name = work.parent.map(|name| Symbol::intern(name.as_str()));
self.with_container_name(parent_name, |s| s.collect_from_module(work.module_id));
}

fn collect_from_module(&mut self, module_id: ModuleId) {
let push_decl = |this: &mut Self, def, name| {
let collect_pub_only = self.collect_pub_only;
let push_decl = |this: &mut Self, def: ModuleDefId, name, vis| {
if collect_pub_only && vis != Visibility::Public {
return;
}
match def {
ModuleDefId::ModuleId(id) => this.push_module(id, name),
ModuleDefId::FunctionId(id) => {
Expand All @@ -125,7 +135,7 @@ impl<'a> SymbolCollector<'a> {
}
ModuleDefId::AdtId(AdtId::EnumId(id)) => {
this.push_decl(id, name, false, None);
let enum_name = this.db.enum_signature(id).name.as_str().to_smolstr();
let enum_name = Symbol::intern(this.db.enum_signature(id).name.as_str());
this.with_container_name(Some(enum_name), |this| {
let variants = id.enum_variants(this.db);
for (variant_id, variant_name, _) in &variants.variants {
Expand Down Expand Up @@ -175,6 +185,9 @@ impl<'a> SymbolCollector<'a> {
};

let mut push_import = |this: &mut Self, i: ImportId, name: &Name, def: ModuleDefId, vis| {
if collect_pub_only && vis != Visibility::Public {
return;
}
let source = import_child_source_cache
.entry(i.use_)
.or_insert_with(|| i.use_.child_source(this.db));
Expand Down Expand Up @@ -209,6 +222,9 @@ impl<'a> SymbolCollector<'a> {

let push_extern_crate =
|this: &mut Self, i: ExternCrateId, name: &Name, def: ModuleDefId, vis| {
if collect_pub_only && vis != Visibility::Public {
return;
}
let loc = i.lookup(this.db);
let source = loc.source(this.db);
let rename = source.value.rename().and_then(|rename| rename.name());
Expand Down Expand Up @@ -258,7 +274,7 @@ impl<'a> SymbolCollector<'a> {
continue;
}
// self is a declaration
push_decl(self, def, name)
push_decl(self, def, name, vis)
}

for (name, Item { def, vis, import }) in scope.macros() {
Expand All @@ -271,7 +287,7 @@ impl<'a> SymbolCollector<'a> {
continue;
}
// self is a declaration
push_decl(self, def.into(), name)
push_decl(self, ModuleDefId::MacroId(def), name, vis)
}

for (name, Item { def, vis, import }) in scope.values() {
Expand All @@ -283,7 +299,7 @@ impl<'a> SymbolCollector<'a> {
continue;
}
// self is a declaration
push_decl(self, def, name)
push_decl(self, def, name, vis)
}

for const_id in scope.unnamed_consts() {
Expand All @@ -304,6 +320,9 @@ impl<'a> SymbolCollector<'a> {
}

fn collect_from_body(&mut self, body_id: impl Into<DefWithBodyId>, name: Option<Name>) {
if self.collect_pub_only {
return;
}
let body_id = body_id.into();
let body = self.db.body(body_id);

Expand All @@ -328,23 +347,28 @@ impl<'a> SymbolCollector<'a> {
)
.to_smolstr(),
);
self.with_container_name(impl_name, |s| {
self.with_container_name(impl_name.as_deref().map(Symbol::intern), |s| {
for &(ref name, assoc_item_id) in &impl_id.impl_items(self.db).items {
if s.collect_pub_only && s.db.assoc_visibility(assoc_item_id) != Visibility::Public
{
continue;
}

s.push_assoc_item(assoc_item_id, name, None)
}
})
}

fn collect_from_trait(&mut self, trait_id: TraitId, trait_do_not_complete: Complete) {
let trait_data = self.db.trait_signature(trait_id);
self.with_container_name(Some(trait_data.name.as_str().into()), |s| {
self.with_container_name(Some(Symbol::intern(trait_data.name.as_str())), |s| {
for &(ref name, assoc_item_id) in &trait_id.trait_items(self.db).items {
s.push_assoc_item(assoc_item_id, name, Some(trait_do_not_complete));
}
});
}

fn with_container_name(&mut self, container_name: Option<SmolStr>, f: impl FnOnce(&mut Self)) {
fn with_container_name(&mut self, container_name: Option<Symbol>, f: impl FnOnce(&mut Self)) {
if let Some(container_name) = container_name {
let prev = self.current_container_name.replace(container_name);
f(self);
Expand Down
99 changes: 66 additions & 33 deletions crates/ide-assists/src/handlers/add_label_to_loop.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,14 @@
use ide_db::syntax_helpers::node_ext::for_each_break_and_continue_expr;
use ide_db::{
source_change::SourceChangeBuilder, syntax_helpers::node_ext::for_each_break_and_continue_expr,
};
use syntax::{
T,
ast::{self, AstNode, HasLoopBody},
SyntaxToken, T,
ast::{
self, AstNode, HasLoopBody,
make::{self, tokens},
syntax_factory::SyntaxFactory,
},
syntax_editor::{Position, SyntaxEditor},
};

use crate::{AssistContext, AssistId, Assists};
Expand All @@ -21,9 +28,9 @@ use crate::{AssistContext, AssistId, Assists};
// ->
// ```
// fn main() {
// 'l: loop {
// break 'l;
// continue 'l;
// ${1:'l}: loop {
// break ${2:'l};
// continue ${0:'l};
// }
// }
// ```
Expand All @@ -39,30 +46,56 @@ pub(crate) fn add_label_to_loop(acc: &mut Assists, ctx: &AssistContext<'_>) -> O
"Add Label",
loop_expr.syntax().text_range(),
|builder| {
builder.insert(loop_kw.text_range().start(), "'l: ");
let make = SyntaxFactory::with_mappings();
let mut editor = builder.make_editor(loop_expr.syntax());

let label = make.lifetime("'l");
let elements = vec![
label.syntax().clone().into(),
make::token(T![:]).into(),
tokens::single_space().into(),
];
editor.insert_all(Position::before(&loop_kw), elements);

if let Some(cap) = ctx.config.snippet_cap {
editor.add_annotation(label.syntax(), builder.make_placeholder_snippet(cap));
}

let loop_body = loop_expr.loop_body().and_then(|it| it.stmt_list());
for_each_break_and_continue_expr(
loop_expr.label(),
loop_body,
&mut |expr| match expr {
ast::Expr::BreakExpr(break_expr) => {
if let Some(break_token) = break_expr.break_token() {
builder.insert(break_token.text_range().end(), " 'l")
}
}
ast::Expr::ContinueExpr(continue_expr) => {
if let Some(continue_token) = continue_expr.continue_token() {
builder.insert(continue_token.text_range().end(), " 'l")
}
}
_ => {}
},
);
for_each_break_and_continue_expr(loop_expr.label(), loop_body, &mut |expr| {
let token = match expr {
ast::Expr::BreakExpr(break_expr) => break_expr.break_token(),
ast::Expr::ContinueExpr(continue_expr) => continue_expr.continue_token(),
_ => return,
};
if let Some(token) = token {
insert_label_after_token(&mut editor, &make, &token, ctx, builder);
}
});

editor.add_mappings(make.finish_with_mappings());
builder.add_file_edits(ctx.vfs_file_id(), editor);
builder.rename();
},
)
}

fn insert_label_after_token(
editor: &mut SyntaxEditor,
make: &SyntaxFactory,
token: &SyntaxToken,
ctx: &AssistContext<'_>,
builder: &mut SourceChangeBuilder,
) {
let label = make.lifetime("'l");
let elements = vec![tokens::single_space().into(), label.syntax().clone().into()];
editor.insert_all(Position::after(token), elements);

if let Some(cap) = ctx.config.snippet_cap {
editor.add_annotation(label.syntax(), builder.make_placeholder_snippet(cap));
}
}

#[cfg(test)]
mod tests {
use crate::tests::{check_assist, check_assist_not_applicable};
Expand All @@ -82,9 +115,9 @@ fn main() {
}"#,
r#"
fn main() {
'l: loop {
break 'l;
continue 'l;
${1:'l}: loop {
break ${2:'l};
continue ${0:'l};
}
}"#,
);
Expand All @@ -107,9 +140,9 @@ fn main() {
}"#,
r#"
fn main() {
'l: loop {
break 'l;
continue 'l;
${1:'l}: loop {
break ${2:'l};
continue ${0:'l};
loop {
break;
continue;
Expand Down Expand Up @@ -139,9 +172,9 @@ fn main() {
loop {
break;
continue;
'l: loop {
break 'l;
continue 'l;
${1:'l}: loop {
break ${2:'l};
continue ${0:'l};
}
}
}"#,
Expand Down
Loading