Skip to content

Commit 252a0ef

Browse files
committed
100% documentation coverage.
1 parent 5536327 commit 252a0ef

39 files changed

Lines changed: 969 additions & 19 deletions

gems.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
gem "bake-modernize"
1717
gem "bake-releases"
1818

19+
gem "agent-context"
20+
1921
gem "utopia-project"
2022
end
2123

lib/ffi/clang.rb

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,3 @@
3232
require_relative 'clang/types/record'
3333
require_relative 'clang/types/type_def'
3434
require_relative 'clang/types/vector'
35-
36-
# @namespace
37-
module FFI
38-
# @namespace
39-
module Clang
40-
end
41-
end

lib/ffi/clang/clang_version.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,14 @@
88

99
module FFI
1010
module Clang
11+
# Get the version string of the libclang library.
12+
# @returns [String] The libclang version string.
1113
def self.clang_version_string
1214
Lib.extract_string Lib.get_clang_version
1315
end
1416

17+
# Get the libclang version as a Gem::Version object.
18+
# @returns [Gem::Version] The parsed version.
1519
def self.clang_version
1620
clang_version = self.clang_version_string.match(/\d+\.\d+\.\d+/)
1721
Gem::Version.new(clang_version)

lib/ffi/clang/code_completion.rb

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,83 +9,119 @@
99

1010
module FFI
1111
module Clang
12+
# @namespace
1213
class CodeCompletion
14+
# Get the default code completion options.
15+
# @returns [Array(Symbol)] The default options.
1316
def self.default_code_completion_options
1417
Lib.opts_from(Lib::CodeCompleteFlags, Lib.default_code_completion_options)
1518
end
1619

20+
# Represents code completion results.
1721
class Results < FFI::AutoPointer
1822
include Enumerable
1923

24+
# @attribute [Integer] The number of completion results.
2025
attr_reader :size
26+
27+
# @attribute [Array(Result)] The array of completion results.
2128
attr_reader :results
2229

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.
2333
def initialize(code_complete_results, translation_unit)
2434
super code_complete_results.pointer
2535
@translation_unit = translation_unit
2636
@code_complete_results = code_complete_results
2737
initialize_results
2838
end
2939

40+
# Release the completion results pointer.
41+
# @parameter pointer [FFI::Pointer] The pointer to release.
3042
def self.release(pointer)
3143
results = Lib::CXCodeCompleteResults.new(pointer)
3244
Lib.dispose_code_complete_results(results)
3345
end
3446

47+
# Iterate over each completion result.
48+
# @yields {|result| ...} Each completion result.
49+
# @parameter result [Result] The completion result.
3550
def each(&block)
3651
@results.each do |token|
3752
block.call(token)
3853
end
3954
end
4055

56+
# Get the number of diagnostics.
57+
# @returns [Integer] The number of diagnostics.
4158
def num_diagnostics
4259
Lib.get_code_complete_get_num_diagnostics(@code_complete_results)
4360
end
4461

62+
# Get a diagnostic by index.
63+
# @parameter i [Integer] The diagnostic index.
64+
# @returns [Diagnostic] The diagnostic.
4565
def diagnostic(i)
4666
Diagnostic.new(@translation_unit, Lib.get_code_complete_get_diagnostic(@code_complete_results, i))
4767
end
4868

69+
# Get all diagnostics.
70+
# @returns [Array(Diagnostic)] Array of diagnostics.
4971
def diagnostics
5072
num_diagnostics.times.map { |i|
5173
Diagnostic.new(@translation_unit, Lib.get_code_complete_get_diagnostic(@code_complete_results, i))
5274
}
5375
end
5476

77+
# Get the completion contexts.
78+
# @returns [Array(Symbol)] The completion contexts.
5579
def contexts
5680
Lib.opts_from Lib::CompletionContext, Lib.get_code_complete_get_contexts(@code_complete_results)
5781
end
5882

83+
# Get the USR of the container.
84+
# @returns [String] The container USR.
5985
def container_usr
6086
Lib.extract_string Lib.get_code_complete_get_container_usr(@code_complete_results)
6187
end
6288

89+
# Get the kind of the container.
90+
# @returns [Symbol] The container kind.
6391
def container_kind
6492
is_incomplete = MemoryPointer.new :uint
6593
Lib.get_code_complete_get_container_kind(@code_complete_results, is_incomplete)
6694
end
6795

96+
# Check if the results are incomplete.
97+
# @returns [Boolean] True if results are incomplete.
6898
def incomplete?
6999
is_incomplete = MemoryPointer.new :uint
70100
Lib.get_code_complete_get_container_kind(@code_complete_results, is_incomplete)
71101
is_incomplete.read_uint != 0
72102
end
73103

