macvim-dev / macvim-dev/macvim

Feature Request: detect and reuse MacVim instance to open file by mvim:// url

オープン
#1,402 コメント 7 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Vim Script
スター
7.9k
フォーク
691
PR マージ指標
30日以内にマージされた PR はありません

説明

Greeting!

I configure mvim:// in React Developer Tools to open file in MacVim from the browser extension.

mvim://open?url=file://{path}&line={line}
image

It works good, but there's a small issue. The issue is that MacVim doesn't reuse the instance that I opened if the target file hasn't been opened. For example, I launch MacVim from /path/to/my-project, and I open files /path/to/my-project/{a,b,c}.js from React Developer Tools. They have different results:

file is editing or has been opened result
a.js editing 😃 get opened in the right instance
b.js has been opened 😃 ditto
c.js neither 💔 get opened in a new instance

I hope the c.js can be opened like a.js and b.js.

I have a workaround in favor of Raycast Script Command deeplinks. My script launch MacVim with specified servername, the launched instance will be reuse if I execute the script again. Here it is (I have multiple ones generated by another script):

#!/bin/bash

# Required parameters:
# @raycast.schemaVersion 1
# @raycast.title Vim Launch
# @raycast.mode silent
# Optional parameters:
# @raycast.icon ✅
# @raycast.packageName vim-launch
# @raycast.argument1 { "type": "text", "placeholder": "file path", "optional": true }
# @raycast.argument2 { "type": "text", "placeholder": "line number", "optional": true }

# Documentation:
# @raycast.description Open vim startify session

export PATH=/Applications/MacVim.app/Contents/bin:$PATH

open_file()
{
    if [[ -n $1 ]]; then
      mvim --servername THE_SERVER_NAME --remote-send "<c-w>:tabedit $1<CR>"
    fi
    if [[ -n $2 ]]; then
      mvim --servername THE_SERVER_NAME --remote-send "$2G"
    fi
}

SERVERS=`mvim --serverlist | grep -i THE_SERVER_NAME | awk '{print tolower($0)}'`
for server in $SERVERS; do
  if [[ $server == "THE_SERVER_NAME" ]];
  then
    osascript >/dev/null <<END
      tell application "System Events" to tell process "MacVim"
        set frontmost to true
        windows where title ends with "THE_SERVER_NAME"
        if result is not {} then perform action "AXRaise" of item 1 of result
      end tell
END
    open_file $1 $2
    exit 0
  fi
done

LANG=en_US.UTF-8 mvim --servername THE_SERVER_NAME +SLoad\ THE_SERVER_NAME >/dev/null 2>&1
# wait for server registration
sleep 1
open_file $1 $2

With this script, I replace mvim:// url with Raycast's deeplink:

raycast://script-commands/vim-launch?arguments={path}&arguments={line}

It's fixed! However it would be better to have native support in MacVim.

I would suggestion to add feature to detect the instance I want to open file with (like if the opening file path is in the working directory of an instance, the closest one), or add another parameter to specified the instance.

Thanks!

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

この issue では MacVim の mvim:// URL 処理とインスタンス/サーバーの選択について述べられていますが、ソースファイルやテストは示されていません。まず、URL のエントリポイントと、既存の MacVim インスタンスを選択するロジックを探します。未オープンのファイルが適切な既存インスタンスを再利用でき、報告された a.js、b.js、c.js のケースをカバーできれば完了です。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
bash, macos, vim
領域
desktop
issue の種類
機能追加
難易度
5/5
見積もり時間
1週間以上
活発さ
停滞
明瞭さ
おおむね明確
初心者へのやさしさ
30/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。