annotate runtime/indent/zig.vim @ 33393:016d8f863230 v9.0.1955

patch 9.0.1955: Vim9: lockvar issues with objects/classes Commit: https://github.com/vim/vim/commit/ee865f37acab6cac2cee6a171d60e1b365f852b0 Author: Ernie Rael <errael@raelity.com> Date: Fri Sep 29 19:53:55 2023 +0200 patch 9.0.1955: Vim9: lockvar issues with objects/classes Problem: Vim9: lockvar issues with objects/classes Solution: fix `get_lhs()` object/class access and avoid `SEGV`, make error messages more accurate. - `get_lval()` detects/returns object/class access - `compile_lock_unlock()` generate code for bare static and obj_arg access - `do_lock_var()` check lval for `ll_object`/`ll_class` and fail if so. Details: - Add `ll_object`/`ll_class`/`ll_oi` to `lval_T`. - Add `lockunlock_T` to `isn_T` for `is_arg` to specify handling of `lval_root` in `get_lval()`. - In `get_lval()`, fill in `ll_object`/`ll_class`/`ll_oi` as needed; when no `[idx] or .key`, check lval_root on the way out. - In `do_lock_var()` check for `ll_object`/`ll_class`; also bullet proof ll_dict case and give `Dictionay required` if problem. (not needed to avoid lockvar crash anymore) - In `compile_lock_unlock()` compile for the class variable and func arg cases. closes: #13174 Signed-off-by: Christian Brabandt <cb@256bit.org> Co-authored-by: Ernie Rael <errael@raelity.com>
author Christian Brabandt <cb@256bit.org>
date Fri, 29 Sep 2023 20:00:07 +0200
parents 15c80d8bc515
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
31383
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
1 " Vim filetype indent file
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
2 " Language: Zig
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
3 " Upstream: https://github.com/ziglang/zig.vim
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
4
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
5 " Only load this indent file when no other was loaded.
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
6 if exists("b:did_indent")
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
7 finish
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
8 endif
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
9 let b:did_indent = 1
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
10
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
11 if (!has("cindent") || !has("eval"))
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
12 finish
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
13 endif
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
14
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
15 setlocal cindent
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
16
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
17 " L0 -> 0 indent for jump labels (i.e. case statement in c).
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
18 " j1 -> indenting for "javascript object declarations"
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
19 " J1 -> see j1
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
20 " w1 -> starting a new line with `(` at the same indent as `(`
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
21 " m1 -> if `)` starts a line, match its indent with the first char of its
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
22 " matching `(` line
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
23 " (s -> use one indent, when starting a new line after a trailing `(`
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
24 setlocal cinoptions=L0,m1,(s,j1,J1,l1
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
25
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
26 " cinkeys: controls what keys trigger indent formatting
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
27 " 0{ -> {
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
28 " 0} -> }
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
29 " 0) -> )
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
30 " 0] -> ]
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
31 " !^F -> make CTRL-F (^F) reindent the current line when typed
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
32 " o -> when <CR> or `o` is used
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
33 " O -> when the `O` command is used
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
34 setlocal cinkeys=0{,0},0),0],!^F,o,O
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
35
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
36 setlocal indentexpr=GetZigIndent(v:lnum)
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
37
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
38 let b:undo_indent = "setlocal cindent< cinkeys< cinoptions< indentexpr<"
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
39
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
40 function! GetZigIndent(lnum)
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
41 let curretLineNum = a:lnum
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
42 let currentLine = getline(a:lnum)
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
43
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
44 " cindent doesn't handle multi-line strings properly, so force no indent
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
45 if currentLine =~ '^\s*\\\\.*'
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
46 return -1
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
47 endif
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
48
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
49 let prevLineNum = prevnonblank(a:lnum-1)
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
50 let prevLine = getline(prevLineNum)
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
51
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
52 " for lines that look like
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
53 " },
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
54 " };
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
55 " try treating them the same as a }
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
56 if prevLine =~ '\v^\s*},$'
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
57 if currentLine =~ '\v^\s*};$' || currentLine =~ '\v^\s*}$'
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
58 return indent(prevLineNum) - 4
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
59 endif
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
60 return indent(prevLineNum-1) - 4
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
61 endif
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
62 if currentLine =~ '\v^\s*},$'
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
63 return indent(prevLineNum) - 4
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
64 endif
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
65 if currentLine =~ '\v^\s*};$'
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
66 return indent(prevLineNum) - 4
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
67 endif
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
68
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
69
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
70 " cindent doesn't handle this case correctly:
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
71 " switch (1): {
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
72 " 1 => true,
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
73 " ~
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
74 " ^---- indents to here
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
75 if prevLine =~ '.*=>.*,$' && currentLine !~ '.*}$'
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
76 return indent(prevLineNum)
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
77 endif
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
78
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
79 return cindent(a:lnum)
15c80d8bc515 Update runtime files
Bram Moolenaar <Bram@vim.org>
parents:
diff changeset
80 endfunction