summaryrefslogtreecommitdiffstats
path: root/runtime/syntax/testdir/input
diff options
context:
space:
mode:
authorAliaksei Budavei <32549825+zzzyxwvut@users.noreply.github.com>2024-03-31 19:26:32 +0300
committerGitHub <noreply@github.com>2024-03-31 18:26:32 +0200
commit80aabaab6636faa7cec461acc4b1fcc3a4c89376 (patch)
treeffb21968c9f0a10a95f6ad4168bbf12d0e5ecd72 /runtime/syntax/testdir/input
parent807fff135d52fe8e6e799b78b80cccb299d246a9 (diff)
runtime(vim): Distinguish Vim9 builtin object methods from namesake builtin functions (#14348)
Currently, the overriding object method definitions are matched as vimFunctionError (:help builtin-object-methods, v9.1.0148). For example: ------------------------------------------------------------ vim9script class Test def string(): string return "Test" enddef endclass echo string(Test.new()) == Test.new().string() ------------------------------------------------------------ Instead, let's introduce a new syntax group vimMethodName and make these methods its members. In order to emphasise the link between the overriding methods and the overridden functions for highlighting, vimMethodName is linked by default to vimFuncName. Signed-off-by: Aliaksei Budavei <0x000c70@gmail.com> Signed-off-by: Doug Kearns <dougkearns@gmail.com> Signed-off-by: Christian Brabandt <cb@256bit.org>
Diffstat (limited to 'runtime/syntax/testdir/input')
-rw-r--r--runtime/syntax/testdir/input/vim_object_methods.vim56
1 files changed, 56 insertions, 0 deletions
diff --git a/runtime/syntax/testdir/input/vim_object_methods.vim b/runtime/syntax/testdir/input/vim_object_methods.vim
new file mode 100644
index 0000000000..d22c7f2e6f
--- /dev/null
+++ b/runtime/syntax/testdir/input/vim_object_methods.vim
@@ -0,0 +1,56 @@
+vim9script
+# VIM_TEST_SETUP hi link vimMethodName Todo
+
+
+# Vim |builtin-object-methods| and namesake builtin functions.
+class PairClassTest
+ public const a: any
+ public const b: any
+
+ def new(a: any, b: any)
+ this.a = a
+ this.b = b
+ enddef
+
+ def empty(): bool
+ return false
+ enddef
+ def len(): number
+ return 2
+ enddef
+ def string(): string
+ return printf('(%s, %s)', this.a, this.b)
+ enddef
+endclass
+
+enum MarkerEnumTest
+ INSTANCE
+
+ def NoOp()
+ enddef
+
+ def empty(): bool
+ return true
+ enddef
+ def len(): number
+ return 0
+ enddef
+ def string(): string
+ return this.name
+ enddef
+endenum
+
+const b1: bool = empty(MarkerEnumTest.INSTANCE)
+const n1: number = len(MarkerEnumTest.INSTANCE)
+const s1: string = string(MarkerEnumTest.INSTANCE)
+echo b1 && MarkerEnumTest.INSTANCE.empty()
+echo n1 == 0 && MarkerEnumTest.INSTANCE.len() == 0
+echo s1 == 'INSTANCE' && MarkerEnumTest.INSTANCE.string() == 'INSTANCE'
+
+const pair: PairClassTest = PairClassTest.new(0, 1)
+const b2: bool = !pair.empty()
+const n2: number = pair.len()
+const s2: string = pair.string()
+echo b2 && !empty(pair)
+echo n2 == 2 && len(pair) == 2
+echo s2 == '(0, 1)' && string(pair) == '(0, 1)'