rubydex 0.1.0.beta14-aarch64-linux → 0.2.1-aarch64-linux

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};
@@ -9,9 +10,10 @@ use libc::{c_char, c_void};
9
10
  use rubydex::indexing::LanguageId;
10
11
  use rubydex::model::encoding::Encoding;
11
12
  use rubydex::model::graph::Graph;
12
- use rubydex::model::ids::{DeclarationId, NameId};
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};
@@ -260,6 +262,29 @@ pub unsafe extern "C" fn rdx_index_all(
260
262
  })
261
263
  }
262
264
 
265
+ /// Returns a pointer to the URI ID of the document identified by `uri`, or NULL if it doesn't exist.
266
+ /// Caller must free the returned pointer with `free_u64`.
267
+ ///
268
+ /// # Safety
269
+ ///
270
+ /// Expects both the graph pointer and uri string pointer to be valid
271
+ #[unsafe(no_mangle)]
272
+ pub unsafe extern "C" fn rdx_graph_get_document(pointer: GraphPointer, uri: *const c_char) -> *const u64 {
273
+ let Ok(uri_str) = (unsafe { utils::convert_char_ptr_to_string(uri) }) else {
274
+ return ptr::null();
275
+ };
276
+
277
+ with_graph(pointer, |graph| {
278
+ let uri_id = UriId::from(uri_str.as_str());
279
+
280
+ if graph.documents().contains_key(&uri_id) {
281
+ Box::into_raw(Box::new(*uri_id)).cast_const()
282
+ } else {
283
+ ptr::null()
284
+ }
285
+ })
286
+ }
287
+
263
288
  /// Deletes a document and all of its definitions from the graph.
264
289
  /// Returns a pointer to the URI ID if the document was found and removed, or NULL if it didn't exist.
265
290
  /// Caller must free the returned pointer with `free_u64`.