104+
# Get the Objective-C selector.
105+
# @returns [String] The Objective-C selector.
74106
def objc_selector
75107
Lib.extract_string Lib.get_code_complete_get_objc_selector(@code_complete_results)
76108
end
77109

110+
# Sort the completion results in place.
78111
def sort!
79112
Lib.sort_code_completion_results(@code_complete_results[:results], @code_complete_results[:num])
80113
initialize_results
81114
end
82115

116+
# Get a string representation of the results.
117+
# @returns [String] The results as a string.
83118
def inspect
84119
@results.inspect
85120
end
86121

87122
private
88123

124+
# @private
89125
def initialize_results
90126
@size = @code_complete_results[:num]
91127
cur_ptr = @code_complete_results[:results]
@@ -97,81 +133,123 @@ def initialize_results
97133
end
98134
end
99135

136+
# Represents a single code completion result.
100137
class Result
138+
# Initialize a completion result.
139+
# @parameter result [Lib::CXCompletionResult] The completion result structure.
101140
def initialize(result)
102141
@result = result
103142
end
104143

144+
# Get the kind of completion.
145+
# @returns [Symbol] The completion kind.
105146
def kind
106147
@result[:kind]
107148
end
108149

150+
# Get the completion string.
151+
# @returns [CodeCompletion::String] The completion string.
109152
def string
110153
CodeCompletion::String.new @result[:string]
111154
end
112155

156+
# Get a string representation of this result.
157+
# @returns [String] The result as a string.
113158
def inspect
114159
"<#{kind.inspect} = #{string.inspect}>"
115160
end
116161
end
117162

163+
# Represents a code completion string with chunks.
118164
class String
165+
# Initialize a completion string.
166+
# @parameter ptr [FFI::Pointer] The completion string pointer.
119167
def initialize(ptr)
120168
@pointer = ptr
121169
end
122170

171+
# Get the kind of a chunk.
172+
# @parameter i [Integer] The chunk index.
173+
# @returns [Symbol] The chunk kind.
123174
def chunk_kind(i)
124175
Lib.get_completion_chunk_kind(@pointer, i)
125176
end
126177

178+
# Get the text of a chunk.
179+
# @parameter i [Integer] The chunk index.
180+
# @returns [String] The chunk text.
127181
def chunk_text(i)
128182
Lib.extract_string Lib.get_completion_text(@pointer, i)
129183
end
130184

185+
# Get the completion string of a chunk.
186+
# @parameter i [Integer] The chunk index.
187+
# @returns [CodeCompletion::String] The chunk's completion string.
131188
def chunk_completion(i)
132189
CodeCompletion::String.new Lib.get_completion_chunk_completion_string(@pointer, i)
133190
end
134191

192+
# Get the number of chunks.
193+
# @returns [Integer] The number of chunks.
135194
def num_chunks
136195
Lib.get_num_completion_chunks(@pointer)
137196
end
138197

198+
# Get all chunks as an array of hashes.
199+
# @returns [Array(Hash)] Array of chunk hashes with `:kind`, `:text`, and `:completion` keys.
139200
def chunks
140201
num_chunks.times.map { |i|
141202
{ kind: chunk_kind(i), text: chunk_text(i), completion: chunk_completion(i) }
142203
}
143204
end
144205

206+
# Get the priority of this completion.
207+
# @returns [Integer] The completion priority.
145208
def priority
146209
Lib.get_completion_priority(@pointer)
147210
end
148211

212+
# Get the availability of this completion.
213+
# @returns [Symbol] The completion availability.
149214
def availability
150215
Lib.get_completion_availability(@pointer)
151216
end
152217

218+
# Get the number of annotations.
219+
# @returns [Integer] The number of annotations.
153220
def num_annotations
154221
Lib.get_completion_num_annotations(@pointer)
155222
end
156223

224+
# Get an annotation by index.
225+
# @parameter i [Integer] The annotation index.
226+
# @returns [String] The annotation text.
157227
def annotation(i)
158228
Lib.extract_string Lib.get_completion_annotation(@pointer, i)
159229
end
160230

231+
# Get all annotations.
232+
# @returns [Array(String)] Array of annotation strings.
161233
def annotations
162234
num_annotations.times.map { |i|
163235
Lib.extract_string Lib.get_completion_annotation(@pointer, i)
164236
}
165237
end
166238

239+
# Get the parent context.
240+
# @returns [String] The parent context.
167241
def parent
168242
Lib.extract_string Lib.get_completion_parent(@pointer, nil)
169243
end
170244

245+
# Get the brief comment.
246+
# @returns [String] The brief comment.
171247
def comment
172248
Lib.extract_string Lib.get_completion_brief_comment(@pointer)
173249
end
174250

251+
# Get a string representation of this completion string.
252+
# @returns [String] The chunks as a string.
175253
def inspect
176254
chunks.inspect
177255
end

0 commit comments

Comments
 (0)