From fa831d06dc37f93e14f681a0348f178c4d692985 Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:13:41 +0200 Subject: [PATCH 01/10] fixed whitespace issue --- Editor/NvimScriptEditor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Editor/NvimScriptEditor.cs b/Editor/NvimScriptEditor.cs index 695106b..584003b 100644 --- a/Editor/NvimScriptEditor.cs +++ b/Editor/NvimScriptEditor.cs @@ -149,7 +149,8 @@ static string HandledExtensionsString public string ReplaceTemplate(String templateStr, String pipePath, String path, int line, int column) { templateStr = templateStr.Replace("${pipePath}", pipePath); - templateStr = templateStr.Replace("${filePath}", path); + // templateStr = templateStr.Replace("${filePath}", path); + templateStr = templateStr.Replace("${filePath}", path.Replace(" ", "\\ ")); templateStr = templateStr.Replace("${line}", Math.Max(line, 1).ToString()); templateStr = templateStr.Replace("${column}", Math.Max(column, 0).ToString()); return templateStr; From f7948a42d871b716187212681c660ee75fdcce79 Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:23:00 +0200 Subject: [PATCH 02/10] allow OSX to put Neovide front and center --- Editor/NvimScriptEditor.cs | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/Editor/NvimScriptEditor.cs b/Editor/NvimScriptEditor.cs index 584003b..076b164 100644 --- a/Editor/NvimScriptEditor.cs +++ b/Editor/NvimScriptEditor.cs @@ -313,6 +313,10 @@ public bool OpenProject(string path, int line, int column) else { // ForceForegroundWindow(process.MainWindowHandle); + if (IsOSX) + { + ActivateOSXApp(ClientCmd); + } } return true; @@ -384,6 +388,26 @@ static bool SupportsExtension(string path) return HandledExtensions.Contains(extension.TrimStart('.')); } + // Allow for OSX to put the app front and center, even when it is already running + static void ActivateOSXApp(string clientCmd) + { + // clientCmd is the CLI binary path (e.g. /opt/homebrew/bin/neovide). + // LaunchServices/AppleScript activation needs the app bundle name, not the binary path. + var appName = Path.GetFileNameWithoutExtension(clientCmd); + appName = char.ToUpper(appName[0]) + appName.Substring(1); // neovide -> Neovide + + var psi = new ProcessStartInfo + { + FileName = "osascript", + Arguments = $"-e 'tell application \"{appName}\" to activate'", + CreateNoWindow = true, + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + }; + Process.Start(psi); + } + public CodeEditor.Installation[] Installations => installations; protected static CodeEditor.Installation[] installations; From b9d6e542d46510a6a9c9368bd0bc318472638dc6 Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:26:44 +0200 Subject: [PATCH 03/10] added original author information --- package.json | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index 72fbc8f..eda7da0 100644 --- a/package.json +++ b/package.json @@ -1,8 +1,8 @@ { "name": "com.unity.nvim", "displayName": "Neovim Editor", - "description": "Code editor integration for supporting Neovim as code editor for unity. Adds support for generating csproj files for intellisense purposes, etc.", - "version": "1.2.5", + "description": "Fork of Neovim Editor by FREEZX. Code editor integration for supporting Neovim as code editor for unity. Adds support for generating csproj files for intellisense purposes, etc.", + "version": "1.3.5", "unity": "2019.2", "unityRelease": "0a12", "upmCi": { @@ -12,5 +12,9 @@ "url": "https://github.com/Unity-Technologies/com.unity.ide.vscode.git", "type": "git", "revision": "b0740c80bfc2440527c317109f7c3d9100132722" + }, + "author": { + "name": "FREEZX", + "url": "https://github.com/FREEZX/com.unity.nvim" } } From 8a641f4af9d28cde0d3df41c39891004c9b854b6 Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:32:28 +0200 Subject: [PATCH 04/10] guard against PID recycling --- Editor/NvimScriptEditor.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Editor/NvimScriptEditor.cs b/Editor/NvimScriptEditor.cs index 076b164..501aa6b 100644 --- a/Editor/NvimScriptEditor.cs +++ b/Editor/NvimScriptEditor.cs @@ -288,7 +288,8 @@ public bool OpenProject(string path, int line, int column) }; Process.Start(nvrStartInfo); - Process process = Process.GetProcesses().FirstOrDefault(x => x.Id == EditorPid); + // Guard agains PID recycling issues (when a PID is reused for another app, then the below still checks that the app getting opened is Neovide, and not something else) + Process process = Process.GetProcesses().FirstOrDefault(x => x.Id == EditorPid && x.ProcessName.IndexOf("neovide", StringComparison.OrdinalIgnoreCase) >= 0); if (process == null || process.HasExited) { From 1cf14886ce470d4471a5e84106cf4b65725cfb23 Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:34:02 +0200 Subject: [PATCH 05/10] exception if opening neovide on MacOS is not working well --- Editor/NvimScriptEditor.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/Editor/NvimScriptEditor.cs b/Editor/NvimScriptEditor.cs index 501aa6b..a5c3ae6 100644 --- a/Editor/NvimScriptEditor.cs +++ b/Editor/NvimScriptEditor.cs @@ -316,7 +316,14 @@ public bool OpenProject(string path, int line, int column) // ForceForegroundWindow(process.MainWindowHandle); if (IsOSX) { - ActivateOSXApp(ClientCmd); + try + { + ActivateOSXApp(ClientCmd); + } + catch (Exception e) + { + UnityEngine.Debug.LogWarning($"[NvimScriptEditor] Failed to activate {ClientCmd}: {e.Message}"); + } } } From 40e0939cf53cdf5d92404b59a6722d6009c9445c Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:35:33 +0200 Subject: [PATCH 06/10] Adds null/empty guards and escapes quotes in the derived app name before interpolating into the AppleScript string --- Editor/NvimScriptEditor.cs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/Editor/NvimScriptEditor.cs b/Editor/NvimScriptEditor.cs index a5c3ae6..d7544cd 100644 --- a/Editor/NvimScriptEditor.cs +++ b/Editor/NvimScriptEditor.cs @@ -399,10 +399,21 @@ static bool SupportsExtension(string path) // Allow for OSX to put the app front and center, even when it is already running static void ActivateOSXApp(string clientCmd) { + if (string.IsNullOrEmpty(clientCmd)) + { + return; + } + // clientCmd is the CLI binary path (e.g. /opt/homebrew/bin/neovide). // LaunchServices/AppleScript activation needs the app bundle name, not the binary path. var appName = Path.GetFileNameWithoutExtension(clientCmd); + if (string.IsNullOrEmpty(appName)) + { + return; + } + appName = char.ToUpper(appName[0]) + appName.Substring(1); // neovide -> Neovide + appName = appName.Replace("\"", "\\\"").Replace("'", "\\'"); // guard against quote injection var psi = new ProcessStartInfo { From 9a90df18470ec9943c7b56785eb85a789845904e Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:36:48 +0200 Subject: [PATCH 07/10] show osascript issues in Unity console for easier debugging --- Editor/NvimScriptEditor.cs | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/Editor/NvimScriptEditor.cs b/Editor/NvimScriptEditor.cs index d7544cd..6fd19ef 100644 --- a/Editor/NvimScriptEditor.cs +++ b/Editor/NvimScriptEditor.cs @@ -424,7 +424,15 @@ static void ActivateOSXApp(string clientCmd) RedirectStandardOutput = true, RedirectStandardError = true, }; - Process.Start(psi); + var proc = Process.Start(psi); + proc?.ErrorDataReceived += (sender, args) => + { + if (!string.IsNullOrEmpty(args.Data)) + { + UnityEngine.Debug.LogWarning($"[NvimScriptEditor] osascript: {args.Data}"); + } + }; + proc?.BeginErrorReadLine(); } public CodeEditor.Installation[] Installations => installations; From e295273a7037e9c86e2bd8970af3131af2f96418 Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:39:35 +0200 Subject: [PATCH 08/10] windows parity --- Editor/NvimScriptEditor.cs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/Editor/NvimScriptEditor.cs b/Editor/NvimScriptEditor.cs index 6fd19ef..b5c9ef1 100644 --- a/Editor/NvimScriptEditor.cs +++ b/Editor/NvimScriptEditor.cs @@ -149,7 +149,6 @@ static string HandledExtensionsString public string ReplaceTemplate(String templateStr, String pipePath, String path, int line, int column) { templateStr = templateStr.Replace("${pipePath}", pipePath); - // templateStr = templateStr.Replace("${filePath}", path); templateStr = templateStr.Replace("${filePath}", path.Replace(" ", "\\ ")); templateStr = templateStr.Replace("${line}", Math.Max(line, 1).ToString()); templateStr = templateStr.Replace("${column}", Math.Max(column, 0).ToString()); @@ -325,6 +324,10 @@ public bool OpenProject(string path, int line, int column) UnityEngine.Debug.LogWarning($"[NvimScriptEditor] Failed to activate {ClientCmd}: {e.Message}"); } } + else + { + ActivateWindowsApp(process); + } } return true; @@ -396,6 +399,23 @@ static bool SupportsExtension(string path) return HandledExtensions.Contains(extension.TrimStart('.')); } + +#if UNITY_EDITOR_WIN + [System.Runtime.InteropServices.DllImport("user32.dll")] + static extern bool SetForegroundWindow(IntPtr hWnd); +#endif + + // Allow windows to put app front and center + static void ActivateWindowsApp(Process process) + { +#if UNITY_EDITOR_WIN + if (process != null && process.MainWindowHandle != IntPtr.Zero) + { + SetForegroundWindow(process.MainWindowHandle); + } +#endif + } + // Allow for OSX to put the app front and center, even when it is already running static void ActivateOSXApp(string clientCmd) { From fb5b9c407f365b8d08c6fd218f186e16db95742a Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:40:49 +0200 Subject: [PATCH 09/10] adjusted description --- Editor/NvimScriptEditor.cs | 2 +- package.json | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Editor/NvimScriptEditor.cs b/Editor/NvimScriptEditor.cs index b5c9ef1..a4450cb 100644 --- a/Editor/NvimScriptEditor.cs +++ b/Editor/NvimScriptEditor.cs @@ -324,7 +324,7 @@ public bool OpenProject(string path, int line, int column) UnityEngine.Debug.LogWarning($"[NvimScriptEditor] Failed to activate {ClientCmd}: {e.Message}"); } } - else + else { ActivateWindowsApp(process); } diff --git a/package.json b/package.json index eda7da0..e714132 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "com.unity.nvim", "displayName": "Neovim Editor", - "description": "Fork of Neovim Editor by FREEZX. Code editor integration for supporting Neovim as code editor for unity. Adds support for generating csproj files for intellisense purposes, etc.", + "description": "Code editor integration for supporting Neovim as code editor for unity. Adds support for generating csproj files for intellisense purposes, etc.", "version": "1.3.5", "unity": "2019.2", "unityRelease": "0a12", From 424d2036d5656e203b9ecd45545e655b9efe29cc Mon Sep 17 00:00:00 2001 From: mrstruijk Date: Tue, 7 Jul 2026 11:44:14 +0200 Subject: [PATCH 10/10] minor bug --- Editor/NvimScriptEditor.cs | 20 +++++++++++++------- 1 file changed, 13 insertions(+), 7 deletions(-) diff --git a/Editor/NvimScriptEditor.cs b/Editor/NvimScriptEditor.cs index a4450cb..92b1b69 100644 --- a/Editor/NvimScriptEditor.cs +++ b/Editor/NvimScriptEditor.cs @@ -324,7 +324,7 @@ public bool OpenProject(string path, int line, int column) UnityEngine.Debug.LogWarning($"[NvimScriptEditor] Failed to activate {ClientCmd}: {e.Message}"); } } - else + else { ActivateWindowsApp(process); } @@ -444,15 +444,21 @@ static void ActivateOSXApp(string clientCmd) RedirectStandardOutput = true, RedirectStandardError = true, }; + var proc = Process.Start(psi); - proc?.ErrorDataReceived += (sender, args) => + + if (proc != null) { - if (!string.IsNullOrEmpty(args.Data)) + proc.ErrorDataReceived += (sender, args) => { - UnityEngine.Debug.LogWarning($"[NvimScriptEditor] osascript: {args.Data}"); - } - }; - proc?.BeginErrorReadLine(); + if (!string.IsNullOrEmpty(args.Data)) + { + UnityEngine.Debug.LogWarning($"[NvimScriptEditor] osascript: {args.Data}"); + } + }; + + proc.BeginErrorReadLine(); + } } public CodeEditor.Installation[] Installations => installations;