@@ -768,11 +793,15 @@ fn run_and_finalize_completion(
768
793
  ///
769
794
  /// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
770
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`.
771
799
  #[unsafe(no_mangle)]
772
800
  pub unsafe extern "C" fn rdx_graph_complete_expression(
773
801
  pointer: GraphPointer,
774
802
  nesting: *const *const c_char,
775
803
  nesting_count: usize,
804
+ self_receiver: *const c_char,
776
805
  ) -> CompletionResult {
777
806
  with_mut_graph(pointer, |graph| {
778
807
  let Some((name_id, names_to_untrack)) = (unsafe { completion_nesting_name_id(graph, nesting, nesting_count) })
@@ -780,7 +809,16 @@ pub unsafe extern "C" fn rdx_graph_complete_expression(
780
809
  return CompletionResult::success(ptr::null_mut());
781
810
  };
782
811
 
783
- 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
+ )
784
822
  })
785
823
  }
786
824
 
@@ -792,19 +830,27 @@ pub unsafe extern "C" fn rdx_graph_complete_expression(
792
830
  ///
793
831
  /// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
794
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).
795
835
  #[unsafe(no_mangle)]
796
836
  pub unsafe extern "C" fn rdx_graph_complete_namespace_access(
797
837
  pointer: GraphPointer,
798
838
  name: *const c_char,
839
+ self_receiver: *const c_char,
799
840
  ) -> CompletionResult {
800
841
  let Ok(name_str) = (unsafe { utils::convert_char_ptr_to_string(name) }) else {
801
842
  return CompletionResult::success(ptr::null_mut());
802
843
  };
803
844
 
804
845
  with_mut_graph(pointer, |graph| {
846
+ let self_decl_id = unsafe { decl_id_from_char_ptr(self_receiver) };
847
+
805
848
  run_and_finalize_completion(
806
849
  graph,
807
- 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
+ },
808
854
  Vec::new(),
809
855
  )
810
856
  })
@@ -818,19 +864,27 @@ pub unsafe extern "C" fn rdx_graph_complete_namespace_access(
818
864
  ///
819
865
  /// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
820
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.
821
869
  #[unsafe(no_mangle)]
822
870
  pub unsafe extern "C" fn rdx_graph_complete_method_call(
823
871
  pointer: GraphPointer,
824
872
  name: *const c_char,
873
+ self_receiver: *const c_char,
825
874
  ) -> CompletionResult {
826
875
  let Ok(name_str) = (unsafe { utils::convert_char_ptr_to_string(name) }) else {
827
876
  return CompletionResult::success(ptr::null_mut());
828
877
  };
829
878
 
830
879
  with_mut_graph(pointer, |graph| {
880
+ let self_decl_id = unsafe { decl_id_from_char_ptr(self_receiver) };
881
+
831
882
  run_and_finalize_completion(
832
883
  graph,
833
- 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
+ },
834
888
  Vec::new(),
835
889
  )
836
890
  })
@@ -845,28 +899,34 @@ pub unsafe extern "C" fn rdx_graph_complete_method_call(
845
899
  /// - `pointer` must be a valid `GraphPointer` previously returned by this crate.
846
900
  /// - `name` must be a valid, null-terminated UTF-8 string (FQN of the method).
847
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.
848
904
  #[unsafe(no_mangle)]
849
905
  pub unsafe extern "C" fn rdx_graph_complete_method_argument(
850
906
  pointer: GraphPointer,
851
907
  name: *const c_char,
852
908
  nesting: *const *const c_char,
853
909
  nesting_count: usize,
910
+ self_receiver: *const c_char,
854
911
  ) -> CompletionResult {
855
912
  let Ok(name_str) = (unsafe { utils::convert_char_ptr_to_string(name) }) else {
856
913
  return CompletionResult::success(ptr::null_mut());
857
914
  };
858
915
 
859
916
  with_mut_graph(pointer, |graph| {
860
- let Some((self_name_id, names_to_untrack)) =
917
+ let Some((nesting_name_id, names_to_untrack)) =
861
918
  (unsafe { completion_nesting_name_id(graph, nesting, nesting_count) })
862
919
  else {
863
920
  return CompletionResult::success(ptr::null_mut());
864
921
  };
865
922
 
923
+ let self_decl_id = unsafe { decl_id_from_char_ptr(self_receiver) };
924
+
866
925
  run_and_finalize_completion(
867
926
  graph,
868
927
  CompletionReceiver::MethodArgument {
869
- self_name_id,
928
+ self_decl_id,
929
+ nesting_name_id,
870
930
  method_decl_id: DeclarationId::from(name_str.as_str()),
871
931
  },
872
932
  names_to_untrack,
@@ -919,6 +979,53 @@ pub unsafe extern "C" fn rdx_keyword_get(name: *const c_char) -> *const CKeyword
919
979
  }
920
980
  }
921
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
+
922
1029
  /// Frees a `CKeyword` previously returned by `rdx_keyword_get`.
923
1030
  ///
924
1031
  /// # Safety
@@ -226,6 +226,43 @@ pub unsafe extern "C" fn rdx_resolved_constant_reference_declaration(
226
226
  })
227
227
  }
228
228
 
229
+ /// Returns the declaration of the resolved receiver for the given method reference. Returns NULL when the method
230
+ /// reference has no tracked receiver or when the receiver could not be resolved. Caller must free with
231
+ /// `free_c_declaration`.
232
+ ///
233
+ /// # Safety
234
+ ///
235
+ /// Assumes pointer is valid.
236
+ ///
237
+ /// # Panics
238
+ ///
239
+ /// This function will panic if the reference cannot be found.
240
+ #[unsafe(no_mangle)]
241
+ pub unsafe extern "C" fn rdx_method_reference_receiver_declaration(
242
+ pointer: GraphPointer,
243
+ reference_id: u64,
244
+ ) -> *const CDeclaration {
245
+ with_graph(pointer, |graph| {
246
+ let ref_id = MethodReferenceId::new(reference_id);
247
+ let reference = graph.method_references().get(&ref_id).expect("Reference not found");
248
+
249
+ let Some(name_id) = reference.receiver() else {
250
+ return ptr::null();
251
+ };
252
+
253
+ let name_ref = graph.names().get(&name_id).expect("Name ID should exist");
254
+
255
+ match name_ref {
256
+ NameRef::Resolved(resolved) => {
257
+ let decl_id = *resolved.declaration_id();
258
+ let decl = graph.declarations().get(&decl_id).expect("Declaration not found");
259
+ Box::into_raw(Box::new(CDeclaration::from_declaration(decl_id, decl))).cast_const()
260
+ }
261
+ NameRef::Unresolved(_) => ptr::null(),
262
+ }
263
+ })
264
+ }
265
+
229
266
  /// Returns a newly allocated `Location` for the given method reference id.
230
267
  /// Caller must free the returned pointer with `rdx_location_free`.
231
268
  ///
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.1.0.beta14
4
+ version: 0.2.1
5
5
  platform: aarch64-linux
6
6
  authors:
7
7
  - Shopify
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2026-04-28 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