rubydex 0.3.0 → 0.4.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.
Files changed (96) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +29 -7
  3. data/THIRD_PARTY_LICENSES.html +238 -2
  4. data/exe/rdx +2 -149
  5. data/ext/rubydex/config.c +140 -0
  6. data/ext/rubydex/config.h +16 -0
  7. data/ext/rubydex/definition.c +34 -0
  8. data/ext/rubydex/definition.h +3 -0
  9. data/ext/rubydex/diagnostic.c +28 -1
  10. data/ext/rubydex/diagnostic.h +2 -0
  11. data/ext/rubydex/extconf.rb +4 -2
  12. data/ext/rubydex/graph.c +71 -55
  13. data/ext/rubydex/graph.h +6 -0
  14. data/ext/rubydex/query.c +398 -16
  15. data/ext/rubydex/rubydex.c +2 -0
  16. data/ext/rubydex/utils.c +11 -4
  17. data/lib/ruby_lsp/rubydex/addon.rb +211 -0
  18. data/lib/rubydex/cli/command/console.rb +55 -0
  19. data/lib/rubydex/cli/command/lint/explain.rb +76 -0
  20. data/lib/rubydex/cli/command/lint.rb +208 -0
  21. data/lib/rubydex/cli/command/mcp.rb +30 -0
  22. data/lib/rubydex/cli/command/query.rb +70 -0
  23. data/lib/rubydex/cli/command/skill.rb +69 -0
  24. data/lib/rubydex/cli/command.rb +168 -0
  25. data/lib/rubydex/cli.rb +93 -0
  26. data/lib/rubydex/config.rb +59 -0
  27. data/lib/rubydex/diagnostic.rb +12 -3
  28. data/lib/rubydex/errors.rb +42 -1
  29. data/lib/rubydex/graph.rb +10 -3
  30. data/lib/rubydex/linter/custom_rule.rb +97 -0
  31. data/lib/rubydex/linter/helpers/path_helpers.rb +78 -0
  32. data/lib/rubydex/linter/helpers/source_access_helpers.rb +31 -0
  33. data/lib/rubydex/linter/rule_loader.rb +36 -0
  34. data/lib/rubydex/linter/rule_test_case.rb +343 -0
  35. data/lib/rubydex/linter/runner.rb +56 -0
  36. data/lib/rubydex/linter.rb +19 -0
  37. data/lib/rubydex/location.rb +3 -0
  38. data/lib/rubydex/mcp_server.rb +1 -2
  39. data/lib/rubydex/related_information.rb +17 -0
  40. data/lib/rubydex/rule.rb +33 -0
  41. data/lib/rubydex/rules/dynamic_ancestor.rb +29 -0
  42. data/lib/rubydex/rules/dynamic_constant_reference.rb +25 -0
  43. data/lib/rubydex/rules/dynamic_singleton_definition.rb +30 -0
  44. data/lib/rubydex/rules/invalid_constant_visibility.rb +28 -0
  45. data/lib/rubydex/rules/invalid_method_visibility.rb +28 -0
  46. data/lib/rubydex/rules/parse_error.rb +25 -0
  47. data/lib/rubydex/rules/parse_warning.rb +28 -0
  48. data/lib/rubydex/rules/top_level_mixin_self.rb +27 -0
  49. data/lib/rubydex/rules/undefined_constant_visibility_target.rb +27 -0
  50. data/lib/rubydex/rules/undefined_method_visibility_target.rb +27 -0
  51. data/lib/rubydex/severity.rb +70 -0
  52. data/lib/rubydex/skill.rb +89 -0
  53. data/lib/rubydex/skill_registry.rb +62 -0
  54. data/lib/rubydex/version.rb +1 -1
  55. data/lib/rubydex.rb +8 -0
  56. data/lib/rubydex_linter/rules/rule_structure.rb +140 -0
  57. data/rbi/rubydex.rbi +464 -21
  58. data/rust/Cargo.lock +2 -2
  59. data/rust/rubydex/Cargo.toml +5 -1
  60. data/rust/rubydex/benches/graph_memory.rs +3 -5
  61. data/rust/rubydex/src/bin/generate_ruby_rules.rs +94 -0
  62. data/rust/rubydex/src/config.rs +538 -157
  63. data/rust/rubydex/src/diagnostic.rs +162 -45
  64. data/rust/rubydex/src/errors.rs +0 -1
  65. data/rust/rubydex/src/indexing/local_graph.rs +6 -5
  66. data/rust/rubydex/src/indexing/rbs_indexer.rs +270 -6
  67. data/rust/rubydex/src/indexing/ruby_indexer.rs +10 -12
  68. data/rust/rubydex/src/indexing/ruby_indexer_tests.rs +134 -81
  69. data/rust/rubydex/src/lib.rs +1 -0
  70. data/rust/rubydex/src/listing.rs +26 -1
  71. data/rust/rubydex/src/main.rs +7 -4
  72. data/rust/rubydex/src/model/declaration.rs +302 -219
  73. data/rust/rubydex/src/model/graph.rs +27 -40
  74. data/rust/rubydex/src/model/name.rs +58 -17
  75. data/rust/rubydex/src/operation/ruby_builder.rs +30 -45
  76. data/rust/rubydex/src/path_helpers.rs +77 -0
  77. data/rust/rubydex/src/query/cypher/schema.rs +63 -0
  78. data/rust/rubydex/src/query/cypher/tests.rs +26 -1
  79. data/rust/rubydex/src/query/cypher.rs +8 -11
  80. data/rust/rubydex/src/query.rs +314 -44
  81. data/rust/rubydex/src/resolution.rs +139 -187
  82. data/rust/rubydex/src/resolution_tests.rs +247 -19
  83. data/rust/rubydex/src/test_utils/context.rs +2 -1
  84. data/rust/rubydex/src/test_utils/graph_test.rs +26 -12
  85. data/rust/rubydex/src/test_utils/local_graph_test.rs +19 -0
  86. data/rust/rubydex/tests/cli.rs +4 -4
  87. data/rust/rubydex-sys/src/config_api.rs +205 -0
  88. data/rust/rubydex-sys/src/cypher_api.rs +791 -0
  89. data/rust/rubydex-sys/src/definition_api.rs +68 -1
  90. data/rust/rubydex-sys/src/diagnostic_api.rs +42 -8
  91. data/rust/rubydex-sys/src/graph_api.rs +125 -205
  92. data/rust/rubydex-sys/src/lib.rs +2 -0
  93. data/rust/rubydex-sys/src/name_api.rs +49 -17
  94. data/rust/rubydex-sys/src/utils.rs +37 -0
  95. data/skills/send-private-method/SKILL.md +133 -0
  96. metadata +42 -2
