rust-merge 7.0.0

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.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: c38459e1d39971cade4fe28316b85c476ccdd6ef327ce876f9df133c48155a00
4
+ data.tar.gz: 44034fa2d21db2abc0fe6189e29123d44ccdea2ba36f9b9840c0e6dacd31130d
5
+ SHA512:
6
+ metadata.gz: 56383574edb836f7149e9b24f4c09d084c477b6cb1e8c42e1e6873dd0369fde3201ea4dddb7c8834101564f4a7bdb433e1fa8c34be74554b758c5e4f03e34cac
7
+ data.tar.gz: 75b5778bc46334c29f63cecc88b735a9e436f2678cf7a2f0ce086cab01f7a0ee15258596eaff701c36f686f8dc2bdea5b2ff79303db0278a68730487e5894b12
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Rust
4
+ module Merge
5
+ module Version
6
+ VERSION = "7.0.0"
7
+ end
8
+
9
+ VERSION = Version::VERSION
10
+ end
11
+ end
data/lib/rust/merge.rb ADDED
@@ -0,0 +1,129 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tree_haver"
4
+
5
+ module Rust
6
+ module Merge
7
+ PACKAGE_NAME = "rust-merge"
8
+ TREE_SITTER_BACKEND = TreeHaver::KREUZBERG_LANGUAGE_PACK_BACKEND
9
+ DESTINATION_WINS_ARRAY_POLICY = { surface: "array", name: "destination_wins_array" }.freeze
10
+
11
+ module_function
12
+
13
+ def rust_feature_profile
14
+ { family: "rust", supported_dialects: ["rust"], supported_policies: [DESTINATION_WINS_ARRAY_POLICY] }
15
+ end
16
+
17
+ def available_rust_backends
18
+ [TREE_SITTER_BACKEND]
19
+ end
20
+
21
+ def rust_backend_feature_profile(backend: nil)
22
+ requested = backend.to_s.empty? ? TREE_SITTER_BACKEND.id : backend.to_s
23
+ return unsupported_feature_result("Unsupported Rust backend #{requested}.") unless requested == TREE_SITTER_BACKEND.id
24
+
25
+ rust_feature_profile.merge(
26
+ backend: requested,
27
+ backend_ref: TREE_SITTER_BACKEND.to_h,
28
+ supports_dialects: true
29
+ )
30
+ end
31
+
32
+ def rust_plan_context(backend: nil)
33
+ profile = rust_backend_feature_profile(backend: backend)
34
+ return profile if profile[:ok] == false
35
+
36
+ {
37
+ family_profile: rust_feature_profile,
38
+ feature_profile: {
39
+ backend: profile[:backend],
40
+ supports_dialects: true,
41
+ supported_policies: profile[:supported_policies]
42
+ }
43
+ }
44
+ end
45
+
46
+ def parse_rust(source, dialect)
47
+ return analyze_rust_module(source) if dialect == "rust"
48
+
49
+ { ok: false, diagnostics: [{ severity: "error", category: "unsupported_feature", message: "Unsupported Rust dialect #{dialect}." }], policies: [] }
50
+ end
51
+
52
+ def match_rust_owners(template, destination)
53
+ destination_paths = destination[:owners].to_h { |owner| [owner[:path], true] }
54
+ template_paths = template[:owners].to_h { |owner| [owner[:path], true] }
55
+ {
56
+ matched: template[:owners].filter { |owner| destination_paths[owner[:path]] }.map { |owner| { template_path: owner[:path], destination_path: owner[:path] } },
57
+ unmatched_template: template[:owners].map { |owner| owner[:path] }.reject { |path| destination_paths[path] },
58
+ unmatched_destination: destination[:owners].map { |owner| owner[:path] }.reject { |path| template_paths[path] }
59
+ }
60
+ end
61
+
62
+ def merge_rust(template_source, destination_source, dialect)
63
+ template = parse_rust(template_source, dialect)
64
+ return { ok: false, diagnostics: template[:diagnostics], policies: [] } unless template[:ok]
65
+ destination = parse_rust(destination_source, dialect)
66
+ unless destination[:ok]
67
+ return {
68
+ ok: false,
69
+ diagnostics: destination[:diagnostics].map { |diagnostic| diagnostic[:category] == "parse_error" ? diagnostic.merge(category: "destination_parse_error") : diagnostic },
70
+ policies: []
71
+ }
72
+ end
73
+
74
+ destination_declarations = destination.dig(:analysis, :declarations).to_h { |item| [item[:path], item] }
75
+ merged_declaration_texts = destination.dig(:analysis, :declarations).map { |item| item[:text] } +
76
+ template.dig(:analysis, :declarations).reject { |item| destination_declarations[item[:path]] }.map { |item| item[:text] }
77
+ import_block = destination.dig(:analysis, :imports).map { |item| item[:text] }.join
78
+ declaration_block = merged_declaration_texts.join("\n").rstrip
79
+ sections = [import_block.rstrip, declaration_block].reject(&:empty?)
80
+ { ok: true, diagnostics: [], output: "#{sections.join("\n\n").rstrip}\n", policies: [DESTINATION_WINS_ARRAY_POLICY] }
81
+ end
82
+
83
+ def analyze_rust_module(source)
84
+ parsed = TreeHaver.parse_with_language_pack(TreeHaver::ParserRequest.new(source: source, language: "rust", dialect: "rust"))
85
+ return { ok: false, diagnostics: parsed[:diagnostics], policies: [] } unless parsed[:ok]
86
+ processed = TreeHaver.process_with_language_pack(TreeHaver::ProcessRequest.new(source: source, language: "rust"))
87
+ return { ok: false, diagnostics: processed[:diagnostics], policies: [] } unless processed[:ok]
88
+
89
+ imports = processed[:analysis].imports.each_with_index.map do |item, index|
90
+ { path: "/imports/#{index}", match_key: normalize_rust_import_path(item.source), text: import_text(source, item.span) }
91
+ end
92
+ declarations = processed[:analysis].structure
93
+ .select { |item| item.name }
94
+ .map { |item| { path: "/declarations/#{item.name}", match_key: item.name, text: declaration_text(source, item.span) } }
95
+ .sort_by { |item| item[:path] }
96
+
97
+ {
98
+ ok: true,
99
+ diagnostics: [],
100
+ analysis: {
101
+ kind: "rust",
102
+ dialect: "rust",
103
+ source: source,
104
+ owners: imports.map { |item| { path: item[:path], owner_kind: "import", match_key: item[:match_key] } } +
105
+ declarations.map { |item| { path: item[:path], owner_kind: "declaration", match_key: item[:match_key] } },
106
+ imports: imports,
107
+ declarations: declarations
108
+ },
109
+ policies: []
110
+ }
111
+ end
112
+ private_class_method :analyze_rust_module
113
+
114
+ def normalize_rust_import_path(import_source)
115
+ import_source.sub(/\Ause\s+/, "").sub(/;\z/, "").strip
116
+ end
117
+ private_class_method :normalize_rust_import_path
118
+
119
+ def import_text(source, span) = "#{slice_span(source, span)}\n"
120
+ def declaration_text(source, span) = "#{line_anchored_slice(source, span)}\n"
121
+ def slice_span(source, span) = source[span.start_byte...span.end_byte].strip
122
+ def line_anchored_slice(source, span)
123
+ line_start = source.rindex("\n", [span.start_byte - 1, 0].max)
124
+ line_start = line_start ? line_start + 1 : 0
125
+ source[line_start...span.end_byte].strip
126
+ end
127
+ private_class_method :import_text, :declaration_text, :slice_span, :line_anchored_slice
128
+ end
129
+ end
data/lib/rust-merge.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "rust/merge"
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,110 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rust-merge
3
+ version: !ruby/object:Gem::Version
4
+ version: 7.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Peter H. Boling
8
+ bindir: bin
9
+ cert_chain:
10
+ - |
11
+ -----BEGIN CERTIFICATE-----
12
+ MIIEgDCCAuigAwIBAgIBATANBgkqhkiG9w0BAQsFADBDMRUwEwYDVQQDDAxwZXRl
13
+ ci5ib2xpbmcxFTATBgoJkiaJk/IsZAEZFgVnbWFpbDETMBEGCgmSJomT8ixkARkW
14
+ A2NvbTAeFw0yNTA1MDQxNTMzMDlaFw00NTA0MjkxNTMzMDlaMEMxFTATBgNVBAMM
15
+ DHBldGVyLmJvbGluZzEVMBMGCgmSJomT8ixkARkWBWdtYWlsMRMwEQYKCZImiZPy
16
+ LGQBGRYDY29tMIIBojANBgkqhkiG9w0BAQEFAAOCAY8AMIIBigKCAYEAruUoo0WA
17
+ uoNuq6puKWYeRYiZekz/nsDeK5x/0IEirzcCEvaHr3Bmz7rjo1I6On3gGKmiZs61
18
+ LRmQ3oxy77ydmkGTXBjruJB+pQEn7UfLSgQ0xa1/X3kdBZt6RmabFlBxnHkoaGY5
19
+ mZuZ5+Z7walmv6sFD9ajhzj+oIgwWfnEHkXYTR8I6VLN7MRRKGMPoZ/yvOmxb2DN
20
+ coEEHWKO9CvgYpW7asIihl/9G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Y9pzV5gGr2I8YUxMqf6ATrZt
36
+ L9nRqA==
37
+ -----END CERTIFICATE-----
38
+ date: 1980-01-02 00:00:00.000000000 Z
39
+ dependencies:
40
+ - !ruby/object:Gem::Dependency
41
+ name: ast-merge
42
+ requirement: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - '='
45
+ - !ruby/object:Gem::Version
46
+ version: 7.0.0
47
+ type: :runtime
48
+ prerelease: false
49
+ version_requirements: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - '='
52
+ - !ruby/object:Gem::Version
53
+ version: 7.0.0
54
+ - !ruby/object:Gem::Dependency
55
+ name: tree_haver
56
+ requirement: !ruby/object:Gem::Requirement
57
+ requirements:
58
+ - - '='
59
+ - !ruby/object:Gem::Version
60
+ version: 7.0.0
61
+ type: :runtime
62
+ prerelease: false
63
+ version_requirements: !ruby/object:Gem::Requirement
64
+ requirements:
65
+ - - '='
66
+ - !ruby/object:Gem::Version
67
+ version: 7.0.0
68
+ description: Portable Rust module owner analysis and merge behavior for Structured
69
+ Merge.
70
+ email:
71
+ - info@structuredmerge.org
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/rust-merge.rb
77
+ - lib/rust/merge.rb
78
+ - lib/rust/merge/version.rb
79
+ homepage: https://github.com/structuredmerge/structuredmerge-ruby
80
+ licenses:
81
+ - AGPL-3.0-only
82
+ - PolyForm-Small-Business-1.0.0
83
+ metadata:
84
+ homepage_uri: https://structuredmerge.org
85
+ source_code_uri: https://github.com/structuredmerge/structuredmerge-ruby/tree/v7.0.0
86
+ changelog_uri: https://github.com/structuredmerge/structuredmerge-ruby/blob/v7.0.0/CHANGELOG.md
87
+ bug_tracker_uri: https://github.com/structuredmerge/structuredmerge-ruby/issues
88
+ documentation_uri: https://www.rubydoc.info/gems/rust-merge/7.0.0
89
+ funding_uri: https://github.com/sponsors/pboling
90
+ wiki_uri: https://github.com/structuredmerge/structuredmerge-ruby/wiki
91
+ discord_uri: https://discord.gg/3qme4XHNKN
92
+ rubygems_mfa_required: 'true'
93
+ rdoc_options: []
94
+ require_paths:
95
+ - lib
96
+ required_ruby_version: !ruby/object:Gem::Requirement
97
+ requirements:
98
+ - - ">="
99
+ - !ruby/object:Gem::Version
100
+ version: 4.0.0
101
+ required_rubygems_version: !ruby/object:Gem::Requirement
102
+ requirements:
103
+ - - ">="
104
+ - !ruby/object:Gem::Version
105
+ version: '0'
106
+ requirements: []
107
+ rubygems_version: 4.0.10
108
+ specification_version: 4
109
+ summary: Structured Merge Rust module analysis and merge for Ruby
110
+ test_files: []
metadata.gz.sig ADDED
Binary file