Skip to content

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

Closed
wants to merge 5 commits into from

Conversation

ricardojlrufino
Copy link
Contributor

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 ) ?

@mastrolinux mastrolinux added the in progress Work on this item is in progress label Apr 29, 2017
@facchinm
Copy link
Member

facchinm commented May 2, 2017

@ArduinoBot build this please

@tigoe
Copy link
Member

tigoe commented May 3, 2017

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?

@cmaglie
Copy link
Member

cmaglie commented May 3, 2017

@tigoe
this PR is aimed to do the only the GUI part first, so the popup is not populated with actual code-completions but with some placeholders. @ricardojlrufino made this after my request here #849, because his first submission of a full implementation of autocomplete (here #3484) is way too complex to handle all at once and touch many aspects of the IDE that are unrelated with the autocompletion.

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.

@tigoe
Copy link
Member

tigoe commented May 3, 2017

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.

Copy link
Member

@cmaglie cmaglie left a 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"/>
Copy link
Member

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{
Copy link
Member

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());
Copy link
Member

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() {
Copy link
Member

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).

@ricardojlrufino
Copy link
Contributor Author

@cmaglie My idea was to follow their guidelines, to have a cleaner interface.
But in fact, I think it's best to use what we already have ...

Is this the autocomplete library here?
https://github.com/bobbylight/AutoComplete

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.
These changes could be made in the bobbylight / AutoComplete project, I believe. I could try doing them (although I'm not an OSX user .. =])

@tigoe
Copy link
Member

tigoe commented May 3, 2017

OK. When you're dealing with the visual/usability, I'll pay attention again, because that is the most important aspect to me.

@ricardojlrufino
Copy link
Contributor Author

ricardojlrufino commented May 4, 2017

@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:
https://github.com/OpenDevice/Arduino/blob/1.6.5-autocomplete/arduino-autocomplete/src/cc/arduino/packages/autocomplete/SketchCompletionProvider.java
https://github.com/OpenDevice/Arduino/blob/1.6.5-autocomplete/arduino-autocomplete/src/cc/arduino/packages/autocomplete/CompletionProviderWithContext.java

@ricardojlrufino
Copy link
Contributor Author

Hi, @cmaglie. Did you have time to do the review?

Copy link
Member

@cmaglie cmaglie left a 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])
Copy link
Member

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());
Copy link
Member

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).

@ricardojlrufino
Copy link
Contributor Author

Hi @cmaglie , I followed your suggestions, what's the next step?

@ricardojlrufino
Copy link
Contributor Author

@cmaglie PING ! =)

@facchinm facchinm mentioned this pull request Nov 13, 2017
@facchinm
Copy link
Member

The relevant bits of this PR has been merged in beta-1.9 branch, closing as merged

@facchinm facchinm closed this Nov 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in progress Work on this item is in progress
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants