From e89dbcac879c0d443c5226f87f2a9307b53ebb95 Mon Sep 17 00:00:00 2001 From: Chris Date: Tue, 9 Dec 2025 23:07:24 +0000 Subject: [PATCH] Cool stuff --- lua/keymap.lua | 2 +- lua/snippets/php.lua | 230 ++++++++++++++++++++++++++++--------------- 2 files changed, 153 insertions(+), 79 deletions(-) diff --git a/lua/keymap.lua b/lua/keymap.lua index 8b172f0..8d1886d 100644 --- a/lua/keymap.lua +++ b/lua/keymap.lua @@ -60,7 +60,7 @@ end, { desc = 'Select surrounding treesitter node' }) local swappable_nodes = { 'argument', 'array_element_initializer', 'simple_parameter', 'string', 'integer', 'member_call_expression', 'method_declaration' } local function closest_swappable_node(node) - while node and not vim.list_contains(swappable_nodes, node:type()) do + while node and not vim.list_contains(swappable_nodes, node:type()) and (not node:next_named_sibling() or not node:prev_named_sibling()) do node = node:parent() end return node diff --git a/lua/snippets/php.lua b/lua/snippets/php.lua index c2bad7a..694bbcc 100644 --- a/lua/snippets/php.lua +++ b/lua/snippets/php.lua @@ -248,45 +248,39 @@ return { bs(atr('b%$', 'bool type parameter'), fmta('bool $#~', { i(0, 'var') })), bs(atr('a%$', 'array type parameter'), fmta('array $#~', { i(0, 'var') })), s(atr('$ ', 'Expand $this->'), fmta('$this->#~', { i(0) })), - bs( - etr('am ', 'array_map function'), - { - c(1, { - sn(nil, fmta('array_map(fn (#~) => #~, #~)', { i(2), i(3), i(1) })), - sn( - nil, - fmta( - [[ + bs(etr('am ', 'array_map function'), { + c(1, { + sn(nil, fmta('array_map(fn (#~) => #~, #~)', { i(2), i(3), i(1) })), + sn( + nil, + fmta( + [[ array_map(function (#~) { #~ }, #~) ]], - { i(2), i(0), i(1) } - ) - ), - }), - } - ), + { i(2), i(0), i(1) } + ) + ), + }), + }), bs(etr('array_map', 'array_map function'), fmta('am', {})), - bs( - etr('af ', 'array_filter function'), - { - c(1, { - sn(nil, fmta('array_filter(#~, fn (#~) => #~)', { i(1), i(2), i(3) })), - sn( - nil, - fmta( - [[ + bs(etr('af ', 'array_filter function'), { + c(1, { + sn(nil, fmta('array_filter(#~, fn (#~) => #~)', { i(1), i(2), i(3) })), + sn( + nil, + fmta( + [[ array_filter(#~, function (#~) { #~ }) ]], - { i(1), i(2), i(0) } - ) - ), - }), - } - ), + { i(1), i(2), i(0) } + ) + ), + }), + }), bs(etr('array_filter', 'array_filter function'), fmta('af', {})), s( etr('php', 'php class'), @@ -377,63 +371,143 @@ return { ------------- s( etr('bt', 'belongsTo Laravel relationship method'), - fmta( - [[ - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\#~, $this> - */ - public function #~(): BelongsTo - { - return $this->belongsTo(#~::class); - } - ]], - { rep(1), i(0), i(1) } - ) + c(0, { + sn( + nil, + fmta( + [[ + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\#~, $this> + */ + public function #~(): BelongsTo + { + return $this->belongsTo(#~::class); + } + ]], + { rep(1), i(0), i(1) } + ) + ), + sn( + nil, + fmta( + [[ + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsTo<\App\Models\#~, $this> + */ + public function #~(): BelongsTo + { + return $this->belongsTo(#~::class, #~); + } + ]], + { rep(1), i(2), i(1), i(0) } + ) + ), + }) ), s( etr('hm', 'hasMany Laravel relationship method'), - fmta( - [[ - /** - * @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\#~, $this> - */ - public function #~(): HasMany - { - return $this->hasOne(#~::class); - } - ]], - { rep(1), i(0), i(1) } - ) + c(0, { + sn( + nil, + fmta( + [[ + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\#~, $this> + */ + public function #~(): HasMany + { + return $this->hasOne(#~::class); + } + ]], + { rep(1), i(0), i(1) } + ) + ), + sn( + nil, + fmta( + [[ + /** + * @return \Illuminate\Database\Eloquent\Relations\HasMany<\App\Models\#~, $this> + */ + public function #~(): HasMany + { + return $this->hasOne(#~::class, #~); + } + ]], + { rep(1), i(2), i(1), i(0) } + ) + ), + }) ), s( etr('ho', 'hasOne Laravel relationship method'), - fmta( - [[ - /** - * @return \Illuminate\Database\Eloquent\Relations\HasOne<\App\Models\#~, $this> - */ - public function #~(): HasOne - { - return $this->hasOne(#~::class); - } - ]], - { rep(1), i(0), i(1) } - ) + c(0, { + sn( + nil, + fmta( + [[ + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne<\App\Models\#~, $this> + */ + public function #~(): HasOne + { + return $this->hasOne(#~::class); + } + ]], + { rep(1), i(0), i(1) } + ) + ), + sn( + nil, + fmta( + [[ + /** + * @return \Illuminate\Database\Eloquent\Relations\HasOne<\App\Models\#~, $this> + */ + public function #~(): HasOne + { + return $this->hasOne(#~::class, #~); + } + ]], + { rep(1), i(2), i(1), i(0) } + ) + ), + }) ), s( etr('bm', 'belongsToMany Laravel relationship method'), - fmta( - [[ - /** - * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\App\Models\#~, $this> - */ - public function #~(): BelongsToMany - { - return $this->belongsToMany(#~::class, #~); - } - ]], - { rep(1), i(2), i(1), i(0) } - ) + c(0, { + sn( + nil, + fmta( + [[ + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\App\Models\#~, $this> + */ + public function #~(): BelongsToMany + { + return $this->belongsToMany(#~::class, #~); + } + ]], + { rep(1), i(2), i(1), i(0) } + ) + ), + sn( + nil, + fmta( + [[ + /** + * @return \Illuminate\Database\Eloquent\Relations\BelongsToMany<\App\Models\#~, $this> + */ + public function #~(): BelongsToMany + { + return $this->belongsToMany(#~::class, #~, #~); + } + ]], + { rep(1), i(2), i(1), i(3), i(0) } + ) + ), + }) ), s( atr('->wr', 'Eloquent where method'),