Skip to content

Commit

Permalink
Remove r_ prefix
Browse files Browse the repository at this point in the history
These functions don't call R
  • Loading branch information
lionel- committed May 30, 2024
1 parent d62b93c commit 335eeca
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 24 deletions.
26 changes: 13 additions & 13 deletions crates/ark/src/lsp/completions/completion_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,16 +10,16 @@ use std::fs::DirEntry;
use anyhow::bail;
use anyhow::Result;
use harp::r_symbol;
use harp::utils::is_symbol_valid;
use harp::utils::r_env_binding_is_active;
use harp::utils::r_envir_name;
use harp::utils::r_formals;
use harp::utils::r_promise_force_with_rollback;
use harp::utils::r_promise_is_forced;
use harp::utils::r_promise_is_lazy_load_binding;
use harp::utils::r_symbol_quote;
use harp::utils::r_symbol_quote_invalid;
use harp::utils::r_symbol_valid;
use harp::utils::r_typeof;
use harp::utils::sym_quote;
use harp::utils::sym_quote_invalid;
use libr::R_UnboundValue;
use libr::Rf_findVarInFrame;
use libr::Rf_isFunction;
Expand Down Expand Up @@ -178,7 +178,7 @@ pub(super) fn completion_item_from_function<T: AsRef<str>>(
let detail = format!("{}({})", name, parameters.joined(", "));
item.detail = Some(detail);

let insert_text = r_symbol_quote_invalid(name);
let insert_text = sym_quote_invalid(name);
item.insert_text_format = Some(InsertTextFormat::SNIPPET);
item.insert_text = Some(format!("{insert_text}($0)"));

Expand Down Expand Up @@ -211,8 +211,8 @@ pub(super) unsafe fn completion_item_from_data_variable(

if enquote {
item.insert_text = Some(format!("\"{}\"", name));
} else if !r_symbol_valid(name) {
item.insert_text = Some(r_symbol_quote(name));
} else if !is_symbol_valid(name) {
item.insert_text = Some(sym_quote(name));
}

item.detail = Some(owner.to_string());
Expand Down Expand Up @@ -253,8 +253,8 @@ pub(super) unsafe fn completion_item_from_object(
item.detail = Some("(Object)".to_string());
item.kind = Some(CompletionItemKind::STRUCT);

if !r_symbol_valid(name) {
item.insert_text = Some(r_symbol_quote(name));
if !is_symbol_valid(name) {
item.insert_text = Some(sym_quote(name));
}

Ok(item)
Expand Down Expand Up @@ -293,8 +293,8 @@ pub(super) unsafe fn completion_item_from_promise(
item.detail = Some("Promise".to_string());
item.kind = Some(CompletionItemKind::STRUCT);

if !r_symbol_valid(name) {
item.insert_text = Some(r_symbol_quote(name));
if !is_symbol_valid(name) {
item.insert_text = Some(sym_quote(name));
}

Ok(item)
Expand All @@ -310,8 +310,8 @@ pub(super) fn completion_item_from_active_binding(name: &str) -> Result<Completi
item.detail = Some("Active binding".to_string());
item.kind = Some(CompletionItemKind::STRUCT);

if !r_symbol_valid(name) {
item.insert_text = Some(r_symbol_quote(name));
if !is_symbol_valid(name) {
item.insert_text = Some(sym_quote(name));
}

Ok(item)
Expand Down Expand Up @@ -433,7 +433,7 @@ pub(super) fn completion_item_from_parameter(
function: callee.to_string(),
};

let parameter = r_symbol_quote_invalid(parameter);
let parameter = sym_quote_invalid(parameter);

// We want to display to the user the name with the `=`
let label = parameter.clone() + " = ";
Expand Down
4 changes: 2 additions & 2 deletions crates/ark/src/lsp/completions/sources/unique/custom.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use anyhow::Result;
use harp::exec::RFunction;
use harp::exec::RFunctionExt;
use harp::object::RObject;
use harp::utils::r_symbol_quote_invalid;
use harp::utils::sym_quote_invalid;
use harp::utils::r_typeof;
use libr::R_NilValue;
use libr::VECSXP;
Expand Down Expand Up @@ -183,7 +183,7 @@ pub fn completions_from_custom_source_impl(
if enquote && !node.is_string() {
item.insert_text = Some(format!("\"{value}\""));
} else {
let mut insert_text = r_symbol_quote_invalid(value.as_str());
let mut insert_text = sym_quote_invalid(value.as_str());

if !append.is_empty() {
insert_text = format!("{insert_text}{append}");
Expand Down
8 changes: 4 additions & 4 deletions crates/ark/src/lsp/diagnostics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@ use harp::exec::RFunctionExt;
use harp::external_ptr::ExternalPointer;
use harp::object::RObject;
use harp::r_symbol;
use harp::utils::is_symbol_valid;
use harp::utils::r_is_null;
use harp::utils::r_symbol_quote_invalid;
use harp::utils::r_symbol_valid;
use harp::utils::sym_quote_invalid;
use libr::R_NilValue;
use libr::Rf_ScalarInteger;
use libr::Rf_allocVector;
Expand Down Expand Up @@ -286,10 +286,10 @@ fn generate_diagnostics(doc: &Document, state: &WorldState) -> Vec<Diagnostic> {

for scope in state.console_scopes.lock().iter() {
for name in scope.iter() {
if r_symbol_valid(name.as_str()) {
if is_symbol_valid(name.as_str()) {
context.session_symbols.insert(name.clone());
} else {
let name = r_symbol_quote_invalid(name.as_str());
let name = sym_quote_invalid(name.as_str());
context.session_symbols.insert(name.clone());
}
}
Expand Down
10 changes: 5 additions & 5 deletions crates/harp/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,19 +497,19 @@ pub unsafe fn r_inspect(object: SEXP) {
Rf_eval(internal, R_BaseEnv);
}

pub fn r_symbol_valid(name: &str) -> bool {
pub fn is_symbol_valid(name: &str) -> bool {
RE_SYNTACTIC_IDENTIFIER.is_match(name)
}

pub fn r_symbol_quote_invalid(name: &str) -> String {
if RE_SYNTACTIC_IDENTIFIER.is_match(name) {
pub fn sym_quote_invalid(name: &str) -> String {
if is_symbol_valid(name) {
name.to_string()
} else {
r_symbol_quote(name)
sym_quote(name)
}
}

pub fn r_symbol_quote(name: &str) -> String {
pub fn sym_quote(name: &str) -> String {
format!("`{}`", name.replace("`", "\\`"))
}

Expand Down

0 comments on commit 335eeca

Please sign in to comment.