refactor: improving names of matched structs and documenting matchers (#1022)

This commit is contained in:
Myriad-Dreamin 2024-12-18 16:35:15 +08:00 committed by GitHub
parent 902bd17cba
commit ad0c1e8aca
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
16 changed files with 391 additions and 412 deletions

View file

@ -14,7 +14,7 @@ use crate::{
find_references,
prelude::*,
prepare_renaming,
syntax::{deref_expr, get_index_info, node_ancestors, Decl, DerefTarget, RefExpr},
syntax::{deref_expr, get_index_info, node_ancestors, Decl, RefExpr, SyntaxClass},
ty::Interned,
};
@ -42,15 +42,15 @@ impl StatefulRequest for RenameRequest {
doc: Option<VersionedDocument>,
) -> Option<Self::Response> {
let source = ctx.source_by_path(&self.path).ok()?;
let deref_target = ctx.deref_syntax_at(&source, self.position, 1)?;
let syntax = ctx.classify_pos(&source, self.position, 1)?;
let def = ctx.def_of_syntax(&source, doc.as_ref(), deref_target.clone())?;
let def = ctx.def_of_syntax(&source, doc.as_ref(), syntax.clone())?;
prepare_renaming(ctx, &deref_target, &def)?;
prepare_renaming(ctx, &syntax, &def)?;
match deref_target {
match syntax {
// todo: abs path
DerefTarget::ImportPath(path) | DerefTarget::IncludePath(path) => {
SyntaxClass::ImportPath(path) | SyntaxClass::IncludePath(path) => {
let ref_path_str = path.cast::<ast::Str>()?.get();
let new_path_str = if !self.new_name.ends_with(".typ") {
self.new_name + ".typ"
@ -94,7 +94,7 @@ impl StatefulRequest for RenameRequest {
})
}
_ => {
let references = find_references(ctx, &source, doc.as_ref(), deref_target)?;
let references = find_references(ctx, &source, doc.as_ref(), syntax)?;
let mut edits = HashMap::new();