rubydex 0.2.0 → 0.2.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -2,6 +2,7 @@
2
2
 
3
3
  use crate::declaration_api::CDeclaration;
4
4
  use crate::declaration_api::DeclarationsIter;
5
+ use crate::declaration_api::decl_id_from_char_ptr;
5
6
  use crate::document_api::DocumentsIter;
6
7
  use crate::reference_api::{CConstantReference, CMethodReference, ConstantReferencesIter, MethodReferencesIter};
7
8
  use crate::{name_api, utils};
@@ -12,6 +13,7 @@ use rubydex::model::graph::Graph;
12
13
  use rubydex::model::ids::{DeclarationId, NameId, UriId};
13
14
  use rubydex::model::keywords;
14
15
  use rubydex::model::name::NameRef;
16
+ use rubydex::model::visibility::Visibility;
15
17
  use rubydex::query::{CompletionCandidate, CompletionContext, CompletionReceiver};
16
18
  use rubydex::resolution::Resolver;
17
19
  use rubydex::{indexing, integrity, listing, query};
@@ -791,11 +793,15 @@ fn run_and_finalize_completion(
791
793
  ///
792
794
  /// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
793
795
  /// - `nesting` must point to `nesting_count` valid, null-terminated UTF-8 strings.
796
+ /// - `self_receiver` must be null or a valid, null-terminated UTF-8 string. When non-null, it
797
+ /// overrides the self-type (e.g., `"Foo::<Foo>"` for completion inside `def Foo.bar`), while
798
+ /// the lexical nesting still comes from `nesting`.
794
799
  #[unsafe(no_mangle)]
795
800
  pub unsafe extern "C" fn rdx_graph_complete_expression(
796
801
  pointer: GraphPointer,
797
802
  nesting: *const *const c_char,
798
803
  nesting_count: usize,
804
+ self_receiver: *const c_char,
799
805
  ) -> CompletionResult {
800
806
  with_mut_graph(pointer, |graph| {
801
807
  let Some((name_id, names_to_untrack)) = (unsafe { completion_nesting_name_id(graph, nesting, nesting_count) })
@@ -803,7 +809,16 @@ pub unsafe extern "C" fn rdx_graph_complete_expression(
803
809
  return CompletionResult::success(ptr::null_mut());
804
810
  };
805
811
 
806
- run_and_finalize_completion(graph, CompletionReceiver::Expression(name_id), names_to_untrack)
812
+ let self_decl_id = unsafe { decl_id_from_char_ptr(self_receiver) };
813
+
814
+ run_and_finalize_completion(
815
+ graph,
816
+ CompletionReceiver::Expression {
817
+ self_decl_id,
818
+ nesting_name_id: name_id,
819
+ },
820
+ names_to_untrack,
821
+ )
807
822
  })
808
823
  }
809
824
 
@@ -815,19 +830,27 @@ pub unsafe extern "C" fn rdx_graph_complete_expression(
815
830
  ///
816
831
  /// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
817
832
  /// - `name` must be a valid, null-terminated UTF-8 string (FQN of the namespace).
833
+ /// - `self_receiver` must be null or a valid, null-terminated UTF-8 string. When non-null, it
834
+ /// is the caller's runtime self type (e.g., for filtering `private_class_method` visibility).
818
835
  #[unsafe(no_mangle)]
819
836
  pub unsafe extern "C" fn rdx_graph_complete_namespace_access(
820
837
  pointer: GraphPointer,
821
838
  name: *const c_char,
839
+ self_receiver: *const c_char,
822
840
  ) -> CompletionResult {
823
841
  let Ok(name_str) = (unsafe { utils::convert_char_ptr_to_string(name) }) else {
824
842
  return CompletionResult::success(ptr::null_mut());
825
843
  };
826
844
 
827
845
  with_mut_graph(pointer, |graph| {
846
+ let self_decl_id = unsafe { decl_id_from_char_ptr(self_receiver) };
847
+
828
848
  run_and_finalize_completion(
829
849
  graph,
830
- CompletionReceiver::NamespaceAccess(DeclarationId::from(name_str.as_str())),
850
+ CompletionReceiver::NamespaceAccess {
851
+ self_decl_id,
852
+ namespace_decl_id: DeclarationId::from(name_str.as_str()),
853
+ },
831
854
  Vec::new(),
832
855
  )
833
856
  })
@@ -841,19 +864,27 @@ pub unsafe extern "C" fn rdx_graph_complete_namespace_access(
841
864
  ///
842
865
  /// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
843
866
  /// - `name` must be a valid, null-terminated UTF-8 string (FQN of the receiver).
867
+ /// - `self_receiver` must be null or a valid, null-terminated UTF-8 string. When non-null, it
868
+ /// is the caller's runtime self type, used for MRI-style visibility checks.
844
869
  #[unsafe(no_mangle)]
845
870
  pub unsafe extern "C" fn rdx_graph_complete_method_call(
846
871
  pointer: GraphPointer,
847
872
  name: *const c_char,
873
+ self_receiver: *const c_char,
848
874
  ) -> CompletionResult {
849
875
  let Ok(name_str) = (unsafe { utils::convert_char_ptr_to_string(name) }) else {
850
876
  return CompletionResult::success(ptr::null_mut());
851
877
  };
852
878
 
853
879
  with_mut_graph(pointer, |graph| {
880
+ let self_decl_id = unsafe { decl_id_from_char_ptr(self_receiver) };
881
+
854
882
  run_and_finalize_completion(
855
883
  graph,
856
- CompletionReceiver::MethodCall(DeclarationId::from(name_str.as_str())),
884
+ CompletionReceiver::MethodCall {
885
+ self_decl_id,
886
+ receiver_decl_id: DeclarationId::from(name_str.as_str()),
887
+ },
857
888
  Vec::new(),
858
889
  )
859
890
  })
@@ -868,28 +899,34 @@ pub unsafe extern "C" fn rdx_graph_complete_method_call(
868
899
  /// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
869
900
  /// - `name` must be a valid, null-terminated UTF-8 string (FQN of the method).
870
901
  /// - `nesting` must point to `nesting_count` valid, null-terminated UTF-8 strings.
902
+ /// - `self_receiver` must be null or a valid, null-terminated UTF-8 string. See
903
+ /// `rdx_graph_complete_expression` for semantics.
871
904
  #[unsafe(no_mangle)]
872
905
  pub unsafe extern "C" fn rdx_graph_complete_method_argument(
873
906
  pointer: GraphPointer,
874
907
  name: *const c_char,
875
908
  nesting: *const *const c_char,
876
909
  nesting_count: usize,
910
+ self_receiver: *const c_char,
877
911
  ) -> CompletionResult {
878
912
  let Ok(name_str) = (unsafe { utils::convert_char_ptr_to_string(name) }) else {
879
913
  return CompletionResult::success(ptr::null_mut());
880
914
  };
881
915
 
882
916
  with_mut_graph(pointer, |graph| {
883
- let Some((self_name_id, names_to_untrack)) =
917
+ let Some((nesting_name_id, names_to_untrack)) =
884
918
  (unsafe { completion_nesting_name_id(graph, nesting, nesting_count) })
885
919
  else {
886
920
  return CompletionResult::success(ptr::null_mut());
887
921
  };
888
922
 
923
+ let self_decl_id = unsafe { decl_id_from_char_ptr(self_receiver) };
924
+
889
925
  run_and_finalize_completion(
890
926
  graph,
891
927
  CompletionReceiver::MethodArgument {
892
- self_name_id,
928
+ self_decl_id,
929
+ nesting_name_id,
893
930
  method_decl_id: DeclarationId::from(name_str.as_str()),
894
931
  },
895
932
  names_to_untrack,
@@ -942,6 +979,53 @@ pub unsafe extern "C" fn rdx_keyword_get(name: *const c_char) -> *const CKeyword
942
979
  }
943
980
  }
944
981
 
982
+ #[repr(u8)]
983
+ #[derive(Debug, Clone, Copy)]
984
+ pub enum CVisibility {
985
+ Public = 0,
986
+ Protected = 1,
987
+ Private = 2,
988
+ }
989
+
990
+ /// Returns the visibility of a declaration (method, constant, class, or module) as a heap-allocated
991
+ /// `CVisibility`, or NULL when the declaration carries no visibility (e.g. variables, singleton
992
+ /// classes, todos). Caller must free the returned pointer with `free_c_visibility`.
993
+ ///
994
+ /// # Safety
995
+ ///
996
+ /// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
997
+ #[unsafe(no_mangle)]
998
+ pub unsafe extern "C" fn rdx_graph_visibility(pointer: GraphPointer, declaration_id: u64) -> *const CVisibility {
999
+ with_graph(pointer, |graph| {
1000
+ let Some(visibility) = graph.visibility(&DeclarationId::new(declaration_id)) else {
1001
+ return ptr::null();
1002
+ };
1003
+
1004
+ let c_visibility = match visibility {
1005
+ Visibility::Public => CVisibility::Public,
1006
+ Visibility::Protected => CVisibility::Protected,
1007
+ Visibility::Private => CVisibility::Private,
1008
+ Visibility::ModuleFunction => {
1009
+ unimplemented!("module_function visibility translation is not implemented yet")
1010
+ }
1011
+ };
1012
+
1013
+ Box::into_raw(Box::new(c_visibility)).cast_const()
1014
+ })
1015
+ }
1016
+
1017
+ /// Frees a `CVisibility` previously returned by `rdx_graph_visibility`.
1018
+ ///
1019
+ /// # Safety
1020
+ ///
1021
+ /// - `ptr` must be a valid pointer previously returned by `rdx_graph_visibility`.
1022
+ #[unsafe(no_mangle)]
1023
+ pub unsafe extern "C" fn free_c_visibility(ptr: *const CVisibility) {
1024
+ unsafe {
1025
+ let _ = Box::from_raw(ptr.cast_mut());
1026
+ }
1027
+ }
1028
+
945
1029
  /// Frees a `CKeyword` previously returned by `rdx_keyword_get`.
946
1030
  ///
947
1031
  /// # Safety
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rubydex
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-05-01 00:00:00.000000000 Z
11
+ date: 2026-05-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A high-performance static analysis suite for Ruby, built in Rust with
14
14
  Ruby APIs