-
-
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
Conversation
@ArduinoBot build this please |
✅ Build completed. Please test this code using one of the following: ⬇️ http://downloads.arduino.cc/javaide/pull_requests/arduino-PR-6235-BUILD-690-linux32.tar.xz ℹ️ The |
I find this confusing, and couldn't get it to autocomplete. When i press control-space (an unusual key combo for OSX users), I get a popup box that interrupts my typing, and when I dismiss it with the enter key, it puts the line number in my code. What I assumed when I saw "autocomplete" was something like what Atom (https://atom.io/) or Coda (https://panic.com/coda/) do: when the editor knows the context from the file type (e.g. .html, .js) it auto-completes from keywords when you tab or hit enter, there's no additional popup box, but there is a very small hovering text tip that doesn't block your view, which you can turn on or off.. It's not invasive, you can ignore it if you choose, or you can complete it with one keystroke. To me, that is what I would expect in an auto-complete. I don't see how that relates to what this is doing. Can you explain further what you're intent is? |
@tigoe So this is a try to go with an incremental approach, once done the GUI part we can focus on the code-completion engine that will be the tricky part to get right. |
I see, thank you for the explanation. In which case, my thoughts on the GUI are as follows: the popup window is too big and invasive. I would do something smaller, that takes less screen real estate. And the key combination is uncomfortable for OSX users. If it requires a command-key combo, I would use control as the modifier on windows and Linux, but command as the modifier on OSX, as is standard. Though ideally, I would not require a modifier except to turn the mode on or off; I'd use enter or tab. like other auto-corrects do. |
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.
Hi @ricardojlrufino,
thanks for the submission!
I've added some inline comments, I didn't know that rsyntaxtextarea already has a CompletionProvider object model, I think that we can use directly that instead to provide our own copy. FakeCompletionProvider
may directly extend LanguageAwareCompletionProvider
as SketchCompletionProvider
already do.
Also all the "Context" passing looks a bit redundant at this point, probably we only need to keep a reference to the SketchTextArea but this can be a field of the SketchCompletionProvider
.
@@ -44,6 +43,7 @@ | |||
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/> | |||
<classpathentry kind="lib" path="lib/jssc-2.8.0.jar"/> | |||
<classpathentry kind="lib" path="lib/rsyntaxtextarea-2.6.1.jar"/> | |||
<classpathentry kind="lib" path="lib/autocomplete-2.6.1.jar" sourcepath="/media/ricardo/Dados/Workspace/Arduino/arduino-dep/AutoComplete-2.6.1"/> |
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
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 comment
The 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 cc.arduino.CompletionProvider
is any useful? maybe we could use directly the rsyntax version instead of making our own and a Bridge class between the two?
Also the cc.arduino.CompletionContext
class looks like useless boilerplate code now.
@@ -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 comment
The reason will be displayed to describe this comment to others. Learn more.
can you inline this call and remove setupAutoComplete
from SketchTextArea
?
Doesn't seems to be any useful to have a SketchCompletionProvider
reference in SketchTextArea
.
You can also use editor.getSketch()
instead of file.getSketch()
and remove the getSketch()
method from FileSketch.
@@ -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 comment
The 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).
@cmaglie My idea was to follow their guidelines, to have a cleaner interface.
YES @tigoe In that first moment, I find it interesting to focus on the functional aspects. The visual part and usability can have its specific moment. |
OK. When you're dealing with the visual/usability, I'll pay attention again, because that is the most important aspect to me. |
@cmaglie Now, basically, there have been two classes ... SketchCompletionProvider, is the basis for providing autocomplete services for various contexts: Code, Strings, documentation. Specifically the 'code' that is what interests us at that moment, will be offered by classses that extend: BaseCCompletionProvider Currently the two classes do not have much, but they will be necessary as we implement new functionalities. For reference, look at my previous code: |
Hi, @cmaglie. Did you have time to do the review? |
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.
Hi @ricardojlrufino sorry for the delay,
I just added two simple nitpicks so we can merge this PR and focus on the functionality, we can continue the discussion on #849
|
||
/** | ||
* Base completion provider for C/C++. | ||
* @author Ricardo JL Rufino ([email protected]) |
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.
May you add a GNU GPL license on top of all the files and move the credits there?
You can copy the header from any of the other files.
@@ -106,6 +107,8 @@ public EditorTab(Editor editor, SketchFile file, String contents) | |||
file.setStorage(this); | |||
applyPreferences(); | |||
add(scrollPane, BorderLayout.CENTER); | |||
|
|||
textarea.setupAutoComplete(editor.getSketch(), new FakeCompletionProvider()); |
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.
Ok some thoughts about this:
-
this call could be commented out, so we can merge this PR without affecting the IDE behavior for now.
-
what about adding a method like
Editor.setAutocompletionProvider(CompletionProvider)
? this way we can implement the completion-engine into a tool... -
moreover I think that this call can be inlined (and the method
textarea.setupAutoComplete
removed).
Hi @cmaglie , I followed your suggestions, what's the next step? |
@cmaglie PING ! =) |
✅ Build completed. Please test this code using one of the following: ⬇️ http://downloads.arduino.cc/javaide/pull_requests/arduino-PR-6235-BUILD-720-linux32.tar.xz ℹ️ The |
The relevant bits of this PR has been merged in beta-1.9 branch, closing as merged |
Start with the minimum base for autocomplete support.
The functionality is initialized with the key: Ctrl + Space
A test class has been created: FakeCompletionProvider, to enable usability testing on other platforms
Implementation can be added through the class extension:
Cc.arduino.autocomplete.CompletionProvider
Tests:
[X] Ubuntu 16.04 64
TODO:
[ ] Discovery of implementations (using preferences or using Java SPI ) ?