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 の Content Assist は、エディタの「補完ポップアップ」を管理する仕組みです。 === なるほどです。順を追って具体的に説明します。Eclipse の Content Assist は、エディタの「補完ポップアップ」を管理する仕組みです。 ここで必要なのは、AISuggestHandler が AI の提案を取得 → SourceViewerConfiguration を介してポップアップ表示 → Tab で採用、という流れです。 ==== - Eclipse のテキストエディタ(JDT JavaEditor など)が持つ設定クラス ==== * 補完や色分けなどの機能を提供 * Content Assist(補完) もここで管理されます 例: <syntaxhighlight lang="java">import org.eclipse.jface.text.source.SourceViewerConfiguration; import org.eclipse.jface.text.contentassist.IContentAssistProcessor; public class AISourceViewerConfig extends SourceViewerConfiguration { private String aiText; public AISourceViewerConfig(String aiText) { this.aiText = aiText; } @Override public IContentAssistProcessor getContentAssistProcessor(String contentType) { return new AIAssistProcessor(aiText); // Tab で採用可能な提案を返す } } </syntaxhighlight> ポイント: * contentType は "java" などの文字種別 * getContentAssistProcessor で返すのが 補完の処理クラス * ここでは先ほど作った AIAssistProcessor を返す ==== - AI から取得した文字列を CompletionProposal に変換する ==== * Eclipse はこの提案をポップアップで表示 * Tab キーで採用するとカーソル位置に挿入される <syntaxhighlight lang="java">public ICompletionProposal[] computeCompletionProposals(ITextViewer viewer, int offset) { ICompletionProposal proposal = new CompletionProposal( aiSuggestion, // AI からの文字列 offset, // 挿入位置 0, // 置換文字数 aiSuggestion.length(), null, "AI Suggestion", null, null ); return new ICompletionProposal[]{ proposal }; } </syntaxhighlight> ==== - SourceViewerConfiguration に設定した Content Assist は ContentAssistant 経由で呼び出されます ==== * AISuggestHandler から呼ぶ場合は、次のようにします(簡易例): <syntaxhighlight lang="java">ITextEditor editor = (ITextEditor) HandlerUtil.getActiveEditor(event); ITextViewer viewer = (ITextViewer) editor.getAdapter(ITextViewer.class); ContentAssistant assistant = new ContentAssistant(); assistant.setContentAssistProcessor(new AIAssistProcessor(aiText), IDocument.DEFAULT_CONTENT_TYPE); assistant.install(viewer); assistant.showPossibleCompletions(); // これでポップアップ表示 </syntaxhighlight> * Tab を押すと、提案内容がカーソル位置に挿入される ==== 1. Ctrl+Shift+Z → AISuggestHandler が AI にリクエスト ==== # AI からコード取得 → extractCodeFromAIResponse でクリーン化 # SourceViewerConfiguration で AIAssistProcessor を返す # ContentAssistant.showPossibleCompletions() でポップアップ表示 # ユーザーが Tab を押すと提案が挿入される 💡 注意点 * この方法では AI 提案をポップアップ表示するまで は AISuggestHandler が管理 * 実務では 既存の JavaEditor/SourceViewer に組み込む形 が望ましい * 「Tab キーで採用」は CompletionProposal の標準動作 です もし希望であれば、私は AISuggestHandler と SourceViewerConfiguration + ContentAssistant を統合して Ctrl+Shift+Z → ポップアップ表示 → Tab で採用可能な完全サンプルコード を作ることもできます。 作りますか?
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)