From 675b02f147d67842a4ddaed87dbe9d92613ce7d1 Mon Sep 17 00:00:00 2001 From: "Gustavo \"Guz\" L de Mello" Date: Wed, 10 Dec 2025 17:42:25 -0300 Subject: [PATCH] feat: auto-highlight on mouse hover and yank --- README.md | 2 +- flake.nix | 3 ++ lua/dot/init.lua | 46 +++++++++++++++++++++++++ scripts/godot-neovim.sh | 75 +++++++++++++++++++++++++++++++++++++++++ 4 files changed, 125 insertions(+), 1 deletion(-) create mode 100644 scripts/godot-neovim.sh diff --git a/README.md b/README.md index 252d7cd..e6abc26 100644 --- a/README.md +++ b/README.md @@ -37,7 +37,7 @@ you can run the configured Neovim binary with just: nix run git+https://forge.capytal.company/dot013/nvim # GitHub mirror -niix run github:dot013/nvim +nix run github:dot013/nvim ``` It also can be used as a NixOS or [Home-Manager](https://github.com/nix-community/home-manager) diff --git a/flake.nix b/flake.nix index ef070db..424e00a 100644 --- a/flake.nix +++ b/flake.nix @@ -41,6 +41,9 @@ neovim = pkgs.callPackage ./package.nix { mdfmt = self.packages.${stdenv.hostPlatform.system}.mdfmt; }; + godot-neovim = pkgs.writeShellApplication { + name = "godot-neovim"; + }; mdfmt = pkgs.buildGoModule { name = "mdfmt"; src = inputs.mdfmt; diff --git a/lua/dot/init.lua b/lua/dot/init.lua index 5c8ebe8..2187b31 100644 --- a/lua/dot/init.lua +++ b/lua/dot/init.lua @@ -86,3 +86,49 @@ vim.diagnostic.config({ require("dot.keymaps") +vim.api.nvim_create_autocmd("TextYankPost", { + desc = "Highlight when yanking text", + group = vim.api.nvim_create_augroup("dot-highlight-yank", { clear = true }), + callback = function() + vim.hl.on_yank() + end, +}) + +vim.api.nvim_create_autocmd("LspAttach", { + group = vim.api.nvim_create_augroup("dot-lsp-attach-autocmds", { clear = true }), + callback = function(e) + local client = vim.lsp.get_client_by_id(e.data.client_id) + + -- Highlight references of word under cursor when it rests for a little while + if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_documentHighlight, e.buf) then + local highlight_augroup = vim.api.nvim_create_augroup("dot-lsp-highlight", { clear = false }) + + vim.api.nvim_create_autocmd({ "CursorHold", "CursorHoldI" }, { + buffer = e.buf, + callback = vim.lsp.buf.document_highlight, + group = highlight_augroup, + }) + + vim.api.nvim_create_autocmd({ "CursorMoved", "CursorMovedI" }, { + buffer = e.buf, + callback = vim.lsp.buf.clear_references, + group = highlight_augroup, + }) + + vim.api.nvim_create_autocmd("LspDetach", { + callback = function(e2) + vim.lsp.buf.clear_references() + vim.api.nvim_clear_autocmds({ group = "dot-lsp-attach-autocmds", buffer = e2.buf }) + end, + group = vim.api.nvim_create_augroup("dot-lsp-detach-autocmds", { clear = true }), + }) + end + + -- Toggle inlay hints + if client and client:supports_method(vim.lsp.protocol.Methods.textDocument_inlayHint, e.buf) then + vim.keymap.set("n", "lh", function() + vim.lsp.inlay_hint.enable(not vim.lsp.inlay_hint.is_enabled({ bufnr = e.buf })) + end, { desc = "LSP: [T]oggle Inlay [H]ints" }) + end + end, +}) diff --git a/scripts/godot-neovim.sh b/scripts/godot-neovim.sh new file mode 100644 index 0000000..21924d9 --- /dev/null +++ b/scripts/godot-neovim.sh @@ -0,0 +1,75 @@ +#!/usr/bin/env bash + +# Script provided by Mathijs Bakker's godotdev.nvim, licensed under the Apache +# License Version 2.0. +# +# A copy of the original script can be found at +# https://github.com/Mathijs-Bakker/godotdev.nvim/blob/79d9315988b7772c03a1cabb6f31f5287c849e2b/doc/neovim-external-editor-setup.md#installation +# +# A copy of the original license can be found at +# https://github.com/Mathijs-Bakker/godotdev.nvim/blob/79d9315988b7772c03a1cabb6f31f5287c849e2b/LICENSE + +# Godot → Neovim launcher with GUI terminal focus +# Usage: +# godot-nvr.sh [terminal_name] +{line} {file} [--tab|--vsplit] + +# ----------------------------- +# Arguments +# ----------------------------- +DEFAULT_TERMINAL="${DEFAULT_TERMINAL:=ghostty}" +ARG0="$1" + +if [[ "$ARG0" == +* || "$ARG0" == --* || -f "$ARG0" ]]; then + # No terminal argument provided, use default + GODOT_TERMINAL="$DEFAULT_TERMINAL" +else + # First argument is terminal name + GODOT_TERMINAL="$ARG0" + shift +fi + +SOCKET="${SOCKET:=/tmp/godot.pipe}" # Neovim socket path +NVR="${NVR:=/Library/Frameworks/Python.framework/Versions/3.8/bin/nvr}" + +OPEN_MODE="window" +LINE="" +FILE="" + +# ----------------------------- +# Parse remaining arguments +# ----------------------------- +while [[ $# -gt 0 ]]; do + case "$1" in + --tab) OPEN_MODE="tab"; shift ;; + --vsplit) OPEN_MODE="vsplit"; shift ;; + +[0-9]*) LINE="${1#+}"; shift ;; + *) FILE="$1"; shift ;; + esac +done + +[ -z "$FILE" ] && exit 0 + +# ----------------------------- +# Open file in Neovim or jump to buffer +# ----------------------------- +if $NVR --servername "$SOCKET" --remote-expr \ + "bufexists(fnamemodify('$FILE', ':p'))" | grep -q 1; then + CMD=":buffer $(basename "$FILE")" +else + case "$OPEN_MODE" in + window) CMD=":e $FILE" ;; + tab) CMD=":tabedit $FILE" ;; + vsplit) CMD=":vsplit $FILE" ;; + esac +fi + +[ -n "$LINE" ] && CMD="$CMD | call cursor($LINE,1)" +CMD="$CMD | normal! zz" + +$NVR --servername "$SOCKET" --remote-send "${CMD}" + +# ----------------------------- +# Focus GUI terminal (Hyprland) +# ----------------------------- +hyprctl dispatch focuswindow class:$GODOT_TERMINAL +