-
-
Notifications
You must be signed in to change notification settings - Fork 7k
Base implementation of autocomplete #849 #6235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
bfedcba
5d64faf
dff2e32
665ac88
349827a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package cc.arduino.autocomplete; | ||
|
||
import org.fife.ui.autocomplete.CompletionProvider; | ||
|
||
import processing.app.Sketch; | ||
import processing.app.syntax.SketchTextArea; | ||
|
||
public class CompletionContext { | ||
|
||
private Sketch sketch; | ||
|
||
private SketchTextArea textArea; | ||
|
||
private CompletionProvider delegate; // of: AutoComplete/RSyntaxTextArea | ||
|
||
public CompletionContext(Sketch sketch, SketchTextArea textArea,CompletionProvider delegate) { | ||
this.sketch = sketch; | ||
this.textArea = textArea; | ||
this.delegate = delegate; | ||
} | ||
|
||
|
||
public String getAlreadyEnteredText() { | ||
return delegate.getAlreadyEnteredText(textArea); | ||
} | ||
|
||
public int getLineNumber() { | ||
return textArea.getCaretLineNumber(); | ||
} | ||
|
||
|
||
public Sketch getSketch() { | ||
return sketch; | ||
} | ||
|
||
public SketchTextArea getTextArea() { | ||
return textArea; | ||
} | ||
|
||
public CompletionProvider getDelegate() { | ||
return delegate; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package cc.arduino.autocomplete; | ||
|
||
import java.util.List; | ||
|
||
import org.fife.ui.autocomplete.Completion; | ||
|
||
public interface CompletionProvider { | ||
|
||
List<Completion> getSuggestions(CompletionContext context); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package cc.arduino.autocomplete; | ||
|
||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
import org.fife.ui.autocomplete.BasicCompletion; | ||
import org.fife.ui.autocomplete.Completion; | ||
|
||
public class FakeCompletionProvider implements CompletionProvider { | ||
|
||
|
||
@Override | ||
public List<Completion> getSuggestions(CompletionContext context) { | ||
List<Completion> list = new LinkedList<>(); | ||
list.add(new BasicCompletion(context.getDelegate(), "Text: " + context.getAlreadyEnteredText())); | ||
list.add(new BasicCompletion(context.getDelegate(), "Line: " + context.getLineNumber())); | ||
|
||
return list; | ||
} | ||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package cc.arduino.autocomplete.rsyntax; | ||
|
||
import java.util.List; | ||
|
||
import javax.swing.text.JTextComponent; | ||
|
||
import org.fife.ui.autocomplete.Completion; | ||
import org.fife.ui.autocomplete.DefaultCompletionProvider; | ||
|
||
import cc.arduino.autocomplete.CompletionContext; | ||
import cc.arduino.autocomplete.CompletionProvider; | ||
|
||
public class CompletionProviderBridge extends DefaultCompletionProvider{ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So, it seems that rsyntaxtextarea's autocomplete.jar already has a CompletionProvider, I didn't know that, having a |
||
|
||
private CompletionProvider provider; | ||
|
||
private CompletionContext context; | ||
|
||
public CompletionProviderBridge(CompletionContext context, CompletionProvider provider) { | ||
this.provider = provider; | ||
this.context = context; | ||
} | ||
|
||
|
||
@Override | ||
public List<Completion> getCompletionsImpl(JTextComponent comp) { | ||
return provider.getSuggestions(context); | ||
|
||
} | ||
|
||
@Override | ||
protected boolean isValidChar(char ch) { | ||
return super.isValidChar(ch) || '.' == ch || '>' == ch || '-' == ch || '<' == ch || '#' == ch || ':' == ch /**|| getParameterListStart() == ch */; | ||
} | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package cc.arduino.autocomplete.rsyntax; | ||
|
||
import org.fife.ui.autocomplete.LanguageAwareCompletionProvider; | ||
|
||
import cc.arduino.autocomplete.CompletionContext; | ||
import cc.arduino.autocomplete.CompletionProvider; | ||
import processing.app.Sketch; | ||
import processing.app.syntax.SketchTextArea; | ||
|
||
|
||
/** | ||
* CompletionProvider for Arduino/CPP Language. <br/> | ||
* Setup basic logic for completions using {@link LanguageAwareCompletionProvider} | ||
* Filtering and decision will appear in the autocomplete dialog by implementations of: {@link CompletionProvider}. <br/> | ||
* | ||
* @author Ricardo JL Rufino ([email protected]) | ||
* @date 28/04/2017 | ||
*/ | ||
public class SketchCompletionProvider extends LanguageAwareCompletionProvider{ | ||
|
||
public SketchCompletionProvider(Sketch sketch, SketchTextArea textArea, CompletionProvider provider) { | ||
|
||
CompletionContext context = new CompletionContext(sketch, textArea, this); | ||
|
||
setDefaultCompletionProvider(new CompletionProviderBridge(context, provider)); | ||
// provider.setParameterChoicesProvider(new ParameterChoicesProvider(this)); | ||
// provider.setParameterizedCompletionParams('(', ", ", ')'); | ||
|
||
} | ||
|
||
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -54,6 +54,7 @@ | |
import org.fife.ui.rtextarea.RTextScrollPane; | ||
|
||
import cc.arduino.UpdatableBoardsLibsFakeURLsHandler; | ||
import cc.arduino.autocomplete.FakeCompletionProvider; | ||
import processing.app.helpers.DocumentTextChangeListener; | ||
import processing.app.syntax.ArduinoTokenMakerFactory; | ||
import processing.app.syntax.PdeKeywords; | ||
|
@@ -106,6 +107,8 @@ public EditorTab(Editor editor, SketchFile file, String contents) | |
file.setStorage(this); | ||
applyPreferences(); | ||
add(scrollPane, BorderLayout.CENTER); | ||
|
||
textarea.setupAutoComplete(file.getSketch(), new FakeCompletionProvider()); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you inline this call and remove You can also use |
||
} | ||
|
||
private RSyntaxDocument createDocument(String contents) { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -246,6 +246,10 @@ public boolean isModified() { | |
public boolean equals(Object o) { | ||
return (o instanceof SketchFile) && file.equals(((SketchFile) o).file); | ||
} | ||
|
||
public Sketch getSketch() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This method can be removed see my previous comment (it may turns out to be useful in the future but I'd like to avoid adding it until really necessary). |
||
return sketch; | ||
} | ||
|
||
/** | ||
* Load this piece of code from a file and return the contents. This | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is this the autocomplete library here?
https://github.com/bobbylight/AutoComplete
where did you found the jar?
I think that the launchers for Windows must be updated too:
build/windows/launcher/config.xml
build/windows/launcher/config_debug.xml