4
4
5
5
" ------------------------------------------------------------------------
6
6
" Omni completion functions
7
+ " {{{
7
8
"
8
9
" Requires ctags from:
9
10
" https://github.com/fishman/ctags
10
11
" https://github.com/exuberant-ctags/ctags
11
12
" ctags must be run with --extra=+q
12
- " {{{
13
13
function ! verilog_systemverilog#Complete (findstart, base)
14
+ " {{{
14
15
" ------------------------------------------------------------------------
15
16
" Phase 1: Find and return prefix of completion
17
+ " s:word contains the keyword to be completed
18
+ " s:prefix contains the "name." prefix preceding s:word
19
+ " s:instname name of the instance ("." completion only)
20
+ " s:module name of the instance ("." completion only)
16
21
if a: findstart
17
22
let linenr = line (' .' )
18
23
let line = getline (' .' )
19
24
let start = col (' .' )
20
25
let prefixpos = -1
21
26
let s: instname = ' '
22
- let s: insttype = ' '
27
+ let s: module = ' '
23
28
24
29
" Define start position depending on relation with end of line
25
30
if start == col (' $' )
@@ -56,11 +61,13 @@ function! verilog_systemverilog#Complete(findstart, base)
56
61
let s: prefix = strpart (line , start , prefixpos - start )
57
62
let s: word = strpart (line , prefixpos, wordpos - prefixpos)
58
63
64
+ " If the prefix is simply a "." assume that this is an instance
65
+ " port connection and search for its declaration
59
66
if s: prefix == ' .'
60
67
" Get instance info and break from while loop
61
68
let values = s: GetInstanceInfo (linenr , start )
62
69
let s: instname = values [0 ]
63
- let s: insttype = values [1 ]
70
+ let s: module = values [1 ]
64
71
endif
65
72
endif
66
73
@@ -72,36 +79,36 @@ function! verilog_systemverilog#Complete(findstart, base)
72
79
if exists (" s:prefix" ) && s: prefix != ' '
73
80
call verilog_systemverilog#Verbose (" Prefix: " . s: prefix )
74
81
call verilog_systemverilog#Verbose (" Word : " . s: word )
75
- if s: insttype != ' '
82
+ if s: module != ' '
76
83
" Process an instance
77
84
call verilog_systemverilog#Verbose (" Process instance" )
78
85
if exists (" s:word" )
79
- let tags = taglist (' ^' . s: insttype . ' \.' . s: word )
86
+ let tags = taglist (' ^' . s: module . ' \.' . s: word )
80
87
else
81
- let tags = taglist (' ^' . s: insttype . ' \.' )
88
+ let tags = taglist (' ^' . s: module . ' \.' )
82
89
endif
83
90
call verilog_systemverilog#Verbose (" Number of tags found: " . len (tags ))
84
91
if s: instname != ' '
85
92
" In instances only return ports
86
- let tags = s: FilterPorts (tags )
93
+ let tags = s: TagsFilterPorts (tags )
87
94
" Filter out hierarchical ports
88
95
call filter (tags , ' len(split(v:val["name"], "\\.")) > 2 ? 0 : 1' )
89
96
call verilog_systemverilog#Verbose (" Number of tags after filtering: " . len (tags ))
90
97
" Remove the module name prefix
91
- call map (tags , ' strpart(v:val["name"], len(s:insttype . "."))' )
98
+ call map (tags , ' strpart(v:val["name"], len(s:module . "."))' )
92
99
if (v: version >= 704 )
93
100
return {' words' : tags }
94
101
else
95
102
return tags
96
103
endif
97
104
else
98
105
" In parameter list only return constants
99
- let tags = s: FilterConstants (tags )
106
+ let tags = s: TagsFilterConstants (tags )
100
107
" Filter out hierarchical ports
101
108
call filter (tags , ' len(split(v:val["name"], "\\.")) > 2 ? 0 : 1' )
102
109
call verilog_systemverilog#Verbose (" Number of tags after filtering: " . len (tags ))
103
110
" Remove the module name prefix
104
- call map (tags , ' strpart(v:val["name"], len(s:insttype . "."))' )
111
+ call map (tags , ' strpart(v:val["name"], len(s:module . "."))' )
105
112
if (v: version >= 704 )
106
113
return {' words' : tags }
107
114
else
@@ -120,7 +127,7 @@ function! verilog_systemverilog#Complete(findstart, base)
120
127
let base = s: instname
121
128
endif
122
129
call verilog_systemverilog#Verbose (" Searching tags starting with " . base)
123
- let tags = s: FilterPortsOrConstants (taglist (' ^' . base . ' \.' ))
130
+ let tags = s: TagsFilterPortsOrConstants (taglist (' ^' . base . ' \.' ))
124
131
call map (tags , ' strpart(v:val["name"], len(base . "."))' )
125
132
if (v: version >= 704 )
126
133
return {' words' : tags }
@@ -172,17 +179,19 @@ function! verilog_systemverilog#Complete(findstart, base)
172
179
return -1
173
180
endif
174
181
endfunction
182
+ " }}}
175
183
176
184
" Search file for instance information:
177
185
" * name
178
186
" * type (typically a module name, but can also be a function/task/etc)
179
187
" * line number
180
188
function ! s: GetInstanceInfo (linenr , column)
189
+ " {{{
181
190
let linenr = a: linenr
182
191
let line = getline (linenr )
183
192
let start = a: column
184
193
let instname = " "
185
- let insttype = " "
194
+ let module = " "
186
195
let ininstdecl = 0
187
196
let ininsttype = 0
188
197
let p = 0
@@ -253,11 +262,11 @@ function! s:GetInstanceInfo(linenr, column)
253
262
let ininsttype = start
254
263
elseif ininsttype > 0 && (line [start - 1 ] = ~ ' \s' || start == 1 )
255
264
if start == 1 && line [start - 1 ] !~ ' \s'
256
- let insttype = strpart (line , 0 , ininsttype)
265
+ let module = strpart (line , 0 , ininsttype)
257
266
else
258
- let insttype = strpart (line , start , ininsttype - start )
267
+ let module = strpart (line , start , ininsttype - start )
259
268
endif
260
- call verilog_systemverilog#Verbose (" Found instance type \" " . insttype . " \" , on line " . linenr )
269
+ call verilog_systemverilog#Verbose (" Found instance type \" " . module . " \" , on line " . linenr )
261
270
break
262
271
endif
263
272
@@ -281,12 +290,14 @@ function! s:GetInstanceInfo(linenr, column)
281
290
let start = len (line )
282
291
endwhile
283
292
284
- call verilog_systemverilog#Verbose (" Found instance. Name: »" . instname . " « Type: »" . insttype . " «" )
285
- return [instname, insttype , linenr ]
293
+ call verilog_systemverilog#Verbose (" Found instance. Name: »" . instname . " « Type: »" . module . " «" )
294
+ return [instname, module , linenr ]
286
295
endfunction
296
+ " }}}
287
297
288
298
" Append signature to functions and tasks
289
299
function s: AppendSignature (tags )
300
+ " {{{
290
301
let newtags = []
291
302
for t in a: tags
292
303
if t [" kind" ] == " t" || t [" kind" ] == " f"
@@ -296,9 +307,11 @@ function s:AppendSignature(tags)
296
307
endfor
297
308
return newtags
298
309
endfunction
310
+ " }}}
299
311
300
312
" Get list of inheritance tags
301
313
function s: GetInheritanceTags (class , object)
314
+ " {{{
302
315
call verilog_systemverilog#Verbose (" Searching inheritance of " . a: object )
303
316
let tags = []
304
317
let inheritance = a: class
@@ -333,9 +346,11 @@ function s:GetInheritanceTags(class, object)
333
346
endwhile
334
347
return tags
335
348
endfunction
349
+ " }}}
336
350
337
351
" Searches for declaration of "word" and returns its type
338
352
function s: GetVariableType (word)
353
+ " {{{
339
354
let position = getpos (" ." )
340
355
if searchdecl (a: word , 0 ) == 0
341
356
let line = getline (' .' )
@@ -348,9 +363,11 @@ function s:GetVariableType(word)
348
363
endif
349
364
return 0
350
365
endfunction
366
+ " }}}
351
367
352
368
" Searches for declaration of "object" and returns "parameter" initialization value
353
369
function s: GetObjectParameterValue (object, parameter)
370
+ " {{{
354
371
let position = getpos (" ." )
355
372
if searchdecl (a: object , 0 ) == 0
356
373
let line = getline (' .' )
@@ -366,9 +383,11 @@ function s:GetObjectParameterValue(object, parameter)
366
383
call setpos (" ." , position)
367
384
return " "
368
385
endfunction
386
+ " }}}
369
387
370
388
" Searches for declaration of "class" and returns default "parameter" value
371
389
function s: GetClassDefaultParameterValue (class , parameter)
390
+ " {{{
372
391
if a: class == " "
373
392
call verilog_systemverilog#Verbose (" Search for default value of parameter " . a: parameter . " in current class" )
374
393
let declaration = {' cmd' : ' /.*type\s\+' . a: parameter . ' \s*=' }
@@ -412,61 +431,75 @@ function s:GetClassDefaultParameterValue(class, parameter)
412
431
return " "
413
432
endif
414
433
endfunction
434
+ " }}}
415
435
416
436
" Filter tag list to only return ports
417
- function s: FilterPorts (tags )
437
+ function s: TagsFilterPorts (tags )
438
+ " {{{
418
439
let tags = a: tags
419
440
call filter (tags , ' has_key(v:val, "kind") ? v:val["kind"] == "p" : 1' )
420
441
return tags
421
442
endfunction
443
+ " }}}
422
444
423
445
" Filter tag list to only return constants
424
- function s: FilterConstants (tags )
446
+ function s: TagsFilterConstants (tags )
447
+ " {{{
425
448
let tags = a: tags
426
449
call filter (tags , ' has_key(v:val, "kind") ? v:val["kind"] == "c" : 1' )
427
450
return tags
428
451
endfunction
452
+ " }}}
429
453
430
454
" Filter tag list to only return ports or constants
431
- function s: FilterPortsOrConstants (tags )
455
+ function s: TagsFilterPortsOrConstants (tags )
456
+ " {{{
432
457
let tags = a: tags
433
458
call filter (tags , ' has_key(v:val, "kind") ? v:val["kind"] == "p" || v:val["kind"] == "c" : 1' )
434
459
return tags
435
460
endfunction
436
461
" }}}
462
+ " }}}
437
463
438
464
" ------------------------------------------------------------------------
439
465
" Common functions
440
466
" {{{
441
467
" Verbose messaging
442
468
" Only displays messages if b:verilog_verbose or g:verilog_verbose is defined
443
469
function verilog_systemverilog#Verbose (message)
470
+ " {{{
444
471
if verilog_systemverilog#VariableExists (" verilog_verbose" )
445
472
echom a: message
446
473
endif
447
474
endfunction
475
+ " }}}
448
476
449
477
" Configuration control
450
478
" Pushes value to list only if new
451
479
" Based on: http://vi.stackexchange.com/questions/6619/append-to-global-variable-and-completion
452
480
function verilog_systemverilog#PushToVariable (variable, value)
481
+ " {{{
453
482
let list = verilog_systemverilog#VariableGetValue (a: variable )
454
483
if (count (list , a: value ) == 0 )
455
484
call add (list , a: value )
456
485
endif
457
486
call verilog_systemverilog#VariableSetValue (a: variable , list )
458
487
endfunction
488
+ " }}}
459
489
460
490
function verilog_systemverilog#PopFromVariable (variable, value)
491
+ " {{{
461
492
let list = verilog_systemverilog#VariableGetValue (a: variable )
462
493
call verilog_systemverilog#VariableSetValue (a: variable , filter (list , " v:val !=# a:value" ))
463
494
endfunction
495
+ " }}}
464
496
465
497
" Get variable value
466
498
" Searches for both b:variable and g:variable, with this priority.
467
499
" If the variable name includes '_lst' it is automatically split into a
468
500
" list.
469
501
function verilog_systemverilog#VariableGetValue (variable)
502
+ " {{{
470
503
if exists (' b:' . a: variable )
471
504
let value = eval (' b:' . a: variable )
472
505
elseif exists (' g:' . a: variable )
@@ -480,13 +513,15 @@ function verilog_systemverilog#VariableGetValue(variable)
480
513
return value
481
514
endif
482
515
endfunction
516
+ " }}}
483
517
484
518
" Set variable value
485
519
" Searches for both b:variable and g:variable, with this priority.
486
520
" If none exists, g: will be used
487
521
" If the variable name includes '_lst' the value argument is assumed to
488
522
" be a list.
489
523
function verilog_systemverilog#VariableSetValue (variable, value)
524
+ " {{{
490
525
if a: variable = ~ ' _lst'
491
526
let value = join (a: value , ' ,' )
492
527
else
@@ -498,17 +533,21 @@ function verilog_systemverilog#VariableSetValue(variable, value)
498
533
exec ' let g:' . a: variable . ' = value'
499
534
endif
500
535
endfunction
536
+ " }}}
501
537
502
538
" Checks for variable existence
503
539
function verilog_systemverilog#VariableExists (variable)
540
+ " {{{
504
541
return exists (' b:' . a: variable ) || exists (' g:' . a: variable )
505
542
endfunction
506
543
" }}}
544
+ " }}}
507
545
508
546
" ------------------------------------------------------------------------
509
547
" Command completion functions
510
548
" {{{
511
549
function verilog_systemverilog#CompleteCommand (lead, command , cursor )
550
+ " {{{
512
551
" Get list with current values in variable
513
552
if (a: command = ~ ' Folding' )
514
553
let current_values = verilog_systemverilog#VariableGetValue (" verilog_syntax_fold_lst" )
@@ -614,18 +653,22 @@ function verilog_systemverilog#CompleteCommand(lead, command, cursor)
614
653
endif
615
654
endfunction
616
655
" }}}
656
+ " }}}
617
657
618
658
" ------------------------------------------------------------------------
619
659
" External functions
620
660
" {{{
621
661
function verilog_systemverilog#GotoInstanceStart (line , column)
662
+ " {{{
622
663
let values = s: GetInstanceInfo (a: line , col (' $' ))
623
664
if values [2 ] != " "
624
665
call cursor (values [2 ], a: column )
625
666
endif
626
667
endfunction
668
+ " }}}
627
669
628
670
function verilog_systemverilog#FollowInstanceTag (line , column)
671
+ " {{{
629
672
let values = s: GetInstanceInfo (a: line , col (' $' ))
630
673
if exists (" g:verilog_navigate_split" )
631
674
exec " wincmd " .g: verilog_navigate_split
@@ -634,8 +677,10 @@ function verilog_systemverilog#FollowInstanceTag(line, column)
634
677
execute " tag " . values [1 ]
635
678
endif
636
679
endfunction
680
+ " }}}
637
681
638
682
function verilog_systemverilog#ReturnFromInstanceTag ()
683
+ " {{{
639
684
if winnr (' $' ) > 1 && exists (" g:verilog_navigate_split" )
640
685
if exists (" g:verilog_navigate_split_close" )
641
686
exec g: verilog_navigate_split_close
@@ -646,19 +691,23 @@ function verilog_systemverilog#ReturnFromInstanceTag()
646
691
exec " pop"
647
692
endif
648
693
endfunction
694
+ " }}}
649
695
650
696
function verilog_systemverilog#FollowInstanceSearchWord (line , column)
697
+ " {{{
651
698
let @/ = ' \<' .expand (" <cword>" ).' \>'
652
699
call verilog_systemverilog#FollowInstanceTag (a: line , a: column )
653
700
exec " normal!" . @/
654
701
normal ! n
655
702
endfunction
656
703
" }}}
704
+ " }}}
657
705
658
706
" ------------------------------------------------------------------------
659
707
" Command to control errorformat and compiler
660
708
" {{{
661
709
function ! verilog_systemverilog#VerilogErrorFormat (... )
710
+ " {{{
662
711
" Choose tool
663
712
if (a: 0 == 0 )
664
713
let l: tool = inputlist ([
@@ -742,5 +791,6 @@ function! verilog_systemverilog#VerilogErrorFormat(...)
742
791
endif
743
792
endfunction
744
793
" }}}
794
+ " }}}
745
795
746
796
" vi: sw = 2 sts = 2 fdm = marker:
0 commit comments