ghazel-ffi-clang 0.2.0.2 → 0.2.1
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ffi/clang.rb +2 -0
- data/lib/ffi/clang/code_completion.rb +181 -0
- data/lib/ffi/clang/compilation_database.rb +125 -0
- data/lib/ffi/clang/cursor.rb +5 -0
- data/lib/ffi/clang/lib.rb +5 -1
- data/lib/ffi/clang/lib/code_completion.rb +130 -0
- data/lib/ffi/clang/lib/compilation_database.rb +58 -0
- data/lib/ffi/clang/lib/cursor.rb +15 -21
- data/lib/ffi/clang/lib/inclusions.rb +32 -0
- data/lib/ffi/clang/lib/type.rb +3 -12
- data/lib/ffi/clang/translation_unit.rb +24 -0
- data/lib/ffi/clang/utils.rb +38 -12
- data/lib/ffi/clang/version.rb +1 -1
- data/spec/clang/code_completion_spec.rb +179 -0
- data/spec/clang/compilation_database_spec.rb +178 -0
- data/spec/clang/diagnostic_spec.rb +2 -1
- data/spec/clang/index_spec.rb +3 -2
- data/spec/clang/token_spec.rb +1 -0
- data/spec/clang/translation_unit_spec.rb +3 -1
- data/spec/clang/utils_spec.rb +2 -3
- data/spec/fixtures/compile_commands.json +17 -0
- data/spec/fixtures/completion.cxx +8 -0
- data/spec/spec_helper.rb +9 -0
- metadata +36 -13
- checksums.yaml +0 -7
@@ -0,0 +1,58 @@
|
|
1
|
+
# Copyright, 2014, by Masahiro Sano.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
module FFI
|
22
|
+
module Clang
|
23
|
+
module Lib
|
24
|
+
typedef :pointer, :CXCompilationDatabase
|
25
|
+
typedef :pointer, :CXCompileCommands
|
26
|
+
typedef :pointer, :CXCompileCommand
|
27
|
+
|
28
|
+
CompilationDatabaseError = enum [
|
29
|
+
:no_error, 0,
|
30
|
+
:can_not_load_database, 1,
|
31
|
+
]
|
32
|
+
|
33
|
+
# CompilationDatabase
|
34
|
+
attach_function :compilation_database_from_directory, :clang_CompilationDatabase_fromDirectory, [:string, :pointer], :CXCompilationDatabase
|
35
|
+
attach_function :compilation_database_dispose, :clang_CompilationDatabase_dispose, [:CXCompilationDatabase], :uint
|
36
|
+
attach_function :compilation_database_get_compile_commands, :clang_CompilationDatabase_getCompileCommands, [:CXCompilationDatabase, :string], :CXCompileCommands
|
37
|
+
if FFI::Clang::Utils.satisfy_version?('3.3')
|
38
|
+
attach_function :compilation_database_get_all_compile_commands, :clang_CompilationDatabase_getAllCompileCommands, [:CXCompilationDatabase], :CXCompileCommands
|
39
|
+
end
|
40
|
+
|
41
|
+
# CompilationDatabase::CompileCommands
|
42
|
+
attach_function :compile_commands_dispose, :clang_CompileCommands_dispose, [:CXCompileCommands], :void
|
43
|
+
attach_function :compile_commands_get_size, :clang_CompileCommands_getSize, [:CXCompileCommands], :uint
|
44
|
+
attach_function :compile_commands_get_command, :clang_CompileCommands_getCommand, [:CXCompileCommands, :uint], :CXCompileCommand
|
45
|
+
|
46
|
+
# CompilationDatabase::CompileCommand
|
47
|
+
attach_function :compile_command_get_directory, :clang_CompileCommand_getDirectory, [:CXCompileCommand], CXString.by_value
|
48
|
+
attach_function :compile_command_get_num_args, :clang_CompileCommand_getNumArgs, [:CXCompileCommand], :uint
|
49
|
+
attach_function :compile_command_get_arg, :clang_CompileCommand_getArg, [:CXCompileCommand, :uint], CXString.by_value
|
50
|
+
if FFI::Clang::Utils.satisfy_version?('3.4')
|
51
|
+
# Thease functions are not exposed by libclang.so privided by packages.
|
52
|
+
# attach_function :compile_command_get_num_mapped_sources, :clang_CompileCommand_getNumMappedSources, [:CXCompileCommand], :uint
|
53
|
+
# attach_function :compile_command_get_mapped_source_path, :clang_CompileCommand_getMappedSourcePath, [:CXCompileCommand, :uint], CXString.by_value
|
54
|
+
# attach_function :compile_command_get_mapped_source_content, :clang_CompileCommand_getMappedSourceContent, [:CXCompileCommand, :uint], CXString.by_value
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
data/lib/ffi/clang/lib/cursor.rb
CHANGED
@@ -30,7 +30,7 @@ require 'ffi/clang/utils'
|
|
30
30
|
module FFI
|
31
31
|
module Clang
|
32
32
|
module Lib
|
33
|
-
enum :
|
33
|
+
enum :cursor_kind, [
|
34
34
|
:cursor_unexposed_decl, 1,
|
35
35
|
:cursor_struct, 2,
|
36
36
|
:cursor_union, 3,
|
@@ -206,7 +206,7 @@ module FFI
|
|
206
206
|
|
207
207
|
class CXCursor < FFI::Struct
|
208
208
|
layout(
|
209
|
-
:kind, :
|
209
|
+
:kind, :cursor_kind,
|
210
210
|
:xdata, :int,
|
211
211
|
:data, [:pointer, 3]
|
212
212
|
)
|
@@ -277,7 +277,7 @@ module FFI
|
|
277
277
|
attach_function :get_canonical_cursor, :clang_getCanonicalCursor, [CXCursor.by_value], CXCursor.by_value
|
278
278
|
attach_function :get_cursor_definition, :clang_getCursorDefinition, [CXCursor.by_value], CXCursor.by_value
|
279
279
|
attach_function :get_specialized_cursor_template, :clang_getSpecializedCursorTemplate, [CXCursor.by_value], CXCursor.by_value
|
280
|
-
attach_function :get_template_cursor_kind, :clang_getTemplateCursorKind, [CXCursor.by_value], :
|
280
|
+
attach_function :get_template_cursor_kind, :clang_getTemplateCursorKind, [CXCursor.by_value], :cursor_kind
|
281
281
|
|
282
282
|
attach_function :get_translation_unit_cursor, :clang_getTranslationUnitCursor, [:CXTranslationUnit], CXCursor.by_value
|
283
283
|
attach_function :cursor_get_translation_unit, :clang_Cursor_getTranslationUnit, [CXCursor.by_value], :CXTranslationUnit
|
@@ -296,19 +296,19 @@ module FFI
|
|
296
296
|
attach_function :get_cursor_display_name, :clang_getCursorDisplayName, [CXCursor.by_value], CXString.by_value
|
297
297
|
attach_function :get_cursor_spelling, :clang_getCursorSpelling, [CXCursor.by_value], CXString.by_value
|
298
298
|
attach_function :get_cursor_usr, :clang_getCursorUSR, [CXCursor.by_value], CXString.by_value
|
299
|
-
attach_function :get_cursor_kind_spelling, :clang_getCursorKindSpelling, [:
|
299
|
+
attach_function :get_cursor_kind_spelling, :clang_getCursorKindSpelling, [:cursor_kind], CXString.by_value
|
300
300
|
|
301
301
|
attach_function :are_equal, :clang_equalCursors, [CXCursor.by_value, CXCursor.by_value], :uint
|
302
302
|
|
303
|
-
attach_function :is_declaration, :clang_isDeclaration, [:
|
304
|
-
attach_function :is_reference, :clang_isReference, [:
|
305
|
-
attach_function :is_expression, :clang_isExpression, [:
|
306
|
-
attach_function :is_statement, :clang_isStatement, [:
|
307
|
-
attach_function :is_attribute, :clang_isAttribute, [:
|
308
|
-
attach_function :is_invalid, :clang_isInvalid, [:
|
309
|
-
attach_function :is_translation_unit, :clang_isTranslationUnit, [:
|
310
|
-
attach_function :is_preprocessing, :clang_isPreprocessing, [:
|
311
|
-
attach_function :is_unexposed, :clang_isUnexposed, [:
|
303
|
+
attach_function :is_declaration, :clang_isDeclaration, [:cursor_kind], :uint
|
304
|
+
attach_function :is_reference, :clang_isReference, [:cursor_kind], :uint
|
305
|
+
attach_function :is_expression, :clang_isExpression, [:cursor_kind], :uint
|
306
|
+
attach_function :is_statement, :clang_isStatement, [:cursor_kind], :uint
|
307
|
+
attach_function :is_attribute, :clang_isAttribute, [:cursor_kind], :uint
|
308
|
+
attach_function :is_invalid, :clang_isInvalid, [:cursor_kind], :uint
|
309
|
+
attach_function :is_translation_unit, :clang_isTranslationUnit, [:cursor_kind], :uint
|
310
|
+
attach_function :is_preprocessing, :clang_isPreprocessing, [:cursor_kind], :uint
|
311
|
+
attach_function :is_unexposed, :clang_isUnexposed, [:cursor_kind], :uint
|
312
312
|
|
313
313
|
enum :child_visit_result, [:break, :continue, :recurse]
|
314
314
|
|
@@ -331,14 +331,8 @@ module FFI
|
|
331
331
|
attach_function :get_cursor_hash, :clang_hashCursor, [CXCursor.by_value], :uint
|
332
332
|
|
333
333
|
if FFI::Clang::Utils.satisfy_version?('3.3')
|
334
|
-
|
335
|
-
|
336
|
-
rescue FFI::NotFoundError => e
|
337
|
-
end
|
338
|
-
begin
|
339
|
-
attach_function :get_field_decl_bit_width, :clang_getFieldDeclBitWidth, [CXCursor.by_value], :int
|
340
|
-
rescue FFI::NotFoundError => e
|
341
|
-
end
|
334
|
+
attach_function :is_bit_field,:clang_Cursor_isBitField, [CXCursor.by_value], :uint
|
335
|
+
attach_function :get_field_decl_bit_width, :clang_getFieldDeclBitWidth, [CXCursor.by_value], :int
|
342
336
|
end
|
343
337
|
|
344
338
|
attach_function :get_overloaded_decl, :clang_getOverloadedDecl, [CXCursor.by_value, :uint], CXCursor.by_value
|
@@ -0,0 +1,32 @@
|
|
1
|
+
# Copyright, 2014, by Greg Hazel
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'ffi/clang/lib/file'
|
22
|
+
require 'ffi/clang/lib/source_location'
|
23
|
+
|
24
|
+
module FFI
|
25
|
+
module Clang
|
26
|
+
module Lib
|
27
|
+
# Source code inclusions:
|
28
|
+
callback :visit_inclusion_function, [:CXFile, :pointer, :uint, :pointer], :void
|
29
|
+
attach_function :get_inclusions, :clang_getInclusions, [:CXTranslationUnit, :visit_inclusion_function, :pointer], :void
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/lib/ffi/clang/lib/type.rb
CHANGED
@@ -138,18 +138,9 @@ module FFI
|
|
138
138
|
attach_function :get_array_element_type ,:clang_getArrayElementType, [CXType.by_value], CXType.by_value
|
139
139
|
|
140
140
|
if FFI::Clang::Utils.satisfy_version?('3.3')
|
141
|
-
|
142
|
-
|
143
|
-
|
144
|
-
end
|
145
|
-
begin
|
146
|
-
attach_function :type_get_size_of, :clang_Type_getSizeOf, [CXType.by_value], :long_long
|
147
|
-
rescue FFI::NotFoundError => e
|
148
|
-
end
|
149
|
-
begin
|
150
|
-
attach_function :type_get_offset_of, :clang_Type_getOffsetOf, [CXType.by_value, :string], :long_long
|
151
|
-
rescue FFI::NotFoundError => e
|
152
|
-
end
|
141
|
+
attach_function :type_get_align_of, :clang_Type_getAlignOf, [CXType.by_value], :long_long
|
142
|
+
attach_function :type_get_size_of, :clang_Type_getSizeOf, [CXType.by_value], :long_long
|
143
|
+
attach_function :type_get_offset_of, :clang_Type_getOffsetOf, [CXType.by_value, :string], :long_long
|
153
144
|
end
|
154
145
|
|
155
146
|
if FFI::Clang::Utils.satisfy_version?('3.4')
|
@@ -21,6 +21,7 @@
|
|
21
21
|
# THE SOFTWARE.
|
22
22
|
|
23
23
|
require 'ffi/clang/lib/translation_unit'
|
24
|
+
require 'ffi/clang/lib/inclusions'
|
24
25
|
require 'ffi/clang/cursor'
|
25
26
|
require 'ffi/clang/file'
|
26
27
|
require 'ffi/clang/token'
|
@@ -109,6 +110,29 @@ module FFI
|
|
109
110
|
Tokens.new(token_ptr.get_pointer(0), uint_ptr.get_uint(0), self)
|
110
111
|
end
|
111
112
|
|
113
|
+
def code_complete(source_file, line, column, unsaved = [], opts = nil)
|
114
|
+
opts = CodeCompletion.default_code_completion_options if opts.nil?
|
115
|
+
unsaved_files = UnsavedFile.unsaved_pointer_from(unsaved)
|
116
|
+
option_bitmask = Lib.bitmask_from(Lib::CodeCompleteFlags, opts)
|
117
|
+
ptr = Lib.code_complete_at(self, source_file, line, column, unsaved_files, unsaved.length, option_bitmask)
|
118
|
+
CodeCompletion::Results.new ptr, self
|
119
|
+
end
|
120
|
+
|
121
|
+
def inclusions(&block)
|
122
|
+
adapter = Proc.new do |included_file, inclusion_stack, include_len, unused|
|
123
|
+
file = Lib.extract_string Lib.get_file_name(included_file)
|
124
|
+
cur_ptr = inclusion_stack
|
125
|
+
inclusions = []
|
126
|
+
include_len.times {
|
127
|
+
inclusions << SourceLocation.new(Lib::CXSourceLocation.new(cur_ptr))
|
128
|
+
cur_ptr += Lib::CXSourceLocation.size
|
129
|
+
}
|
130
|
+
block.call file, inclusions
|
131
|
+
end
|
132
|
+
|
133
|
+
Lib.get_inclusions(self, adapter, nil)
|
134
|
+
end
|
135
|
+
|
112
136
|
class ResourceUsage < AutoPointer
|
113
137
|
def initialize(resource_usage)
|
114
138
|
# CXResourceUsage is returned by value and should be freed explicitly.
|
data/lib/ffi/clang/utils.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
# Copyright, 2014 by Masahiro Sano.
|
2
|
+
# Copyright, 2014 by Samuel Williams.
|
2
3
|
#
|
3
4
|
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
5
|
# of this software and associated documentation files (the "Software"), to deal
|
@@ -23,35 +24,60 @@ require 'ffi/clang/lib/string'
|
|
23
24
|
|
24
25
|
module FFI
|
25
26
|
module Clang
|
26
|
-
|
27
|
+
module Utils
|
28
|
+
@@clang_version = nil
|
29
|
+
|
27
30
|
def self.clang_version_string
|
28
31
|
Lib.extract_string Lib.get_clang_version
|
29
32
|
end
|
30
33
|
|
31
34
|
def self.clang_version
|
32
|
-
|
33
|
-
|
35
|
+
unless @@clang_version
|
36
|
+
# Version string vary wildy:
|
37
|
+
# Ubuntu: "Ubuntu clang version 3.0-6ubuntu3 (tags/RELEASE_30/final) (based on LLVM 3.0)"
|
38
|
+
# Mac OS X: "Apple LLVM version 5.0 (clang-500.2.79) (based on LLVM 3.3svn)"
|
39
|
+
# Linux: "clang version 3.3"
|
40
|
+
|
41
|
+
if parts = clang_version_string.match(/(?:clang version|based on LLVM) (\d+)\.(\d+)(svn)?/)
|
42
|
+
major = parts[1].to_i
|
43
|
+
minor = parts[2].to_i
|
44
|
+
rc = parts[3]
|
45
|
+
|
46
|
+
# Mac OS X currently reports support for 3.3svn, but this support is broken in some ways, so we revert it back to 3.2 which it supports completely.
|
47
|
+
if rc == 'svn'
|
48
|
+
minor -= 1
|
49
|
+
end
|
50
|
+
|
51
|
+
@@clang_version = [major, minor]
|
52
|
+
|
53
|
+
puts "Clang version detected: #{@@clang_version.inspect}"
|
54
|
+
else
|
55
|
+
abort "Invalid/unsupported clang version string."
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
return @@clang_version
|
34
60
|
end
|
35
61
|
|
36
62
|
def self.clang_version_symbol
|
37
|
-
|
38
|
-
version.intern
|
63
|
+
"clang_#{clang_version.join('_')}".to_sym
|
39
64
|
end
|
40
65
|
|
41
66
|
def self.clang_major_version
|
42
|
-
|
43
|
-
version.match(/based on LLVM (\d+)\./).values_at(1).first.to_i
|
67
|
+
clang_version[0]
|
44
68
|
end
|
45
69
|
|
46
70
|
def self.clang_minor_version
|
47
|
-
|
48
|
-
version.match(/based on LLVM \d+\.(\d+)/).values_at(1).first.to_i
|
71
|
+
clang_version[1]
|
49
72
|
end
|
50
73
|
|
74
|
+
# Returns true if the current clang version is >= min version and optionally <= max_version
|
51
75
|
def self.satisfy_version?(min_version, max_version = nil)
|
52
|
-
|
53
|
-
|
54
|
-
|
76
|
+
min_version = Gem::Version.create(min_version)
|
77
|
+
max_version = Gem::Version.create(max_version) if max_version
|
78
|
+
current_version = Gem::Version.create(self.clang_version.join('.'))
|
79
|
+
|
80
|
+
return (current_version >= min_version) && (!max_version || current_version <= max_version)
|
55
81
|
end
|
56
82
|
end
|
57
83
|
end
|
data/lib/ffi/clang/version.rb
CHANGED
@@ -0,0 +1,179 @@
|
|
1
|
+
# Copyright, 2014, by Masahiro Sano.
|
2
|
+
#
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
8
|
+
# furnished to do so, subject to the following conditions:
|
9
|
+
#
|
10
|
+
# The above copyright notice and this permission notice shall be included in
|
11
|
+
# all copies or substantial portions of the Software.
|
12
|
+
#
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
# THE SOFTWARE.
|
20
|
+
|
21
|
+
require 'spec_helper'
|
22
|
+
|
23
|
+
describe CodeCompletion do
|
24
|
+
let(:filename) { fixture_path("completion.cxx") }
|
25
|
+
let(:tu) { Index.new.parse_translation_unit(filename) }
|
26
|
+
let(:line) { 7 }
|
27
|
+
let(:column) { 6 }
|
28
|
+
let(:results) { tu.code_complete(filename, line, column) }
|
29
|
+
|
30
|
+
describe "self.default_code_completion_options" do
|
31
|
+
let(:options) { FFI::Clang::CodeCompletion.default_code_completion_options }
|
32
|
+
it "returns a default set of code-completion options" do
|
33
|
+
expect(options).to be_kind_of(Hash)
|
34
|
+
options.keys.each { |key|
|
35
|
+
expect(FFI::Clang::Lib::CodeCompleteFlags.symbols).to include(key)
|
36
|
+
}
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
describe CodeCompletion::Results do
|
41
|
+
it "can be obtained from a translation unit" do
|
42
|
+
expect(results).to be_kind_of(CodeCompletion::Results)
|
43
|
+
expect(results.size).to eq(42)
|
44
|
+
expect(results.results).to be_kind_of(Array)
|
45
|
+
expect(results.results.first).to be_kind_of(CodeCompletion::Result)
|
46
|
+
end
|
47
|
+
|
48
|
+
it "calls dispose_code_complete_results on GC" do
|
49
|
+
expect(Lib).to receive(:dispose_code_complete_results).at_least(:once)
|
50
|
+
expect{results.free}.not_to raise_error
|
51
|
+
end
|
52
|
+
|
53
|
+
it "#each" do
|
54
|
+
spy = double(stub: nil)
|
55
|
+
expect(spy).to receive(:stub).exactly(results.size).times
|
56
|
+
results.each { spy.stub }
|
57
|
+
end
|
58
|
+
|
59
|
+
it "#num_diagnostics" do
|
60
|
+
expect(results.num_diagnostics).to eq(2)
|
61
|
+
end
|
62
|
+
|
63
|
+
it "#diagnostic" do
|
64
|
+
expect(results.diagnostic(0)).to be_kind_of(Diagnostic)
|
65
|
+
end
|
66
|
+
|
67
|
+
it "#diagnostics" do
|
68
|
+
expect(results.diagnostics).to be_kind_of(Array)
|
69
|
+
expect(results.diagnostics.first).to be_kind_of(Diagnostic)
|
70
|
+
expect(results.diagnostics.size).to eq(results.num_diagnostics)
|
71
|
+
end
|
72
|
+
|
73
|
+
it "#contexts" do
|
74
|
+
expect(results.contexts).to be_kind_of(Hash)
|
75
|
+
results.contexts.keys.each { |key|
|
76
|
+
expect(FFI::Clang::Lib::CompletionContext.symbols).to include(key)
|
77
|
+
}
|
78
|
+
end
|
79
|
+
|
80
|
+
it "#container_usr" do
|
81
|
+
expect(results.container_usr).to be_kind_of(String)
|
82
|
+
expect(results.container_usr).to match(/std.+vector/)
|
83
|
+
end
|
84
|
+
|
85
|
+
it "#container_kind" do
|
86
|
+
expect(results.container_kind).to be_kind_of(Symbol)
|
87
|
+
expect(results.container_kind).to eq(:cursor_class_decl)
|
88
|
+
end
|
89
|
+
|
90
|
+
it "#incomplete?" do
|
91
|
+
expect(results.incomplete?).to be_false
|
92
|
+
end
|
93
|
+
|
94
|
+
it "#objc_selector" do
|
95
|
+
#TODO
|
96
|
+
end
|
97
|
+
|
98
|
+
it "#sort!" do
|
99
|
+
results.sort!
|
100
|
+
# may be sorted with typed_text kind, first result will start with 'a'
|
101
|
+
expect(results.results.first.string.chunks.select{|x| x[:kind] == :typed_text}.first[:text]).to eq('assign')
|
102
|
+
end
|
103
|
+
end
|
104
|
+
|
105
|
+
describe CodeCompletion::Result do
|
106
|
+
let(:result) { results.results.first }
|
107
|
+
it "#string" do
|
108
|
+
expect(result.string).to be_kind_of(CodeCompletion::String)
|
109
|
+
end
|
110
|
+
|
111
|
+
it "#kind" do
|
112
|
+
expect(result.kind).to be_kind_of(Symbol)
|
113
|
+
end
|
114
|
+
end
|
115
|
+
|
116
|
+
describe CodeCompletion::String do
|
117
|
+
let(:str) { results.sort!; results.results.first.string }
|
118
|
+
|
119
|
+
|
120
|
+
it "#num_chunks" do
|
121
|
+
expect(str.num_chunks).to eq(7)
|
122
|
+
end
|
123
|
+
|
124
|
+
it "#chunk_kind" do
|
125
|
+
expect(str.chunk_kind(0)).to eq(:result_type)
|
126
|
+
expect(str.chunk_kind(1)).to eq(:typed_text)
|
127
|
+
end
|
128
|
+
|
129
|
+
|
130
|
+
it "#chunk_text" do
|
131
|
+
expect(str.chunk_text(0)).to eq('void')
|
132
|
+
expect(str.chunk_text(1)).to eq('assign')
|
133
|
+
end
|
134
|
+
|
135
|
+
it "#chunk_completion" do
|
136
|
+
expect(str.chunk_completion(0)).to be_kind_of(CodeCompletion::String)
|
137
|
+
end
|
138
|
+
|
139
|
+
it "#chunks" do
|
140
|
+
expect(str.chunks).to be_kind_of(Array)
|
141
|
+
expect(str.chunks.first).to be_kind_of(Hash)
|
142
|
+
expect(str.chunks.size).to eq(str.num_chunks)
|
143
|
+
end
|
144
|
+
|
145
|
+
it "#priority" do
|
146
|
+
expect(str.priority).to be_kind_of(Integer)
|
147
|
+
end
|
148
|
+
|
149
|
+
it "#availability" do
|
150
|
+
expect(str.availability).to be_kind_of(Symbol)
|
151
|
+
expect(str.availability).to eq(:available)
|
152
|
+
end
|
153
|
+
|
154
|
+
it "#num_annotations" do
|
155
|
+
expect(str.num_annotations).to be_kind_of(Integer)
|
156
|
+
expect(str.num_annotations).to eq(0)
|
157
|
+
end
|
158
|
+
|
159
|
+
it "#annotation" do
|
160
|
+
expect(str.annotation(100)).to be_nil
|
161
|
+
# TODO: need tests for String which has annotation
|
162
|
+
end
|
163
|
+
|
164
|
+
it "#annotations" do
|
165
|
+
expect(str.annotations).to be_kind_of(Array)
|
166
|
+
# TODO: need tests for String which has annotation
|
167
|
+
end
|
168
|
+
|
169
|
+
it "#parent" do
|
170
|
+
expect(str.parent).to be_kind_of(String)
|
171
|
+
expect(str.parent).to eq('std::vector')
|
172
|
+
end
|
173
|
+
|
174
|
+
it "#comment" do
|
175
|
+
expect(str.comment).to be_nil
|
176
|
+
# TODO: need tests for String which has real comment
|
177
|
+
end
|
178
|
+
end
|
179
|
+
end
|