go-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: '05906de20bc8bf7f1421bca4a76a0b70769bf77c39a1c5a95c529afaba978a62'
4
+ data.tar.gz: b5988a169b45234e975361f26dbadd6acf887e8eb10dddbb2c6ee067a03e7cb4
5
+ SHA512:
6
+ metadata.gz: 11df7df7c5ebc207c4908fa2341213de80cb7759f07a53d07ba05358b5e1f9aa5e06b9900887d7f838de3cb40c2d5ff04df5cdadae3f91279ca898fc1e9fb6fe
7
+ data.tar.gz: 0fc22e8f3580fa233e037484812218031d0e4944984fa18b9d3e8fcac66cd47389bcf0c2f0fe674708f431a088476e4e7f1dd31d761dee0e3b0b4bc5adab1318
checksums.yaml.gz.sig ADDED
Binary file
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Go
4
+ module Merge
5
+ module Version
6
+ VERSION = "7.0.0"
7
+ end
8
+
9
+ VERSION = Version::VERSION
10
+ end
11
+ end
data/lib/go/merge.rb ADDED
@@ -0,0 +1,143 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "tree_haver"
4
+ require "ast/merge"
5
+
6
+ module Go
7
+ module Merge
8
+ extend self
9
+
10
+ PACKAGE_NAME = "go-merge"
11
+ TREE_SITTER_BACKEND = TreeHaver::KREUZBERG_LANGUAGE_PACK_BACKEND
12
+ DESTINATION_WINS_ARRAY_POLICY = { surface: "array", name: "destination_wins_array" }.freeze
13
+
14
+ def go_feature_profile
15
+ { family: "go", supported_dialects: ["go"], supported_policies: [DESTINATION_WINS_ARRAY_POLICY] }
16
+ end
17
+
18
+ def available_go_backends
19
+ [TREE_SITTER_BACKEND]
20
+ end
21
+
22
+ def go_backend_feature_profile(backend: nil)
23
+ requested = backend.to_s.empty? ? TREE_SITTER_BACKEND.id : backend.to_s
24
+ return unsupported_feature_result("Unsupported Go backend #{requested}.") unless requested == TREE_SITTER_BACKEND.id
25
+
26
+ go_feature_profile.merge(
27
+ backend: requested,
28
+ backend_ref: TREE_SITTER_BACKEND.to_h,
29
+ supports_dialects: true
30
+ )
31
+ end
32
+
33
+ def go_plan_context(backend: nil)
34
+ profile = go_backend_feature_profile(backend: backend)
35
+ return profile if profile[:ok] == false
36
+
37
+ {
38
+ family_profile: go_feature_profile,
39
+ feature_profile: {
40
+ backend: profile[:backend],
41
+ supports_dialects: true,
42
+ supported_policies: profile[:supported_policies]
43
+ }
44
+ }
45
+ end
46
+
47
+ def parse_go(source, dialect)
48
+ requested = TREE_SITTER_BACKEND.id
49
+ return unsupported_feature_result("Unsupported Go backend #{requested}.") unless requested == TREE_SITTER_BACKEND.id
50
+ return analyze_go_module(source) if dialect == "go"
51
+
52
+ { ok: false, diagnostics: [{ severity: "error", category: "unsupported_feature", message: "Unsupported Go dialect #{dialect}." }], policies: [] }
53
+ end
54
+
55
+ def match_go_owners(template, destination)
56
+ destination_paths = destination[:owners].to_h { |owner| [owner[:path], true] }
57
+ template_paths = template[:owners].to_h { |owner| [owner[:path], true] }
58
+ {
59
+ matched: template[:owners].filter { |owner| destination_paths[owner[:path]] }.map { |owner| { template_path: owner[:path], destination_path: owner[:path] } },
60
+ unmatched_template: template[:owners].map { |owner| owner[:path] }.reject { |path| destination_paths[path] },
61
+ unmatched_destination: destination[:owners].map { |owner| owner[:path] }.reject { |path| template_paths[path] }
62
+ }
63
+ end
64
+
65
+ def merge_go(template_source, destination_source, dialect)
66
+ template = parse_go(template_source, dialect)
67
+ return { ok: false, diagnostics: template[:diagnostics], policies: [] } unless template[:ok]
68
+ destination = parse_go(destination_source, dialect)
69
+ unless destination[:ok]
70
+ return {
71
+ ok: false,
72
+ diagnostics: destination[:diagnostics].map { |diagnostic| diagnostic[:category] == "parse_error" ? diagnostic.merge(category: "destination_parse_error") : diagnostic },
73
+ policies: []
74
+ }
75
+ end
76
+
77
+ destination_declarations = destination.dig(:analysis, :declarations).to_h { |item| [item[:path], item] }
78
+ merged_declaration_texts = destination.dig(:analysis, :declarations).map { |item| item[:text] } +
79
+ template.dig(:analysis, :declarations).reject { |item| destination_declarations[item[:path]] }.map { |item| item[:text] }
80
+ import_block = destination.dig(:analysis, :imports).map { |item| item[:text] }.join
81
+ declaration_block = merged_declaration_texts.join("\n").rstrip
82
+ sections = [import_block.rstrip, declaration_block].reject(&:empty?)
83
+ { ok: true, diagnostics: [], output: "#{sections.join("\n\n").rstrip}\n", policies: [DESTINATION_WINS_ARRAY_POLICY] }
84
+ end
85
+
86
+ def analyze_go_module(source)
87
+ parsed = TreeHaver.parse_with_language_pack(TreeHaver::ParserRequest.new(source: source, language: "go", dialect: "go"))
88
+ return { ok: false, diagnostics: parsed[:diagnostics], policies: [] } unless parsed[:ok]
89
+ processed = TreeHaver.process_with_language_pack(TreeHaver::ProcessRequest.new(source: source, language: "go"))
90
+ return { ok: false, diagnostics: processed[:diagnostics], policies: [] } unless processed[:ok]
91
+
92
+ deduped_imports = {}
93
+ processed[:analysis].imports.each do |item|
94
+ match_key = normalize_go_import_path(item.source)
95
+ candidate = { path: nil, match_key: match_key, text: import_text(source, item.span) }
96
+ current = deduped_imports[match_key]
97
+ deduped_imports[match_key] = candidate if current.nil? || candidate[:text].length > current[:text].length
98
+ end
99
+ imports = deduped_imports.values.each_with_index.map { |item, index| item.merge(path: "/imports/#{index}") }
100
+ declarations = processed[:analysis].structure
101
+ .select { |item| item.name }
102
+ .map { |item| { path: "/declarations/#{item.name}", match_key: item.name, text: declaration_text(source, item.span) } }
103
+ .sort_by { |item| item[:path] }
104
+
105
+ {
106
+ ok: true,
107
+ diagnostics: [],
108
+ analysis: {
109
+ kind: "go",
110
+ dialect: "go",
111
+ source: source,
112
+ owners: imports.map { |item| { path: item[:path], owner_kind: "import", match_key: item[:match_key] } } +
113
+ declarations.map { |item| { path: item[:path], owner_kind: "declaration", match_key: item[:match_key] } },
114
+ imports: imports,
115
+ declarations: declarations
116
+ },
117
+ policies: []
118
+ }
119
+ end
120
+ private_class_method :analyze_go_module
121
+
122
+ def normalize_go_import_path(import_source)
123
+ match = import_source.match(/"([^"]+)"/)
124
+ match ? match[1] : import_source.sub(/\Aimport\s+/, "").strip
125
+ end
126
+ private_class_method :normalize_go_import_path
127
+
128
+ def import_text(source, span) = "#{slice_span(source, span)}\n"
129
+ def declaration_text(source, span) = "#{line_anchored_slice(source, span)}\n"
130
+ def slice_span(source, span) = source[span.start_byte...span.end_byte].strip
131
+ def line_anchored_slice(source, span)
132
+ line_start = source.rindex("\n", [span.start_byte - 1, 0].max)
133
+ line_start = line_start ? line_start + 1 : 0
134
+ source[line_start...span.end_byte].strip
135
+ end
136
+ private_class_method :import_text, :declaration_text, :slice_span, :line_anchored_slice
137
+
138
+ def unsupported_feature_result(message)
139
+ Ast::Merge.unsupported_feature_result(message)
140
+ end
141
+ private_class_method :unsupported_feature_result
142
+ end
143
+ end
data/lib/go-merge.rb ADDED
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "go/merge"
data.tar.gz.sig ADDED
Binary file
metadata ADDED
@@ -0,0 +1,109 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: go-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
+ LGQBGRYDY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LTF1HMSJXZ7/pkxLCsB8m4EFVdb/IrW/0k
32
+ kNSfjtAfBHO8nLGuqQZVH9IBD1i9K6aSs7pT6TW8itXUIlkIUI2tg5YzW6OFfPzq
33
+ QekSkX3lZfY+HTSp/o+YvKkqWLUV7PQ7xh1ZYDtocpaHwgxe/j3bBqHE+CUPH2vA
34
+ 0V/FwdTRWcwsjVoOJTrYcff8pBZ8r2MvtAc54xfnnhGFzeRHfcltobgFxkAXdE6p
35
+ DVjBtqT23eugOqQ73umLcYDZkc36vnqGxUBSsXrzY9pzV5gGr2I8YUxMqf6ATrZt
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 Go module owner analysis and merge behavior for Structured Merge.
69
+ email:
70
+ - info@structuredmerge.org
71
+ executables: []
72
+ extensions: []
73
+ extra_rdoc_files: []
74
+ files:
75
+ - lib/go-merge.rb
76
+ - lib/go/merge.rb
77
+ - lib/go/merge/version.rb
78
+ homepage: https://github.com/structuredmerge/structuredmerge-ruby
79
+ licenses:
80
+ - AGPL-3.0-only
81
+ - PolyForm-Small-Business-1.0.0
82
+ metadata:
83
+ homepage_uri: https://structuredmerge.org
84
+ source_code_uri: https://github.com/structuredmerge/structuredmerge-ruby/tree/v7.0.0
85
+ changelog_uri: https://github.com/structuredmerge/structuredmerge-ruby/blob/v7.0.0/CHANGELOG.md
86
+ bug_tracker_uri: https://github.com/structuredmerge/structuredmerge-ruby/issues
87
+ documentation_uri: https://www.rubydoc.info/gems/go-merge/7.0.0
88
+ funding_uri: https://github.com/sponsors/pboling
89
+ wiki_uri: https://github.com/structuredmerge/structuredmerge-ruby/wiki
90
+ discord_uri: https://discord.gg/3qme4XHNKN
91
+ rubygems_mfa_required: 'true'
92
+ rdoc_options: []
93
+ require_paths:
94
+ - lib
95
+ required_ruby_version: !ruby/object:Gem::Requirement
96
+ requirements:
97
+ - - ">="
98
+ - !ruby/object:Gem::Version
99
+ version: 4.0.0
100
+ required_rubygems_version: !ruby/object:Gem::Requirement
101
+ requirements:
102
+ - - ">="
103
+ - !ruby/object:Gem::Version
104
+ version: '0'
105
+ requirements: []
106
+ rubygems_version: 4.0.10
107
+ specification_version: 4
108
+ summary: Structured Merge Go module analysis and merge for Ruby
109
+ test_files: []
metadata.gz.sig ADDED
Binary file