mirror of
https://github.com/rust-lang/rust-analyzer.git
synced 2025-09-30 22:01:37 +00:00
Keep SyntaxNodePtr::range private
This commit is contained in:
parent
66cea8cbaa
commit
fb0ab9f745
4 changed files with 17 additions and 9 deletions
|
@ -267,7 +267,7 @@ impl fmt::Display for CaseType {
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
pub struct IncorrectCase {
|
pub struct IncorrectCase {
|
||||||
pub file: HirFileId,
|
pub file: HirFileId,
|
||||||
pub ident: SyntaxNodePtr,
|
pub ident: AstPtr<ast::Name>,
|
||||||
pub expected_case: CaseType,
|
pub expected_case: CaseType,
|
||||||
pub ident_type: String,
|
pub ident_type: String,
|
||||||
pub ident_text: String,
|
pub ident_text: String,
|
||||||
|
@ -290,7 +290,7 @@ impl Diagnostic for IncorrectCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn display_source(&self) -> InFile<SyntaxNodePtr> {
|
fn display_source(&self) -> InFile<SyntaxNodePtr> {
|
||||||
InFile::new(self.file, self.ident.clone())
|
InFile::new(self.file, self.ident.clone().into())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
fn as_any(&self) -> &(dyn Any + Send + 'static) {
|
||||||
|
|
|
@ -213,12 +213,21 @@ impl<'a, 'b> DeclValidator<'a, 'b> {
|
||||||
for param_to_rename in fn_param_replacements {
|
for param_to_rename in fn_param_replacements {
|
||||||
// We assume that parameters in replacement are in the same order as in the
|
// We assume that parameters in replacement are in the same order as in the
|
||||||
// actual params list, but just some of them (ones that named correctly) are skipped.
|
// actual params list, but just some of them (ones that named correctly) are skipped.
|
||||||
let ast_ptr = loop {
|
let ast_ptr: ast::Name = loop {
|
||||||
match fn_params_iter.next() {
|
match fn_params_iter.next() {
|
||||||
Some(element)
|
Some(element)
|
||||||
if pat_equals_to_name(element.pat(), ¶m_to_rename.current_name) =>
|
if pat_equals_to_name(element.pat(), ¶m_to_rename.current_name) =>
|
||||||
{
|
{
|
||||||
break element.pat().unwrap()
|
if let ast::Pat::IdentPat(pat) = element.pat().unwrap() {
|
||||||
|
break pat.name().unwrap();
|
||||||
|
} else {
|
||||||
|
// This is critical. If we consider this parameter the expected one,
|
||||||
|
// it **must** have a name.
|
||||||
|
panic!(
|
||||||
|
"Pattern {:?} equals to expected replacement {:?}, but has no name",
|
||||||
|
element, param_to_rename
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Some(_) => {}
|
Some(_) => {}
|
||||||
None => {
|
None => {
|
||||||
|
|
|
@ -104,8 +104,11 @@ impl DiagnosticWithFix for MissingOkInTailExpr {
|
||||||
|
|
||||||
impl DiagnosticWithFix for IncorrectCase {
|
impl DiagnosticWithFix for IncorrectCase {
|
||||||
fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> {
|
fn fix(&self, sema: &Semantics<RootDatabase>) -> Option<Fix> {
|
||||||
|
let root = sema.db.parse_or_expand(self.file)?;
|
||||||
|
let name_node = self.ident.to_node(&root);
|
||||||
|
|
||||||
let file_id = self.file.original_file(sema.db);
|
let file_id = self.file.original_file(sema.db);
|
||||||
let offset = self.ident.text_range().start();
|
let offset = name_node.syntax().text_range().start();
|
||||||
let file_position = FilePosition { file_id, offset };
|
let file_position = FilePosition { file_id, offset };
|
||||||
|
|
||||||
let rename_changes = rename_with_semantics(sema, file_position, &self.suggested_text)?;
|
let rename_changes = rename_with_semantics(sema, file_position, &self.suggested_text)?;
|
||||||
|
|
|
@ -23,10 +23,6 @@ impl SyntaxNodePtr {
|
||||||
SyntaxNodePtr { range: node.text_range(), kind: node.kind() }
|
SyntaxNodePtr { range: node.text_range(), kind: node.kind() }
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn text_range(&self) -> TextRange {
|
|
||||||
self.range.clone()
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode {
|
pub fn to_node(&self, root: &SyntaxNode) -> SyntaxNode {
|
||||||
assert!(root.parent().is_none());
|
assert!(root.parent().is_none());
|
||||||
successors(Some(root.clone()), |node| {
|
successors(Some(root.clone()), |node| {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue