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!
==== 現状の lastIndexOf("final") は不要です。AI の返答に final が含まれない場合、余計な切り取りが発生するので削除します。 ==== <syntaxhighlight lang="java">private String extractCodeFromAIResponse(String response) { // 不要な制御トークン(<|…|>)を削除 String cleaned = response.replaceAll("<\\|.*?\\|>", ""); // Markdownコードブロック(</syntaxhighlight>java や ``<code>)を削除 cleaned = cleaned.replaceAll("(?m)^</code>`<code>.*$", ""); cleaned = cleaned.replaceAll("</code>`<code>", ""); // 前後空白を削除 return cleaned.trim(); } <syntaxhighlight> ✅ 修正理由:final に依存せず、純粋にコードだけ抽出する ==== - すでにコメントアウト済みですが、直接挿入はせず、CompletionProposal で提案するようにします。 ==== </syntaxhighlight>java // document.replace(cursorOffset, 0, aiText); // 直接挿入は不要 <syntaxhighlight> ==== この部分は既に完成しています。 ==== </syntaxhighlight>java ICompletionProposal proposal = new CompletionProposal( aiText, // 挿入文字列 cursorOffset, // 挿入位置 0, // 置換文字数 aiText.length(), // カーソル移動位置 null, // 画像(アイコン) "AI Suggestion", // 表示文字列 null, null ); <syntaxhighlight> * Tab で採用可能 * aiText.length() によりカーソルが挿入後の末尾に移動 ==== ここが追加で必要な部分です。AISuggestHandler だけではポップアップが出ません。 ==== ===== 1. エディタの SourceViewerConfiguration を拡張 ===== # getContentAssistProcessor(String contentType) で AIAssistProcessor を返す </syntaxhighlight>java @Override public IContentAssistProcessor getContentAssistProcessor(String contentType) { return new AIAssistProcessor(aiText); // AI から取得した文字列を渡す } <syntaxhighlight> * AIAssistProcessor は先ほど作成済みのクラス * Tab キーで提案を採用できる ==== 1. Ctrl+Shift+Z → AISuggestHandler が AI にリクエスト ==== # AI の返答を extractCodeFromAIResponse でクリーン化 # AIAssistProcessor に渡す # SourceViewerConfiguration 経由で Content Assist を呼び出す # ポップアップ表示 → Tab で採用 </syntaxhighlight>java // SourceViewerConfiguration 内で IContentAssistProcessor processor = new AIAssistProcessor(aiText); contentAssistant.setContentAssistProcessor(processor, IDocument.DEFAULT_CONTENT_TYPE); contentAssistant.showPossibleCompletions(); </code>`` ===== - extractCodeFromAIResponse から final 処理を削除 ===== * document.replace は直接挿入せずコメントアウト * CompletionProposal はそのままで OK * Content Assist 表示は SourceViewerConfiguration + AIAssistProcessor で行う もし希望であれば、私は AISuggestHandler と AIAssistProcessor を統合して Ctrl+Shift+Z → Content Assist ポップアップ → 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)