diff options
author | bors[bot] <26634292+bors[bot]@users.noreply.github.com> | 2019-12-29 12:24:19 +0000 |
---|---|---|
committer | GitHub <[email protected]> | 2019-12-29 12:24:19 +0000 |
commit | cdcb3d3833d3d5b37b2cd4dac91a6e9366f20aea (patch) | |
tree | c9750e1ef8079a691caed3dc941392c99fda1524 /crates/ra_syntax | |
parent | c5a48bea1218afb63d7932a6816f34c810bbab6b (diff) | |
parent | 9fd2c813ca355c3a1f10f54993c16e81778b867b (diff) |
Merge #2667
2667: Visibility r=matklad a=flodiebold
This adds the infrastructure for handling visibility (for fields and methods, not in name resolution) in the HIR and code model, and as a first application hides struct fields from completions if they're not visible from the current module. (We might want to relax this again later, but I think it's ok for now?)
Co-authored-by: Florian Diebold <[email protected]>
Diffstat (limited to 'crates/ra_syntax')
-rw-r--r-- | crates/ra_syntax/src/ast.rs | 4 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/extensions.rs | 29 | ||||
-rw-r--r-- | crates/ra_syntax/src/ast/generated.rs | 3 | ||||
-rw-r--r-- | crates/ra_syntax/src/grammar.ron | 6 |
4 files changed, 38 insertions, 4 deletions
diff --git a/crates/ra_syntax/src/ast.rs b/crates/ra_syntax/src/ast.rs index 277532a8c..89cb9a9f3 100644 --- a/crates/ra_syntax/src/ast.rs +++ b/crates/ra_syntax/src/ast.rs | |||
@@ -17,7 +17,9 @@ use crate::{ | |||
17 | 17 | ||
18 | pub use self::{ | 18 | pub use self::{ |
19 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, | 19 | expr_extensions::{ArrayExprKind, BinOp, ElseBranch, LiteralKind, PrefixOp, RangeOp}, |
20 | extensions::{FieldKind, PathSegmentKind, SelfParamKind, StructKind, TypeBoundKind}, | 20 | extensions::{ |
21 | FieldKind, PathSegmentKind, SelfParamKind, StructKind, TypeBoundKind, VisibilityKind, | ||
22 | }, | ||
21 | generated::*, | 23 | generated::*, |
22 | tokens::*, | 24 | tokens::*, |
23 | traits::*, | 25 | traits::*, |
diff --git a/crates/ra_syntax/src/ast/extensions.rs b/crates/ra_syntax/src/ast/extensions.rs index baaef3023..d9666cdca 100644 --- a/crates/ra_syntax/src/ast/extensions.rs +++ b/crates/ra_syntax/src/ast/extensions.rs | |||
@@ -413,3 +413,32 @@ impl ast::TraitDef { | |||
413 | self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) | 413 | self.syntax().children_with_tokens().any(|t| t.kind() == T![auto]) |
414 | } | 414 | } |
415 | } | 415 | } |
416 | |||
417 | pub enum VisibilityKind { | ||
418 | In(ast::Path), | ||
419 | PubCrate, | ||
420 | PubSuper, | ||
421 | Pub, | ||
422 | } | ||
423 | |||
424 | impl ast::Visibility { | ||
425 | pub fn kind(&self) -> VisibilityKind { | ||
426 | if let Some(path) = children(self).next() { | ||
427 | VisibilityKind::In(path) | ||
428 | } else if self.is_pub_crate() { | ||
429 | VisibilityKind::PubCrate | ||
430 | } else if self.is_pub_super() { | ||
431 | VisibilityKind::PubSuper | ||
432 | } else { | ||
433 | VisibilityKind::Pub | ||
434 | } | ||
435 | } | ||
436 | |||
437 | fn is_pub_crate(&self) -> bool { | ||
438 | self.syntax().children_with_tokens().any(|it| it.kind() == T![crate]) | ||
439 | } | ||
440 | |||
441 | fn is_pub_super(&self) -> bool { | ||
442 | self.syntax().children_with_tokens().any(|it| it.kind() == T![super]) | ||
443 | } | ||
444 | } | ||
diff --git a/crates/ra_syntax/src/ast/generated.rs b/crates/ra_syntax/src/ast/generated.rs index 9f9d6e63c..e64c83d33 100644 --- a/crates/ra_syntax/src/ast/generated.rs +++ b/crates/ra_syntax/src/ast/generated.rs | |||
@@ -1064,6 +1064,7 @@ impl AstNode for ExternCrateItem { | |||
1064 | } | 1064 | } |
1065 | } | 1065 | } |
1066 | impl ast::AttrsOwner for ExternCrateItem {} | 1066 | impl ast::AttrsOwner for ExternCrateItem {} |
1067 | impl ast::VisibilityOwner for ExternCrateItem {} | ||
1067 | impl ExternCrateItem { | 1068 | impl ExternCrateItem { |
1068 | pub fn name_ref(&self) -> Option<NameRef> { | 1069 | pub fn name_ref(&self) -> Option<NameRef> { |
1069 | AstChildren::new(&self.syntax).next() | 1070 | AstChildren::new(&self.syntax).next() |
@@ -2006,6 +2007,7 @@ impl AstNode for ModuleItem { | |||
2006 | } | 2007 | } |
2007 | } | 2008 | } |
2008 | impl ast::AttrsOwner for ModuleItem {} | 2009 | impl ast::AttrsOwner for ModuleItem {} |
2010 | impl ast::VisibilityOwner for ModuleItem {} | ||
2009 | impl ModuleItem {} | 2011 | impl ModuleItem {} |
2010 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] | 2012 | #[derive(Debug, Clone, PartialEq, Eq, Hash)] |
2011 | pub struct Name { | 2013 | pub struct Name { |
@@ -3893,6 +3895,7 @@ impl AstNode for UseItem { | |||
3893 | } | 3895 | } |
3894 | } | 3896 | } |
3895 | impl ast::AttrsOwner for UseItem {} | 3897 | impl ast::AttrsOwner for UseItem {} |
3898 | impl ast::VisibilityOwner for UseItem {} | ||
3896 | impl UseItem { | 3899 | impl UseItem { |
3897 | pub fn use_tree(&self) -> Option<UseTree> { | 3900 | pub fn use_tree(&self) -> Option<UseTree> { |
3898 | AstChildren::new(&self.syntax).next() | 3901 | AstChildren::new(&self.syntax).next() |
diff --git a/crates/ra_syntax/src/grammar.ron b/crates/ra_syntax/src/grammar.ron index 08aafb610..e43a724f0 100644 --- a/crates/ra_syntax/src/grammar.ron +++ b/crates/ra_syntax/src/grammar.ron | |||
@@ -412,7 +412,7 @@ Grammar( | |||
412 | "ModuleItem": ( | 412 | "ModuleItem": ( |
413 | enum: ["StructDef", "UnionDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock", | 413 | enum: ["StructDef", "UnionDef", "EnumDef", "FnDef", "TraitDef", "TypeAliasDef", "ImplBlock", |
414 | "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ], | 414 | "UseItem", "ExternCrateItem", "ConstDef", "StaticDef", "Module" ], |
415 | traits: ["AttrsOwner"], | 415 | traits: ["AttrsOwner", "VisibilityOwner"], |
416 | ), | 416 | ), |
417 | "ImplItem": ( | 417 | "ImplItem": ( |
418 | enum: ["FnDef", "TypeAliasDef", "ConstDef"], | 418 | enum: ["FnDef", "TypeAliasDef", "ConstDef"], |
@@ -683,7 +683,7 @@ Grammar( | |||
683 | ] | 683 | ] |
684 | ), | 684 | ), |
685 | "UseItem": ( | 685 | "UseItem": ( |
686 | traits: ["AttrsOwner"], | 686 | traits: ["AttrsOwner", "VisibilityOwner"], |
687 | options: [ "UseTree" ], | 687 | options: [ "UseTree" ], |
688 | ), | 688 | ), |
689 | "UseTree": ( | 689 | "UseTree": ( |
@@ -696,7 +696,7 @@ Grammar( | |||
696 | collections: [("use_trees", "UseTree")] | 696 | collections: [("use_trees", "UseTree")] |
697 | ), | 697 | ), |
698 | "ExternCrateItem": ( | 698 | "ExternCrateItem": ( |
699 | traits: ["AttrsOwner"], | 699 | traits: ["AttrsOwner", "VisibilityOwner"], |
700 | options: ["NameRef", "Alias"], | 700 | options: ["NameRef", "Alias"], |
701 | ), | 701 | ), |
702 | "ArgList": ( | 702 | "ArgList": ( |