@@ -1,5 +1,5 @@
1
- use super::run_query;
2
1
  use super::schema::RelType;
2
+ use super::{render, run_query};
3
3
  use crate::model::graph::Graph;
4
4
  use crate::test_utils::GraphTest;
5
5
  use cypher_parser::{CypherValue, OutputFormat, ResultSet, execute, parse};
@@ -197,6 +197,31 @@ fn run_query_json_output() {
197
197
  assert_eq!(output, "[{\"c.name\":\"Dog\"}]");
198
198
  }
199
199
 
200
+ #[test]
201
+ fn render_formats_one_result_set_in_both_formats() {
202
+ // `execute` runs the query once; `render` formats that same result set as often as needed.
203
+ let graph = fixture_graph();
204
+ let result = run(&graph, "MATCH (c:Class {name: 'Dog'}) RETURN c.name");
205
+
206
+ assert_eq!(render(&result, OutputFormat::Json), "[{\"c.name\":\"Dog\"}]");
207
+
208
+ let table = render(&result, OutputFormat::Table);
209
+ assert!(table.contains("c.name"));
210
+ assert!(table.contains("Dog"));
211
+ assert!(table.contains("1 row"));
212
+ }
213
+
214
+ #[test]
215
+ fn incoming_declares_and_defines_reach_the_document() {
216
+ // Exercises `expand_in`: walk the Document -> Definition -> Declaration spine backwards.
217
+ let graph = fixture_graph();
218
+ let result = run(
219
+ &graph,
220
+ "MATCH (decl:Class {name: 'Dog'})<-[:DECLARES]-(def:Definition)<-[:DEFINES]-(d:Document) RETURN DISTINCT d.name",
221
+ );
222
+ assert_eq!(column_strings(&result, 0), vec!["zoo.rb".to_string()]);
223
+ }
224
+
200
225
  #[test]
201
226
  fn unknown_relationship_type_errors() {
202
227
  let graph = fixture_graph();
@@ -18,8 +18,9 @@
18
18
  // `Graph` (in `schema`) and the static schema description (in `schema_info`).
19
19
  //
20
20
  // `Query` is the opaque parsed-query object: callers can `parse` a query string once (failing fast
21
- // on syntax errors), then `run_parsed` it against a graph that was built afterwards.
22
- pub use cypher_parser::{CypherError, OutputFormat, Query, parse};
21
+ // on syntax errors), `execute` it against a graph that was built afterwards, and `render` the
22
+ // resulting [`ResultSet`] without running the query again.
23
+ pub use cypher_parser::{CypherError, CypherValue, OutputFormat, Query, ResultSet, execute, parse};
23
24
 
24
25
  pub mod schema;
25
26
  pub mod schema_info;
@@ -35,15 +36,11 @@ pub fn run_query(graph: &Graph, query: &str, output_format: OutputFormat) -> Res
35
36
  cypher_parser::run_query(graph, query, output_format)
36
37
  }
37
38
 
38
- /// Executes an already-parsed [`Query`] against the graph and formats the result. Pair with
39
- /// [`parse`] to validate a query before building the graph.
40
- ///
41
- /// # Errors
42
- ///
43
- /// Returns a [`CypherError`] if the query cannot be executed.
44
- pub fn run_parsed(graph: &Graph, query: &Query, output_format: OutputFormat) -> Result<String, CypherError> {
45
- let result = cypher_parser::execute(graph, query)?;
46
- Ok(cypher_parser::format::format(&result, output_format))
39
+ /// Renders an already-executed [`ResultSet`] in the requested format. Pair with [`execute`] to run a
40
+ /// parsed query once and render its result set as often as needed.
41
+ #[must_use]
42
+ pub fn render(result: &ResultSet, output_format: OutputFormat) -> String {
43
+ cypher_parser::format::format(result, output_format)
47
44
  }
48
45
 
49
46
  /// Returns a description of the queryable schema (node labels, relationship types, and properties)