@@ -859,6 +859,92 @@ function_using_block_scopes(ufunc_T *fp, cstack_T *cstack)
859859 cstack -> cs_flags [i ] |= CSF_FUNC_DEF ;
860860}
861861
862+ /*
863+ * Skip over all the characters in a single quoted string starting at "p" and
864+ * return a pointer to the character following the ending single quote.
865+ * If the ending single quote is missing, then return a pointer to the NUL
866+ * character.
867+ */
868+ static char_u *
869+ skip_single_quote_string (char_u * p )
870+ {
871+ p ++ ; // skip the beginning single quote
872+ while (* p != NUL )
873+ {
874+ // Within the string, a single quote can be escaped by using
875+ // two single quotes.
876+ if (* p == '\'' && * (p + 1 ) == '\'' )
877+ p += 2 ;
878+ else if (* p == '\'' )
879+ {
880+ p ++ ; // skip the ending single quote
881+ break ;
882+ }
883+ else
884+ MB_PTR_ADV (p );
885+ }
886+
887+ return p ;
888+ }
889+
890+ /*
891+ * Skip over all the characters in a double quoted string starting at "p" and
892+ * return a pointer to the character following the ending double quote.
893+ * If the ending double quote is missing, then return a pointer to the NUL
894+ * character.
895+ */
896+ static char_u *
897+ skip_double_quote_string (char_u * p )
898+ {
899+ p ++ ; // skip the beginning double quote
900+ while (* p != NUL )
901+ {
902+ // Within the string, a double quote can be escaped by
903+ // preceding it with a backslash.
904+ if (* p == '\\' && * (p + 1 ) == '"' )
905+ p += 2 ;
906+ else if (* p == '"' )
907+ {
908+ p ++ ; // skip the ending double quote
909+ break ;
910+ }
911+ else
912+ MB_PTR_ADV (p );
913+ }
914+
915+ return p ;
916+ }
917+
918+ /*
919+ * Return the start of a Vim9 comment (#) in the line starting at "line".
920+ * If a comment is not found, then returns a pointer to the end of the
921+ * string (NUL).
922+ */
923+ static char_u *
924+ find_start_of_vim9_comment (char_u * line )
925+ {
926+ char_u * p = line ;
927+
928+ while (* p != NUL )
929+ {
930+ if (* p == '\'' )
931+ // Skip a single quoted string.
932+ p = skip_single_quote_string (p );
933+ else if (* p == '"' )
934+ // Skip a double quoted string.
935+ p = skip_double_quote_string (p );
936+ else
937+ {
938+ if (* p == '#' )
939+ // Found the start of a Vim9 comment
940+ break ;
941+ MB_PTR_ADV (p );
942+ }
943+ }
944+
945+ return p ;
946+ }
947+
862948/*
863949 * Read the body of a function, put every line in "newlines".
864950 * This stops at "}", "endfunction" or "enddef".
@@ -1123,7 +1209,17 @@ get_function_body(
11231209 if (nesting_def [nesting ] ? * p != '#' : * p != '"' )
11241210 {
11251211 // Not a comment line: check for nested inline function.
1126- end = p + STRLEN (p ) - 1 ;
1212+
1213+ if (nesting_inline [nesting ])
1214+ {
1215+ // A comment (#) can follow the opening curly brace of a
1216+ // block statement. Need to ignore the comment and look
1217+ // for the opening curly brace before the comment.
1218+ end = find_start_of_vim9_comment (p ) - 1 ;
1219+ }
1220+ else
1221+ end = p + STRLEN (p ) - 1 ;
1222+
11271223 while (end > p && VIM_ISWHITE (* end ))
11281224 -- end ;
11291225 if (end > p + 1 && * end == '{' && VIM_ISWHITE (end [-1 ]))
0 commit comments