Skip to content

Commit

Permalink
remove code duplication when creating codeLens
Browse files Browse the repository at this point in the history
  • Loading branch information
anaPerezGhiglia committed Jul 10, 2024
1 parent eac8d44 commit 2fa81e5
Showing 1 changed file with 16 additions and 40 deletions.
56 changes: 16 additions & 40 deletions tooling/lsp/src/requests/code_lens_request.rs
Original file line number Diff line number Diff line change
Expand Up @@ -156,46 +156,22 @@ pub(crate) fn collect_lenses_for_package(

lenses.push(compile_lens);

let info_command = Command {
title: INFO_CODELENS_TITLE.to_string(),
command: INFO_COMMAND.into(),
arguments: Some(package_selection_args(workspace, package)),
};

let info_lens = CodeLens { range, command: Some(info_command), data: None };

lenses.push(info_lens);

let execute_command = Command {
title: EXECUTE_CODELENS_TITLE.to_string(),
command: EXECUTE_COMMAND.into(),
arguments: Some(package_selection_args(workspace, package)),
};

let execute_lens = CodeLens { range, command: Some(execute_command), data: None };

lenses.push(execute_lens);

let profile_command = Command {
title: PROFILE_CODELENS_TITLE.to_string(),
command: PROFILE_COMMAND.into(),
arguments: Some(package_selection_args(workspace, package)),
};

let profile_lens = CodeLens { range, command: Some(profile_command), data: None };

lenses.push(profile_lens);


let debug_command = Command {
title: DEBUG_CODELENS_TITLE.to_string(),
command: DEBUG_COMMAND.into(),
arguments: Some(package_selection_args(workspace, package)),
};

let debug_lens = CodeLens { range, command: Some(debug_command), data: None };

lenses.push(debug_lens);
let internal_command_lenses = [
(INFO_CODELENS_TITLE, INFO_COMMAND),
(EXECUTE_CODELENS_TITLE, EXECUTE_COMMAND),
(PROFILE_CODELENS_TITLE, PROFILE_COMMAND),
(DEBUG_CODELENS_TITLE, DEBUG_COMMAND),
]
.map(|(title, command)| {
let command = Command {
title: title.to_string(),
command: command.into(),
arguments: Some(package_selection_args(workspace, package)),
};
CodeLens { range, command: Some(command), data: None }
});

lenses.append(&mut Vec::from(internal_command_lenses));
}
}

Expand Down

0 comments on commit 2fa81e5

Please sign in to comment.