Jump to content
Main menu
Main menu
move to sidebar
hide
Navigation
Main page
Recent changes
Random page
freem
Search
Search
Appearance
Create account
Log in
Personal tools
Create account
Log in
Pages for logged out editors
learn more
Contributions
Talk
Editing
Openai/691151cc-3da4-800f-9b7c-81b0e0d10369
(section)
Add languages
Page
Discussion
English
Read
Edit
Edit source
View history
Tools
Tools
move to sidebar
hide
Actions
Read
Edit
Edit source
View history
General
What links here
Related changes
Special pages
Page information
Appearance
move to sidebar
hide
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
=== Assistant: 完璧です! === 完璧です! ここからがプラグイン開発の「核」となる部分です。 Eclipseプラグインでは、plugin.xml に「ショートカット(キー)→コマンド→ハンドラ(Javaコード)」という連携を定義します。 以下に、AI補完用ショートカットキーを定義してハンドラを動かすまでを、順に説明します。 ==== <syntaxhighlight>[ユーザーがショートカットを押す] ==== ↓ <command> (名前とIDを定義) ↓ <handler> (実際にJavaクラスを呼び出す) ↓ ショートカット(<key>)でコマンド発火 </syntaxhighlight> ==== Ctrl+Shift+A(例)を押すと「AI補完コマンド」を実行し、AISuggestHandler.java が動くようにする。 ==== ==== 1. プロジェクトのルートにある <code>plugin.xml</code> を開く ==== # 画面下のタブで 「Extensions」 を選択 # 右上の 「Add...」 ボタンをクリック # 「Extension Point Selection」で検索欄に以下を入力: ``<code> org.eclipse.ui.commands </code>`` → これを選んで [Finish] ==== 1. 右ペインで「commands」ノードを右クリック → New → command ==== # 右側のプロパティ欄に以下を設定: | | | | --- | --- | | | | | | | | | | ==== 1. 「Extensions」タブで「Add...」をクリック ==== # 検索に「org.eclipse.ui.handlers」と入力 → [Finish] # 「handlers」ノードを右クリック → New → handler # 以下を入力: | | | | --- | --- | | | | | | | ※ このクラスはまだ存在しないので、後で作成します。 ==== 1. 「Extensions」タブで再度「Add...」→ org.eclipse.ui.bindings を選択 ==== # 「bindings」ノード → 右クリック → New → key # 以下を設定: | | | | --- | --- | | | | | | | | | | | | | | | | 💡 M1 は「Ctrl(Windows/Linux)」または「Command(Mac)」 M2 は「Shift」 つまり、M1+M2+A → Ctrl+Shift+A になります。 (例:Ctrl+Shift+AでAI補完を起動) ==== <syntaxhighlight lang="xml"><?xml version="1.0" encoding="UTF-8"?> ==== <?eclipse version="3.4"?> <plugin> <!-- コマンドの定義 --> <extension point="org.eclipse.ui.commands"> <command id="com.example.aiassist.commands.request" name="AI Suggest Request" description="Send current code to local AI and show suggestion"/> </extension> <!-- ハンドラの定義 --> <extension point="org.eclipse.ui.handlers"> <handler class="com.example.aiassist.handlers.AISuggestHandler" commandId="com.example.aiassist.commands.request"> </handler> </extension> <!-- ショートカットキー(Ctrl+Shift+A)の定義 --> <extension point="org.eclipse.ui.bindings"> <key commandId="com.example.aiassist.commands.request" contextId="org.eclipse.ui.contexts.window" schemeId="org.eclipse.ui.defaultAcceleratorConfiguration" sequence="M1+M2+A"> </key> </extension> </plugin> </syntaxhighlight> ==== 1. src/com/example/aiassist/handlers フォルダを作成 ==== # そこに新規クラス AISuggestHandler.java を作る # 内容は以下のようにします: <syntaxhighlight lang="java">package com.example.aiassist.handlers; import org.eclipse.core.commands.AbstractHandler; import org.eclipse.core.commands.ExecutionEvent; import org.eclipse.core.commands.ExecutionException; import org.eclipse.jface.dialogs.MessageDialog; import org.eclipse.ui.IWorkbenchWindow; import org.eclipse.ui.handlers.HandlerUtil; public class AISuggestHandler extends AbstractHandler { @Override public Object execute(ExecutionEvent event) throws ExecutionException { IWorkbenchWindow window = HandlerUtil.getActiveWorkbenchWindow(event); MessageDialog.openInformation( window.getShell(), "AI Suggest", "ショートカットキーが押されました!AI補完処理をここに実装します。" ); return null; } } </syntaxhighlight> ==== 1. メニューで [Run] → [Run Configurations…] → [Eclipse Application] → [New] ==== # 新規 Eclipse を起動 # 任意のエディタを開き、Ctrl+Shift+A を押す # 「AI Suggest」というダイアログが出れば成功 🎉 ==== | | | ==== | --- | --- | | | | | | | | | | ==== この後は、 ==== 🧠「AISuggestHandler」内でエディタからソースコードを取得し、AIサーバーへ送信する処理 を実装します。 つまり、今作ったショートカットをトリガーにして、AIにリクエストを飛ばす部分へ進みます。 希望があれば、次に「現在開いているソースコード全文とカーソル位置を取得する」実装部分を、次のステップとして詳しく解説しますが、進めてよいですか?
Summary:
Please note that all contributions to freem are considered to be released under the Creative Commons Attribution-ShareAlike 4.0 (see
Freem:Copyrights
for details). If you do not want your writing to be edited mercilessly and redistributed at will, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource.
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)