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!
==== Eclipse の標準補完 UI を再利用すると、ユーザーに馴染みやすく、Tabで受理しやすい。簡単な ICompletionProposal 実装例: ==== <syntaxhighlight lang="java">public class AICompletionProposal implements ICompletionProposal { private final String replacement; private final int offset; private final int length; private final ITextEditor editor; public AICompletionProposal(String replacement, int offset, int length, ITextEditor editor) { this.replacement = replacement; this.offset = offset; this.length = length; this.editor = editor; } @Override public void apply(IDocument document) { try { document.replace(offset, length, replacement); } catch (BadLocationException e) { // handle } } @Override public Point getSelection(IDocument document) { int newPos = offset + replacement.length(); return new Point(newPos, 0); } @Override public String getAdditionalProposalInfo() { return null; } @Override public String getDisplayString() { return "[AI] " + (replacement.length() > 100 ? replacement.substring(0, 100) + "..." : replacement); } @Override public Image getImage() { return null; } @Override public IContextInformation getContextInformation() { return null; } } </syntaxhighlight> 提案をポップアップするには ContentAssist フレームワークへ登録するか、簡易的には CompletionProposalPopup を自前実装して表示する。既存の ContentAssistant を使うと Tab で選択確定される設定が容易。 簡易表示フロー: * ITextViewer を取得して ICompletionProposal[] を生成。 * ContentAssistant.showPossibleCompletions() を呼ぶか、IContentAssistantExtension3.showProposalPopup()。 実例(概念): <syntaxhighlight lang="java">private void showProposal(ITextEditor editor, String suggestion, int offset) { IDocumentProvider dp = editor.getDocumentProvider(); IDocument doc = dp.getDocument(editor.getEditorInput()); AICompletionProposal p = new AICompletionProposal(suggestion, offset, 0, editor); ICompletionProposal[] proposals = new ICompletionProposal[] { p }; // シンプルに直接適用する方法(ユーザーがTabを押す仕組みを自前で実装する場合はキーリスナが必要) // もしくは ContentAssistant へ渡して標準UIで提示する(推奨)。 // 実装はプロジェクト種別・Eclipseのバージョンに合わせて調整してください。 } </syntaxhighlight>
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)