Skip to content

Commit 449e94f

Browse files
committed
Significant performance improvements to goFuncParam, eliminate the need to refer to @GoType and goVariadic when using goFuncParam
1 parent 6281ed8 commit 449e94f

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

goFuncParam_Diagrams.monopic

250 Bytes
Binary file not shown.

syntax/go.vim

Lines changed: 16 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -451,7 +451,7 @@ syntax keyword goPrimitiveTypes any bool byte complex128 complex64 error float32
451451

452452
syntax match goFuncType /func\s*(/ contained contains=goFuncTypeParens skipwhite nextgroup=@goType,goFuncTypeMultiReturnType
453453

454-
syntax region goFuncTypeParens matchgroup=goFuncParens start='(' end=')' contained contains=goFuncParam,@goType,goComma,goComment
454+
syntax region goFuncTypeParens matchgroup=goFuncParens start='(' end=')' contained contains=goFuncParam,goComma,goComment
455455
syntax region goFuncTypeMultiReturnType matchgroup=goFuncMultiReturnParens start='(' end=')' contained contains=goNamedReturnValue,goComma,goComment
456456

457457
syntax keyword goMapType map contained skipwhite skipempty nextgroup=goMapTypeKeyType
@@ -548,9 +548,9 @@ syntax match goTypeConstraintSymbols /[~|]/ contained
548548
" goFuncMultiReturn); look into this further and try to remove this.
549549
syntax match goFuncReturnType /\s*\zs(\@1<!\%(\%(interface\|struct\)\s*{\|[^{]\)\+/ contained contains=@goType skipwhite skipempty nextgroup=goFuncBlock
550550

551-
syntax region goFuncParams matchgroup=goFuncParens start='(' end=')' contained contains=goFuncParam,@goType,goComma,goComment skipwhite nextgroup=goFuncReturnType,goFuncMultiReturn,goFuncBlock
551+
syntax region goFuncParams matchgroup=goFuncParens start='(' end=')' contained contains=goFuncParam,goComma,goComment skipwhite nextgroup=goFuncReturnType,goFuncMultiReturn,goFuncBlock
552552
syntax region goFuncMultiReturn matchgroup=goFuncMultiReturnParens start='(' end=')' contained contains=goNamedReturnValue,goComma,goComment skipwhite skipempty nextgroup=goFuncBlock
553-
syntax region goMethodReceiver matchgroup=goReceiverParens start='(' end=')' contained contains=goFuncParam,@goType,goComment skipwhite skipempty nextgroup=goFuncName
553+
syntax region goMethodReceiver matchgroup=goReceiverParens start='(' end=')' contained contains=goFuncParam,goComment skipwhite skipempty nextgroup=goFuncName
554554

555555
GoFoldFunc syntax region goFuncBlock matchgroup=goFuncBraces start='{' end='}' contained contains=@goStatement skipwhite nextgroup=goFuncCallArgs
556556

@@ -564,22 +564,20 @@ GoFoldFunc syntax region goFuncBlock matchgroup=goFuncBraces start='{' end='}' c
564564
" ')\@1<=' didn't work for some reason (i.e. when typing a parameter name, it
565565
" was highlighted as a type).
566566
"
567-
" TODO: Performance: Figure out how to remove the need for @goType every time
568-
" goFuncParam is used. This would require this regex to have a zero-length
569-
" match when it's just the type.
570-
"
571567
" goFuncParam: Assume the user is typing a parameter name (i.e. avoid
572568
" highlighting parameter names as types until proven otherwise).
573-
syntax match goFuncParam /\%(^\|[(,]\)\@1<=\s*\zs\%(\%(\K\k*\s*,\%(\s\|\n\)*\)*\%(chan\>\)\@!\K\k*\)\%(\s*,\?\%(\s\|\n\)*\%#\ze)\|\s\+\ze[^,]\)/ contained contains=goComma,goUnderscore skipwhite nextgroup=@goType,goVariadic
574-
" └──────────────────┘ │ └──────────────┘ │└────────────┘ │└────────────────┘ │ │ │ "
575-
" Param must be preceded │ comma/ws/nl │ 'chan' a type, │ comma/ws/nl │ │ │ "
576-
" by start of line, '(', │ │ not param name │ │ │ │ "
577-
" or ',' followed by └────────────────────────────┘ └────────────────────────┘ └───────────┘ "
578-
" whitespace zero or more previous params if this matches, then we otherwise if this "
579-
" (e.g. 'a, b, ' in 'a, b, c') have one or more params, matches, we have "
580-
" then cursor, then close params then type, "
581-
" paren, e.g.: e.g.: "
582-
" (a, b, c, |) (a, b foo) "
569+
" conditional group allows skipping directly to type, e.g. func(SomeType) "
570+
" ┌───────────────────────────────────────────────────────────────────────────────────────────────────┐ "
571+
syntax match goFuncParam /\%(^\|[(,]\)\@1<=\s*\zs\%(\%(\%(\K\k*\s*,\%(\s\|\n\)*\)*\%(chan\>\)\@!\K\k*\)\%(\s*,\?\%(\s\|\n\)*\%#\ze)\|\s\+\ze[^,]\)\)\?/ contained contains=goComma,goUnderscore skipwhite nextgroup=@goType,goVariadic
572+
" └──────────────────┘ │ └──────────────┘ │└────────────┘ │└────────────────┘ │ │ │ "
573+
" Param must be preceded │ comma/ws/nl │ 'chan' a type, │ comma/ws/nl │ │ │ "
574+
" by start of line, '(', │ │ not param name │ │ │ │ "
575+
" or ',' followed by └────────────────────────────┘ └────────────────────────┘ └───────────┘ "
576+
" whitespace zero or more previous params if this matches, then we otherwise if this "
577+
" (e.g. 'a, b, ' in 'a, b, c') have one or more params, matches, we have "
578+
" then cursor, then close params then type, "
579+
" paren, e.g.: e.g.: "
580+
" (a, b, c, |) (a, b foo) "
583581
" The above diagrams can be found in the Monodraw file goFuncParam_Diagrams.monopic
584582

585583
" goFuncParam: Assume the user is typing a type (i.e. avoid highlighting custom
@@ -649,7 +647,7 @@ syntax keyword goInterfaceType interface contained skipwhite skipempty nextgroup
649647
GoFoldInterface syntax region goInterfaceBlock matchgroup=goInterfaceBraces start='{' end='}' contained contains=@goType,goTypeConstraintSymbols,goInterfaceMethod,goComment extend
650648

651649
syntax match goInterfaceMethod /\K\k*\ze(/ contained skipwhite nextgroup=goInterfaceMethodParams
652-
syntax region goInterfaceMethodParams matchgroup=goInterfaceMethodParens start='(' end=')' contained contains=goFuncParam,@goType,goComma,goComment skipwhite nextgroup=@goType,goInterfaceMethodMultiReturn
650+
syntax region goInterfaceMethodParams matchgroup=goInterfaceMethodParens start='(' end=')' contained contains=goFuncParam,goComma,goComment skipwhite nextgroup=@goType,goInterfaceMethodMultiReturn
653651
syntax region goInterfaceMethodMultiReturn matchgroup=goFuncMultiReturnParens start='(' end=')' contained contains=goNamedReturnValue,goComma,goComment
654652

655653
hi link goStructType Keyword

0 commit comments

Comments
 (0)