@@ -13,20 +13,21 @@ define(function(require, exports, module) {
1313
1414 // different completion types
1515 var completion_type = {
16- namespace_t : 0 ,
17- class_t : 1 ,
18- attribute_t : 2 ,
19- method_t : 3 ,
20- parameter_t : 4 ,
21- struct_t : 5 ,
22- function_t : 6 ,
23- enum_t : 7 ,
24- enum_static_t : 8 ,
25- union_t : 9 ,
26- typedef_t : 10 ,
27- variable_t : 11 ,
28- macro_t : 12 ,
29- unkown_t : 13 ,
16+ namespace_t : 0 ,
17+ class_t : 1 ,
18+ attribute_t : 2 ,
19+ method_t : 3 ,
20+ parameter_t : 4 ,
21+ struct_t : 5 ,
22+ function_t : 6 ,
23+ enum_t : 7 ,
24+ enum_static_t : 8 ,
25+ union_t : 9 ,
26+ typedef_t : 10 ,
27+ variable_t : 11 ,
28+ macro_t : 12 ,
29+ include_t : 13 ,
30+ unkown_t : 14
3031 } ;
3132
3233 // caches last results
@@ -51,7 +52,7 @@ define(function(require, exports, module) {
5152
5253 // check if we handle the language
5354 completer . handlesLanguage = function ( language ) {
54- return language === "c_cpp" ;
55+ return ( language === "c_cpp" ) ;
5556 } ;
5657
5758 // do an initial parse to speed things up in the future
@@ -226,64 +227,91 @@ define(function(require, exports, module) {
226227 // create a unique numeric id to identify correct callback relationships
227228 var cId = ++ uId ;
228229
229- completer . sender . on ( "_outlineResult" , function invoTmp ( ev ) {
230- if ( ev . data . id != cId )
231- return ;
232-
233- // unregister this cb
234- completer . sender . off ( "_outlineResult" , invoTmp ) ;
235- var items = [ ] ;
236-
237- // @todo : Add location once available in clang_tool
238- _ . forEach ( ev . data . results . includes , function ( include ) {
239- items . push ( {
240- icon : "c_cpp_include" ,
241- name : "<" + include + ">" ,
242- pos : { sl : 1 , sc : 1 } ,
243- displayPos : { sl : 1 , sc : 1 }
244- } ) ;
245- } ) ;
230+ // returns function arguments for an ast node
231+ var astParam = function ( ast ) {
232+ var params = [ ] ;
246233
247- _ . forEach ( ev . data . results . functions , function ( func ) {
248- items . push ( {
249- icon : "method2" ,
250- name : func . name + "(" + func . params . join ( ", " ) + ")" ,
251- pos : { sl : 1 , sc : 1 } ,
252- displayPos : { sl : 1 , sc : 1 }
253- } ) ;
234+ _ . forEach ( ast , function ( ele ) {
235+ if ( ele . cursor == completion_type . parameter_t ) {
236+ params . push ( ele . type + " " + ele . name ) ;
237+ }
254238 } ) ;
255239
256- _ . forEach ( ev . data . results . classes , function ( c ) {
257- var itemssub = [ ] ;
240+ return "(" + params . join ( ", " ) + ")" ;
241+ }
258242
259- _ . forEach ( c . functions , function ( func ) {
260- itemssub . push ( {
261- icon : "method2" ,
262- name : func . name + "(" + func . params . join ( ", " ) + ")" ,
263- pos : { sl : 1 , sc : 1 } ,
264- displayPos : { sl : 1 , sc : 1 }
265- } ) ;
266- } ) ;
243+ // recursive ast parser function
244+ // @todo : icon for class / union / struct enum
245+ // @todo : take access specifier into account (green = public, blue = protected, red = private)
246+ // @todo : handle enum elements
247+ var parseAst = function ( ast , item ) {
248+ _ . forEach ( ast , function ( ele ) {
249+ switch ( ele . cursor ) {
250+ // includes, no subs
251+ case completion_type . include_t :
252+ item . items . push ( {
253+ icon : "c_cpp_include" ,
254+ name : "<" + ele . name + ">" ,
255+ pos : { sl : ele . loc_row , sc : ele . loc_col } ,
256+ displayPos : { ele . loc_row, sc : ele . loc_col }
257+ } ) ;
258+ break ;
267259
268- _ . forEach ( c . attributes , function ( attr ) {
269- itemssub . push ( {
270- icon : "property" ,
271- name : attr ,
272- pos : { sl : 1 , sc : 1 } ,
273- displayPos : { sl : 1 , sc : 1 }
274- } ) ;
275- } ) ;
260+ // classes, subs maybe other classes, attributes or functions
261+ case completion_type . class_t :
262+ case completion_type . union_t :
263+ case completion_type . struct_t :
264+ case completion_type . enum_t : {
265+ var it = {
266+ icon : "c_cpp_class" ,
267+ name : ele . name ,
268+ pos : { ele. loc_row , sc : ele . loc_col } ,
269+ displayPos : { ele . loc_row, sc : ele . loc_col } ,
270+ items : [ ]
271+ } ;
272+
273+ parseAst ( ele . children , it ) ;
274+ item . items . push ( it ) ;
275+ } break ;
276+
277+ // attributes, no subs
278+ case completion_type . enum_static_t :
279+ case completion_type . attribute_t :
280+ item . items . push ( {
281+ icon : "property" ,
282+ name : ele . name ,
283+ pos : { ele. loc_row , sc : ele . loc_col } ,
284+ displayPos : { ele . loc_row , sc : ele . loc_col }
285+ } ) ;
286+ break ;
276287
277- items . push ( {
278- icon : "c_cpp_class" ,
279- name : c . name ,
280- pos : { sl : 1 , sc : 1 } ,
281- displayPos : { sl : 1 , sc : 1 } ,
282- items : itemssub
283- } ) ;
288+ // functions and methods
289+ case completion_type . function_t :
290+ case completion_type . method_t : {
291+ var it = {
292+ icon : "method2" ,
293+ name : ele . name + astParam ( ele . children ) ,
294+ pos : { sl : 1 , sc : 1 } ,
295+ displayPos : { sl : 1 , sc : 1 } ,
296+ items : [ ]
297+ } ;
298+
299+ parseAst ( ele . children , it ) ;
300+ item . items . push ( it ) ;
301+ } break ;
302+ }
284303 } ) ;
304+ } ;
305+
306+ completer . sender . on ( "_outlineResult" , function invoTmp ( ev ) {
307+ if ( ev . data . id != cId )
308+ return ;
309+
310+ completer . sender . off ( "_outlineResult" , invoTmp ) ;
311+ var data = { items :[ ] } ;
312+ parseAst ( ev . data . ast , data ) ;
285313
286- return callback ( { items : items } ) ;
314+ return callback ( data ) ;
287315 } ) ;
288316
289317 // send the data to the server
0 commit comments