ffi-clang 0.13.0 → 0.14.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 +4 -4
- checksums.yaml.gz.sig +0 -0
- data/ext/rakefile.rb +2 -2
- data/lib/ffi/clang/clang_version.rb +7 -3
- data/lib/ffi/clang/code_completion.rb +121 -44
- data/lib/ffi/clang/comment.rb +164 -57
- data/lib/ffi/clang/compilation_database.rb +79 -25
- data/lib/ffi/clang/cursor.rb +395 -149
- data/lib/ffi/clang/diagnostic.rb +57 -23
- data/lib/ffi/clang/error.rb +12 -0
- data/lib/ffi/clang/file.rb +30 -11
- data/lib/ffi/clang/index.rb +37 -13
- data/lib/ffi/clang/lib/clang_version.rb +2 -2
- data/lib/ffi/clang/lib/code_completion.rb +15 -11
- data/lib/ffi/clang/lib/comment.rb +16 -14
- data/lib/ffi/clang/lib/compilation_database.rb +5 -5
- data/lib/ffi/clang/lib/cursor.rb +74 -56
- data/lib/ffi/clang/lib/diagnostic.rb +14 -14
- data/lib/ffi/clang/lib/file.rb +10 -6
- data/lib/ffi/clang/lib/inclusions.rb +3 -3
- data/lib/ffi/clang/lib/index.rb +7 -5
- data/lib/ffi/clang/lib/printing_policy.rb +36 -36
- data/lib/ffi/clang/lib/source_location.rb +9 -7
- data/lib/ffi/clang/lib/source_range.rb +5 -3
- data/lib/ffi/clang/lib/string.rb +9 -4
- data/lib/ffi/clang/lib/token.rb +17 -4
- data/lib/ffi/clang/lib/translation_unit.rb +17 -13
- data/lib/ffi/clang/lib/type.rb +19 -17
- data/lib/ffi/clang/lib.rb +35 -19
- data/lib/ffi/clang/platform.rb +25 -0
- data/lib/ffi/clang/printing_policy.rb +31 -18
- data/lib/ffi/clang/source_location.rb +119 -36
- data/lib/ffi/clang/source_range.rb +30 -12
- data/lib/ffi/clang/token.rb +48 -23
- data/lib/ffi/clang/translation_unit.rb +97 -33
- data/lib/ffi/clang/types/array.rb +15 -1
- data/lib/ffi/clang/types/elaborated.rb +19 -4
- data/lib/ffi/clang/types/function.rb +35 -10
- data/lib/ffi/clang/types/pointer.rb +23 -7
- data/lib/ffi/clang/types/record.rb +23 -8
- data/lib/ffi/clang/types/type.rb +80 -36
- data/lib/ffi/clang/types/type_def.rb +14 -2
- data/lib/ffi/clang/types/vector.rb +13 -1
- data/lib/ffi/clang/unsaved_file.rb +18 -8
- data/lib/ffi/clang/version.rb +4 -2
- data/lib/ffi/clang.rb +23 -45
- data/license.md +3 -2
- data/readme.md +12 -13
- data/releases.md +5 -0
- data.tar.gz.sig +0 -0
- metadata +10 -5
- metadata.gz.sig +0 -0
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e7e863a657523fadf6b3bbe7bf5e53fc047fb028418464d9969011041ced1f7
|
|
4
|
+
data.tar.gz: 9fa425cacdfeda2905d5450081d308e7b37979f96beb181c5dcc64e51976c33e
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 7200e81a683eed2b5415d544025af4c800767b96ac145f28b602c2d84c933650ddde92a8310b897592a7b434f08ccaf647a62965ce933493af7b5332fe6aac95
|
|
7
|
+
data.tar.gz: 494b4856f2dd7fbbabe4638bd3efda40910163d59cc78203f68553994791356f920ebf72962e8b1ce3270c6df3ed46c5e90cfaec13dbdbac87bc1e2d4b3f0323
|
checksums.yaml.gz.sig
CHANGED
|
Binary file
|
data/ext/rakefile.rb
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2013-
|
|
4
|
+
# Copyright, 2013-2025, by Samuel Williams.
|
|
5
5
|
|
|
6
|
-
require
|
|
6
|
+
require "teapot"
|
|
7
7
|
|
|
8
8
|
task :default do
|
|
9
9
|
controller = Teapot::Controller.new(__dir__)
|
|
@@ -1,17 +1,21 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
|
-
# Copyright, 2016-
|
|
4
|
+
# Copyright, 2016-2025, by Samuel Williams.
|
|
5
5
|
# Copyright, 2023, by Charlie Savage.
|
|
6
6
|
|
|
7
|
-
require_relative
|
|
7
|
+
require_relative "lib/clang_version"
|
|
8
8
|
|
|
9
9
|
module FFI
|
|
10
10
|
module Clang
|
|
11
|
+
# Get the version string of the libclang library.
|
|
12
|
+
# @returns [String] The libclang version string.
|
|
11
13
|
def self.clang_version_string
|
|
12
14
|
Lib.extract_string Lib.get_clang_version
|
|
13
15
|
end
|
|
14
|
-
|
|
16
|
+
|
|
17
|
+
# Get the libclang version as a Gem::Version object.
|
|
18
|
+
# @returns [Gem::Version] The parsed version.
|
|
15
19
|
def self.clang_version
|
|
16
20
|
clang_version = self.clang_version_string.match(/\d+\.\d+\.\d+/)
|
|
17
21
|
Gem::Version.new(clang_version)
|
|
@@ -2,176 +2,253 @@
|
|
|
2
2
|
|
|
3
3
|
# Released under the MIT License.
|
|
4
4
|
# Copyright, 2014, by Masahiro Sano.
|
|
5
|
-
# Copyright, 2014-
|
|
5
|
+
# Copyright, 2014-2025, by Samuel Williams.
|
|
6
6
|
# Copyright, 2023-2024, by Charlie Savage.
|
|
7
7
|
|
|
8
|
-
require_relative
|
|
8
|
+
require_relative "lib/code_completion"
|
|
9
9
|
|
|
10
10
|
module FFI
|
|
11
11
|
module Clang
|
|
12
|
+
# @namespace
|
|
12
13
|
class CodeCompletion
|
|
14
|
+
# Get the default code completion options.
|
|
15
|
+
# @returns [Array(Symbol)] The default options.
|
|
13
16
|
def self.default_code_completion_options
|
|
14
17
|
Lib.opts_from(Lib::CodeCompleteFlags, Lib.default_code_completion_options)
|
|
15
18
|
end
|
|
16
|
-
|
|
19
|
+
|
|
20
|
+
# Represents code completion results.
|
|
17
21
|
class Results < FFI::AutoPointer
|
|
18
22
|
include Enumerable
|
|
19
|
-
|
|
23
|
+
|
|
24
|
+
# @attribute [Integer] The number of completion results.
|
|
20
25
|
attr_reader :size
|
|
26
|
+
|
|
27
|
+
# @attribute [Array(Result)] The array of completion results.
|
|
21
28
|
attr_reader :results
|
|
22
|
-
|
|
29
|
+
|
|
30
|
+
# Initialize code completion results.
|
|
31
|
+
# @parameter code_complete_results [Lib::CXCodeCompleteResults] The completion results structure.
|
|
32
|
+
# @parameter translation_unit [TranslationUnit] The parent translation unit.
|
|
23
33
|
def initialize(code_complete_results, translation_unit)
|
|
24
34
|
super code_complete_results.pointer
|
|
25
35
|
@translation_unit = translation_unit
|
|
26
36
|
@code_complete_results = code_complete_results
|
|
27
37
|
initialize_results
|
|
28
38
|
end
|
|
29
|
-
|
|
39
|
+
|
|
40
|
+
# Release the completion results pointer.
|
|
41
|
+
# @parameter pointer [FFI::Pointer] The pointer to release.
|
|
30
42
|
def self.release(pointer)
|
|
31
|
-
|
|
43
|
+
results = Lib::CXCodeCompleteResults.new(pointer)
|
|
32
44
|
Lib.dispose_code_complete_results(results)
|
|
33
45
|
end
|
|
34
|
-
|
|
46
|
+
|
|
47
|
+
# Iterate over each completion result.
|
|
48
|
+
# @yields {|result| ...} Each completion result.
|
|
49
|
+
# @parameter result [Result] The completion result.
|
|
35
50
|
def each(&block)
|
|
36
51
|
@results.each do |token|
|
|
37
52
|
block.call(token)
|
|
38
53
|
end
|
|
39
54
|
end
|
|
40
|
-
|
|
55
|
+
|
|
56
|
+
# Get the number of diagnostics.
|
|
57
|
+
# @returns [Integer] The number of diagnostics.
|
|
41
58
|
def num_diagnostics
|
|
42
59
|
Lib.get_code_complete_get_num_diagnostics(@code_complete_results)
|
|
43
60
|
end
|
|
44
|
-
|
|
61
|
+
|
|
62
|
+
# Get a diagnostic by index.
|
|
63
|
+
# @parameter i [Integer] The diagnostic index.
|
|
64
|
+
# @returns [Diagnostic] The diagnostic.
|
|
45
65
|
def diagnostic(i)
|
|
46
66
|
Diagnostic.new(@translation_unit, Lib.get_code_complete_get_diagnostic(@code_complete_results, i))
|
|
47
67
|
end
|
|
48
|
-
|
|
68
|
+
|
|
69
|
+
# Get all diagnostics.
|
|
70
|
+
# @returns [Array(Diagnostic)] Array of diagnostics.
|
|
49
71
|
def diagnostics
|
|
50
|
-
num_diagnostics.times.map {
|
|
72
|
+
num_diagnostics.times.map {|i|
|
|
51
73
|
Diagnostic.new(@translation_unit, Lib.get_code_complete_get_diagnostic(@code_complete_results, i))
|
|
52
74
|
}
|
|
53
75
|
end
|
|
54
|
-
|
|
76
|
+
|
|
77
|
+
# Get the completion contexts.
|
|
78
|
+
# @returns [Array(Symbol)] The completion contexts.
|
|
55
79
|
def contexts
|
|
56
80
|
Lib.opts_from Lib::CompletionContext, Lib.get_code_complete_get_contexts(@code_complete_results)
|
|
57
81
|
end
|
|
58
|
-
|
|
82
|
+
|
|
83
|
+
# Get the USR of the container.
|
|
84
|
+
# @returns [String] The container USR.
|
|
59
85
|
def container_usr
|
|
60
86
|
Lib.extract_string Lib.get_code_complete_get_container_usr(@code_complete_results)
|
|
61
87
|
end
|
|
62
|
-
|
|
88
|
+
|
|
89
|
+
# Get the kind of the container.
|
|
90
|
+
# @returns [Symbol] The container kind.
|
|
63
91
|
def container_kind
|
|
64
92
|
is_incomplete = MemoryPointer.new :uint
|
|
65
93
|
Lib.get_code_complete_get_container_kind(@code_complete_results, is_incomplete)
|
|
66
94
|
end
|
|
67
|
-
|
|
95
|
+
|
|
96
|
+
# Check if the results are incomplete.
|
|
97
|
+
# @returns [Boolean] True if results are incomplete.
|
|
68
98
|
def incomplete?
|
|
69
99
|
is_incomplete = MemoryPointer.new :uint
|
|
70
100
|
Lib.get_code_complete_get_container_kind(@code_complete_results, is_incomplete)
|
|
71
101
|
is_incomplete.read_uint != 0
|
|
72
102
|
end
|
|
73
|
-
|
|
103
|
+
|
|
104
|
+
# Get the Objective-C selector.
|
|
105
|
+
# @returns [String] The Objective-C selector.
|
|
74
106
|
def objc_selector
|
|
75
107
|
Lib.extract_string Lib.get_code_complete_get_objc_selector(@code_complete_results)
|
|
76
108
|
end
|
|
77
|
-
|
|
109
|
+
|
|
110
|
+
# Sort the completion results in place.
|
|
78
111
|
def sort!
|
|
79
112
|
Lib.sort_code_completion_results(@code_complete_results[:results], @code_complete_results[:num])
|
|
80
113
|
initialize_results
|
|
81
114
|
end
|
|
82
|
-
|
|
115
|
+
|
|
116
|
+
# Get a string representation of the results.
|
|
117
|
+
# @returns [String] The results as a string.
|
|
83
118
|
def inspect
|
|
84
119
|
@results.inspect
|
|
85
120
|
end
|
|
86
|
-
|
|
121
|
+
|
|
87
122
|
private
|
|
88
|
-
|
|
123
|
+
|
|
124
|
+
# @private
|
|
89
125
|
def initialize_results
|
|
90
126
|
@size = @code_complete_results[:num]
|
|
91
127
|
cur_ptr = @code_complete_results[:results]
|
|
92
128
|
@results = []
|
|
93
|
-
@size.times {
|
|
94
|
-
|
|
95
|
-
cur_ptr += Lib::CXCompletionResult.size
|
|
129
|
+
@size.times {@results << Result.new(Lib::CXCompletionResult.new(cur_ptr))
|
|
130
|
+
cur_ptr += Lib::CXCompletionResult.size
|
|
96
131
|
}
|
|
97
132
|
end
|
|
98
133
|
end
|
|
99
|
-
|
|
134
|
+
|
|
135
|
+
# Represents a single code completion result.
|
|
100
136
|
class Result
|
|
137
|
+
# Initialize a completion result.
|
|
138
|
+
# @parameter result [Lib::CXCompletionResult] The completion result structure.
|
|
101
139
|
def initialize(result)
|
|
102
140
|
@result = result
|
|
103
141
|
end
|
|
104
|
-
|
|
142
|
+
|
|
143
|
+
# Get the kind of completion.
|
|
144
|
+
# @returns [Symbol] The completion kind.
|
|
105
145
|
def kind
|
|
106
146
|
@result[:kind]
|
|
107
147
|
end
|
|
108
|
-
|
|
148
|
+
|
|
149
|
+
# Get the completion string.
|
|
150
|
+
# @returns [CodeCompletion::String] The completion string.
|
|
109
151
|
def string
|
|
110
152
|
CodeCompletion::String.new @result[:string]
|
|
111
153
|
end
|
|
112
|
-
|
|
154
|
+
|
|
155
|
+
# Get a string representation of this result.
|
|
156
|
+
# @returns [String] The result as a string.
|
|
113
157
|
def inspect
|
|
114
158
|
"<#{kind.inspect} = #{string.inspect}>"
|
|
115
159
|
end
|
|
116
160
|
end
|
|
117
|
-
|
|
161
|
+
|
|
162
|
+
# Represents a code completion string with chunks.
|
|
118
163
|
class String
|
|
164
|
+
# Initialize a completion string.
|
|
165
|
+
# @parameter ptr [FFI::Pointer] The completion string pointer.
|
|
119
166
|
def initialize(ptr)
|
|
120
167
|
@pointer = ptr
|
|
121
168
|
end
|
|
122
|
-
|
|
169
|
+
|
|
170
|
+
# Get the kind of a chunk.
|
|
171
|
+
# @parameter i [Integer] The chunk index.
|
|
172
|
+
# @returns [Symbol] The chunk kind.
|
|
123
173
|
def chunk_kind(i)
|
|
124
174
|
Lib.get_completion_chunk_kind(@pointer, i)
|
|
125
175
|
end
|
|
126
|
-
|
|
176
|
+
|
|
177
|
+
# Get the text of a chunk.
|
|
178
|
+
# @parameter i [Integer] The chunk index.
|
|
179
|
+
# @returns [String] The chunk text.
|
|
127
180
|
def chunk_text(i)
|
|
128
181
|
Lib.extract_string Lib.get_completion_text(@pointer, i)
|
|
129
182
|
end
|
|
130
|
-
|
|
183
|
+
|
|
184
|
+
# Get the completion string of a chunk.
|
|
185
|
+
# @parameter i [Integer] The chunk index.
|
|
186
|
+
# @returns [CodeCompletion::String] The chunk's completion string.
|
|
131
187
|
def chunk_completion(i)
|
|
132
188
|
CodeCompletion::String.new Lib.get_completion_chunk_completion_string(@pointer, i)
|
|
133
189
|
end
|
|
134
|
-
|
|
190
|
+
|
|
191
|
+
# Get the number of chunks.
|
|
192
|
+
# @returns [Integer] The number of chunks.
|
|
135
193
|
def num_chunks
|
|
136
194
|
Lib.get_num_completion_chunks(@pointer)
|
|
137
195
|
end
|
|
138
|
-
|
|
196
|
+
|
|
197
|
+
# Get all chunks as an array of hashes.
|
|
198
|
+
# @returns [Array(Hash)] Array of chunk hashes with `:kind`, `:text`, and `:completion` keys.
|
|
139
199
|
def chunks
|
|
140
|
-
num_chunks.times.map {
|
|
200
|
+
num_chunks.times.map {|i|
|
|
141
201
|
{ kind: chunk_kind(i), text: chunk_text(i), completion: chunk_completion(i) }
|
|
142
202
|
}
|
|
143
203
|
end
|
|
144
|
-
|
|
204
|
+
|
|
205
|
+
# Get the priority of this completion.
|
|
206
|
+
# @returns [Integer] The completion priority.
|
|
145
207
|
def priority
|
|
146
208
|
Lib.get_completion_priority(@pointer)
|
|
147
209
|
end
|
|
148
|
-
|
|
210
|
+
|
|
211
|
+
# Get the availability of this completion.
|
|
212
|
+
# @returns [Symbol] The completion availability.
|
|
149
213
|
def availability
|
|
150
214
|
Lib.get_completion_availability(@pointer)
|
|
151
215
|
end
|
|
152
|
-
|
|
216
|
+
|
|
217
|
+
# Get the number of annotations.
|
|
218
|
+
# @returns [Integer] The number of annotations.
|
|
153
219
|
def num_annotations
|
|
154
220
|
Lib.get_completion_num_annotations(@pointer)
|
|
155
221
|
end
|
|
156
|
-
|
|
222
|
+
|
|
223
|
+
# Get an annotation by index.
|
|
224
|
+
# @parameter i [Integer] The annotation index.
|
|
225
|
+
# @returns [String] The annotation text.
|
|
157
226
|
def annotation(i)
|
|
158
227
|
Lib.extract_string Lib.get_completion_annotation(@pointer, i)
|
|
159
228
|
end
|
|
160
|
-
|
|
229
|
+
|
|
230
|
+
# Get all annotations.
|
|
231
|
+
# @returns [Array(String)] Array of annotation strings.
|
|
161
232
|
def annotations
|
|
162
|
-
num_annotations.times.map {
|
|
233
|
+
num_annotations.times.map {|i|
|
|
163
234
|
Lib.extract_string Lib.get_completion_annotation(@pointer, i)
|
|
164
235
|
}
|
|
165
236
|
end
|
|
166
|
-
|
|
237
|
+
|
|
238
|
+
# Get the parent context.
|
|
239
|
+
# @returns [String] The parent context.
|
|
167
240
|
def parent
|
|
168
241
|
Lib.extract_string Lib.get_completion_parent(@pointer, nil)
|
|
169
242
|
end
|
|
170
|
-
|
|
243
|
+
|
|
244
|
+
# Get the brief comment.
|
|
245
|
+
# @returns [String] The brief comment.
|
|
171
246
|
def comment
|
|
172
247
|
Lib.extract_string Lib.get_completion_brief_comment(@pointer)
|
|
173
248
|
end
|
|
174
|
-
|
|
249
|
+
|
|
250
|
+
# Get a string representation of this completion string.
|
|
251
|
+
# @returns [String] The chunks as a string.
|
|
175
252
|
def inspect
|
|
176
253
|
chunks.inspect
|
|
177
254
|
end
|