Skip to content

Commit 354298d

Browse files
committed
Rename to harp::env_parent()
1 parent 4d663c8 commit 354298d

File tree

5 files changed

+17
-19
lines changed

5 files changed

+17
-19
lines changed

crates/ark/src/lsp/completions/completion_item.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77

88
use std::fs::DirEntry;
99

10-
use harp::environment::r_env_parent;
1110
use harp::r_symbol;
1211
use harp::syntax::is_valid_symbol;
1312
use harp::syntax::sym_quote;
@@ -480,7 +479,7 @@ pub(super) unsafe fn completion_item_from_namespace(
480479
};
481480

482481
// Otherwise, try the imports environment.
483-
let imports = r_env_parent(namespace);
482+
let imports = harp::env_parent(namespace);
484483
let error_imports = match completion_item_from_symbol(
485484
name,
486485
imports,

crates/ark/src/lsp/completions/sources/composite/search_path.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
//
66
//
77

8-
use harp::environment::r_env_parent;
8+
use harp::env_parent;
99
use harp::exec::RFunction;
1010
use harp::exec::RFunctionExt;
1111
use harp::utils::r_env_is_pkg_env;
@@ -113,7 +113,7 @@ fn completions_from_search_path(
113113
}
114114

115115
// Get the next environment.
116-
env = r_env_parent(env);
116+
env = env_parent(env);
117117
}
118118

119119
// Include installed packages as well.

crates/harp/src/environment.rs

Lines changed: 1 addition & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ impl Environment {
7474
}
7575

7676
pub fn parent(&self) -> Option<Environment> {
77-
let parent = r_env_parent(self.inner.sexp);
77+
let parent = crate::r::env_parent(self.inner.sexp);
7878
if parent == R_ENVS.empty {
7979
None
8080
} else {
@@ -240,18 +240,6 @@ impl Environment {
240240
}
241241
}
242242

243-
/// Returns the parent (enclosing) environment. Uses `R_ParentEnv` on
244-
/// R >= 4.5 where `ENCLOS` is hidden, with fallback to `ENCLOS` for older R.
245-
pub fn r_env_parent(env: SEXP) -> SEXP {
246-
unsafe {
247-
if libr::has::R_ParentEnv() {
248-
libr::R_ParentEnv(env)
249-
} else {
250-
libr::ENCLOS(env)
251-
}
252-
}
253-
}
254-
255243
impl From<Environment> for SEXP {
256244
fn from(object: Environment) -> Self {
257245
object.inner.sexp

crates/harp/src/r.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,17 @@ pub fn env_bind_force(env: SEXP, sym: SEXP, value: SEXP) {
6666
}
6767
}
6868

69+
/// Returns the parent (enclosing) environment.
70+
pub fn env_parent(env: SEXP) -> SEXP {
71+
unsafe {
72+
if libr::has::R_ParentEnv() {
73+
libr::R_ParentEnv(env)
74+
} else {
75+
libr::ENCLOS(env)
76+
}
77+
}
78+
}
79+
6980
// --- Attributes ---
7081

7182
/// Gets an attribute from `x`.

crates/harp/src/size.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ use std::u32;
1313
use libc::c_double;
1414
use libr::*;
1515

16-
use crate::environment::r_env_parent;
1716
use crate::environment::BindingValue;
1817
use crate::environment::Environment;
1918
use crate::environment::R_ENVS;
@@ -22,6 +21,7 @@ use crate::object::r_chr_get;
2221
use crate::object::r_length;
2322
use crate::r::attrib_for_each;
2423
use crate::r::attrib_has_any;
24+
use crate::r::env_parent;
2525
use crate::r::fn_body;
2626
use crate::r::fn_env;
2727
use crate::r::fn_formals;
@@ -297,7 +297,7 @@ fn obj_size_tree(
297297
}
298298

299299
size += obj_size_tree(
300-
r_env_parent(x),
300+
env_parent(x),
301301
base_env,
302302
sizeof_node,
303303
sizeof_vector,

0 commit comments

Comments
 (0)