Skip to content

internal: rename children_modules to child_modules #19554

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -7,32 +7,32 @@ use syntax::{

use crate::NavigationTarget;

// Feature: Children Modules
// Feature: Child Modules
//
// Navigates to the children modules of the current module.
// Navigates to the child modules of the current module.
//
// | Editor | Action Name |
// |---------|-------------|
// | VS Code | **rust-analyzer: Locate children modules** |
// | VS Code | **rust-analyzer: Locate child modules** |

/// This returns `Vec` because a module may be included from several places.
pub(crate) fn children_modules(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> {
pub(crate) fn child_modules(db: &RootDatabase, position: FilePosition) -> Vec<NavigationTarget> {
let sema = Semantics::new(db);
let source_file = sema.parse_guess_edition(position.file_id);
// First go to the parent module which contains the cursor
let module = find_node_at_offset::<ast::Module>(source_file.syntax(), position.offset);

match module {
Some(module) => {
// Return all the children module inside the ItemList of the parent module
// Return all child modules inside the ItemList of the parent module
sema.to_def(&module)
.into_iter()
.flat_map(|module| module.children(db))
.map(|module| NavigationTarget::from_module_to_decl(db, module).call_site())
.collect()
}
None => {
// Return all the children module inside the source file
// Return all the child modules inside the source file
sema.file_to_module_defs(position.file_id)
.flat_map(|module| module.children(db))
.map(|module| NavigationTarget::from_module_to_decl(db, module).call_site())
Expand All @@ -47,9 +47,9 @@ mod tests {

use crate::fixture;

fn check_children_module(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
fn check_child_module(#[rust_analyzer::rust_fixture] ra_fixture: &str) {
let (analysis, position, expected) = fixture::annotations(ra_fixture);
let navs = analysis.children_modules(position).unwrap();
let navs = analysis.child_modules(position).unwrap();
let navs = navs
.iter()
.map(|nav| FileRange { file_id: nav.file_id, range: nav.focus_or_full_range() })
Expand All @@ -58,8 +58,8 @@ mod tests {
}

#[test]
fn test_resolve_children_module() {
check_children_module(
fn test_resolve_child_module() {
check_child_module(
r#"
//- /lib.rs
$0
Expand All @@ -73,8 +73,8 @@ mod foo;
}

#[test]
fn test_resolve_children_module_on_module_decl() {
check_children_module(
fn test_resolve_child_module_on_module_decl() {
check_child_module(
r#"
//- /lib.rs
mod $0foo;
Expand All @@ -89,8 +89,8 @@ mod bar;
}

#[test]
fn test_resolve_children_module_for_inline() {
check_children_module(
fn test_resolve_child_module_for_inline() {
check_child_module(
r#"
//- /lib.rs
mod foo {
Expand All @@ -104,7 +104,7 @@ mod foo {

#[test]
fn test_resolve_multi_child_module() {
check_children_module(
check_child_module(
r#"
//- /main.rs
$0
Expand Down
6 changes: 3 additions & 3 deletions crates/ide/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ mod navigation_target;

mod annotations;
mod call_hierarchy;
mod children_modules;
mod child_modules;
mod doc_links;
mod expand_macro;
mod extend_selection;
Expand Down Expand Up @@ -607,8 +607,8 @@ impl Analysis {
}

/// Returns vec of `mod name;` declaration which are created by the current module.
pub fn children_modules(&self, position: FilePosition) -> Cancellable<Vec<NavigationTarget>> {
self.with_db(|db| children_modules::children_modules(db, position))
pub fn child_modules(&self, position: FilePosition) -> Cancellable<Vec<NavigationTarget>> {
self.with_db(|db| child_modules::child_modules(db, position))
}

/// Returns crates that this file belongs to.
Expand Down
8 changes: 4 additions & 4 deletions crates/rust-analyzer/src/handlers/request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -943,14 +943,14 @@ pub(crate) fn handle_parent_module(
Ok(Some(res))
}

pub(crate) fn handle_children_modules(
pub(crate) fn handle_child_modules(
snap: GlobalStateSnapshot,
params: lsp_types::TextDocumentPositionParams,
) -> anyhow::Result<Option<lsp_types::GotoDefinitionResponse>> {
let _p = tracing::info_span!("handle_children_module").entered();
// locate children module by semantics
let _p = tracing::info_span!("handle_child_modules").entered();
// locate child module by semantics
let position = try_default!(from_proto::file_position(&snap, params)?);
let navs = snap.analysis.children_modules(position)?;
let navs = snap.analysis.child_modules(position)?;
let res = to_proto::goto_definition_response(&snap, None, navs)?;
Ok(Some(res))
}
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/lsp/capabilities.rs
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ pub fn server_capabilities(config: &Config) -> ServerCapabilities {
"onEnter": true,
"openCargoToml": true,
"parentModule": true,
"childrenModules": true,
"childModules": true,
"runnables": {
"kinds": [ "cargo" ],
},
Expand Down
6 changes: 3 additions & 3 deletions crates/rust-analyzer/src/lsp/ext.rs
Original file line number Diff line number Diff line change
Expand Up @@ -399,12 +399,12 @@ impl Request for ParentModule {
const METHOD: &'static str = "experimental/parentModule";
}

pub enum ChildrenModules {}
pub enum ChildModules {}

impl Request for ChildrenModules {
impl Request for ChildModules {
type Params = lsp_types::TextDocumentPositionParams;
type Result = Option<lsp_types::GotoDefinitionResponse>;
const METHOD: &'static str = "experimental/childrenModule";
const METHOD: &'static str = "experimental/childModules";
}

pub enum JoinLines {}
Expand Down
2 changes: 1 addition & 1 deletion crates/rust-analyzer/src/main_loop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1172,7 +1172,7 @@ impl GlobalState {
.on::<NO_RETRY, lsp_ext::InterpretFunction>(handlers::handle_interpret_function)
.on::<NO_RETRY, lsp_ext::ExpandMacro>(handlers::handle_expand_macro)
.on::<NO_RETRY, lsp_ext::ParentModule>(handlers::handle_parent_module)
.on::<NO_RETRY, lsp_ext::ChildrenModules>(handlers::handle_children_modules)
.on::<NO_RETRY, lsp_ext::ChildModules>(handlers::handle_child_modules)
.on::<NO_RETRY, lsp_ext::Runnables>(handlers::handle_runnables)
.on::<NO_RETRY, lsp_ext::RelatedTests>(handlers::handle_related_tests)
.on::<NO_RETRY, lsp_ext::CodeActionRequest>(handlers::handle_code_action)
Expand Down
2 changes: 1 addition & 1 deletion docs/book/src/contributing/lsp-extensions.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<!---
lsp/ext.rs hash: 300b4be5841cee6f
lsp/ext.rs hash: 78e87a78de8f288e

If you need to change the above hash to make the test pass, please check if you
need to adjust this doc as well and ping this issue:
Expand Down
6 changes: 3 additions & 3 deletions editors/code/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -171,8 +171,8 @@
"category": "rust-analyzer"
},
{
"command": "rust-analyzer.childrenModules",
"title": "Locate children modules",
"command": "rust-analyzer.childModules",
"title": "Locate child modules",
"category": "rust-analyzer"
},
{
Expand Down Expand Up @@ -3379,7 +3379,7 @@
"when": "inRustProject"
},
{
"command": "rust-analyzer.childrenModule",
"command": "rust-analyzer.childModules",
"when": "inRustProject"
},
{
Expand Down
4 changes: 2 additions & 2 deletions editors/code/src/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -266,15 +266,15 @@ export function parentModule(ctx: CtxInit): Cmd {
};
}

export function childrenModules(ctx: CtxInit): Cmd {
export function childModules(ctx: CtxInit): Cmd {
return async () => {
const editor = vscode.window.activeTextEditor;
if (!editor) return;
if (!(isRustDocument(editor.document) || isCargoTomlDocument(editor.document))) return;

const client = ctx.client;

const locations = await client.sendRequest(ra.childrenModules, {
const locations = await client.sendRequest(ra.childModules, {
textDocument: client.code2ProtocolConverter.asTextDocumentIdentifier(editor.document),
position: client.code2ProtocolConverter.asPosition(editor.selection.active),
});
Expand Down
4 changes: 2 additions & 2 deletions editors/code/src/lsp_ext.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,11 +194,11 @@ export const parentModule = new lc.RequestType<
lc.LocationLink[] | null,
void
>("experimental/parentModule");
export const childrenModules = new lc.RequestType<
export const childModules = new lc.RequestType<
lc.TextDocumentPositionParams,
lc.LocationLink[] | null,
void
>("experimental/childrenModule");
>("experimental/childModules");
export const runnables = new lc.RequestType<RunnablesParams, Runnable[], void>(
"experimental/runnables",
);
Expand Down
14 changes: 10 additions & 4 deletions editors/code/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -158,7 +158,7 @@ function createCommands(): Record<string, CommandFactory> {
matchingBrace: { enabled: commands.matchingBrace },
joinLines: { enabled: commands.joinLines },
parentModule: { enabled: commands.parentModule },
childrenModules: { enabled: commands.childrenModules },
childModules: { enabled: commands.childModules },
viewHir: { enabled: commands.viewHir },
viewMir: { enabled: commands.viewMir },
interpretFunction: { enabled: commands.interpretFunction },
Expand Down Expand Up @@ -188,7 +188,9 @@ function createCommands(): Record<string, CommandFactory> {
openWalkthrough: { enabled: commands.openWalkthrough },
// Internal commands which are invoked by the server.
applyActionGroup: { enabled: commands.applyActionGroup },
applySnippetWorkspaceEdit: { enabled: commands.applySnippetWorkspaceEditCommand },
applySnippetWorkspaceEdit: {
enabled: commands.applySnippetWorkspaceEditCommand,
},
debugSingle: { enabled: commands.debugSingle },
gotoLocation: { enabled: commands.gotoLocation },
hoverRefCommandProxy: { enabled: commands.hoverRefCommandProxy },
Expand All @@ -201,8 +203,12 @@ function createCommands(): Record<string, CommandFactory> {
revealDependency: { enabled: commands.revealDependency },
syntaxTreeReveal: { enabled: commands.syntaxTreeReveal },
syntaxTreeCopy: { enabled: commands.syntaxTreeCopy },
syntaxTreeHideWhitespace: { enabled: commands.syntaxTreeHideWhitespace },
syntaxTreeShowWhitespace: { enabled: commands.syntaxTreeShowWhitespace },
syntaxTreeHideWhitespace: {
enabled: commands.syntaxTreeHideWhitespace,
},
syntaxTreeShowWhitespace: {
enabled: commands.syntaxTreeShowWhitespace,
},
};
}

Expand Down