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
Closed
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion app/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
<classpathentry kind="src" path="test"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8"/>
<classpathentry combineaccessrules="false" kind="src" path="/arduino-core"/>
<classpathentry kind="output" path="bin"/>
<classpathentry kind="lib" path="lib/apple.jar"/>
<classpathentry kind="lib" path="lib/batik-1.8.jar"/>
<classpathentry kind="lib" path="lib/batik-anim-1.8.jar"/>
Expand Down Expand Up @@ -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

<classpathentry kind="lib" path="lib/xml-apis-1.3.04.jar"/>
<classpathentry kind="lib" path="lib/xml-apis-ext-1.3.04.jar"/>
<classpathentry kind="lib" path="lib/xmlgraphics-commons-2.0.jar"/>
Expand All @@ -53,4 +53,5 @@
<classpathentry kind="lib" path="test-lib/fest-swing-1.2.jar"/>
<classpathentry kind="lib" path="test-lib/fest-util-1.1.2.jar"/>
<classpathentry kind="lib" path="test-lib/jcip-annotations-1.0.jar"/>
<classpathentry kind="output" path="bin"/>
</classpath>
2 changes: 1 addition & 1 deletion app/.project
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>processing</name>
<name>app</name>
<comment></comment>
<projects>
</projects>
Expand Down
Binary file added app/lib/autocomplete-2.6.1.jar
Binary file not shown.
17 changes: 17 additions & 0 deletions app/src/cc/arduino/autocomplete/BaseCCompletionProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package cc.arduino.autocomplete;

import org.fife.ui.autocomplete.DefaultCompletionProvider;

/**
* 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.

* @date 28/04/2017
*/
public class BaseCCompletionProvider extends DefaultCompletionProvider{

@Override
protected boolean isValidChar(char ch) {
return super.isValidChar(ch) || '.' == ch || '>' == ch || '-' == ch || '<' == ch || '#' == ch || ':' == ch /**|| getParameterListStart() == ch */;
}

}
28 changes: 28 additions & 0 deletions app/src/cc/arduino/autocomplete/FakeCompletionProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package cc.arduino.autocomplete;

import java.util.LinkedList;
import java.util.List;

import javax.swing.text.JTextComponent;

import org.fife.ui.autocomplete.BasicCompletion;
import org.fife.ui.autocomplete.Completion;

import processing.app.syntax.SketchTextArea;

public class FakeCompletionProvider extends BaseCCompletionProvider {

@Override
protected List<Completion> getCompletionsImpl(JTextComponent comp) {
List<Completion> list = new LinkedList<>();

SketchTextArea area = (SketchTextArea) comp;

list.add(new BasicCompletion(this, "Text: " + getAlreadyEnteredText(comp)));
list.add(new BasicCompletion(this, "Line: " + area.getCaretLineNumber()));

return list;
}


}
27 changes: 27 additions & 0 deletions app/src/cc/arduino/autocomplete/SketchCompletionProvider.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package cc.arduino.autocomplete;

import org.fife.ui.autocomplete.CompletionProvider;
import org.fife.ui.autocomplete.LanguageAwareCompletionProvider;

import processing.app.Sketch;
import processing.app.syntax.SketchTextArea;

/**
* CompletionProvider for Arduino/CPP Language. <br/>
* Setup basic logic for completions using {@link LanguageAwareCompletionProvider}. <br/>
* 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) {

setDefaultCompletionProvider(provider);
// provider.setParameterChoicesProvider(new ParameterChoicesProvider(this));
// provider.setParameterizedCompletionParams('(', ", ", ')');

}

}
3 changes: 3 additions & 0 deletions app/src/processing/app/EditorTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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).

}

private RSyntaxDocument createDocument(String contents) {
Expand Down
66 changes: 49 additions & 17 deletions app/src/processing/app/syntax/SketchTextArea.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,12 @@

package processing.app.syntax;

import java.awt.Color;
import java.awt.Cursor;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.InputEvent;
import java.awt.event.KeyEvent;
import javax.swing.KeyStroke;
import org.apache.commons.compress.utils.IOUtils;
import org.fife.ui.rsyntaxtextarea.*;
import org.fife.ui.rsyntaxtextarea.Token;
import org.fife.ui.rtextarea.RTextArea;
import org.fife.ui.rtextarea.RTextAreaUI;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.PreferencesData;

import javax.swing.event.EventListenerList;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Segment;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.io.File;
import java.io.FileInputStream;
Expand All @@ -56,6 +44,34 @@
import java.net.URL;
import java.util.Map;
import java.util.logging.Logger;

import javax.swing.KeyStroke;
import javax.swing.event.EventListenerList;
import javax.swing.event.HyperlinkEvent;
import javax.swing.event.HyperlinkListener;
import javax.swing.text.BadLocationException;
import javax.swing.text.Segment;

import org.apache.commons.compress.utils.IOUtils;
import org.fife.ui.autocomplete.AutoCompletion;
import org.fife.ui.autocomplete.CompletionProvider;
import org.fife.ui.rsyntaxtextarea.LinkGenerator;
import org.fife.ui.rsyntaxtextarea.LinkGeneratorResult;
import org.fife.ui.rsyntaxtextarea.RSyntaxDocument;
import org.fife.ui.rsyntaxtextarea.RSyntaxTextArea;
import org.fife.ui.rsyntaxtextarea.Style;
import org.fife.ui.rsyntaxtextarea.Theme;
import org.fife.ui.rsyntaxtextarea.Token;
import org.fife.ui.rsyntaxtextarea.TokenImpl;
import org.fife.ui.rsyntaxtextarea.TokenTypes;
import org.fife.ui.rtextarea.RTextArea;
import org.fife.ui.rtextarea.RTextAreaUI;

import cc.arduino.autocomplete.SketchCompletionProvider;
import processing.app.Base;
import processing.app.BaseNoGui;
import processing.app.PreferencesData;
import processing.app.Sketch;
import processing.app.helpers.OSUtils;

/**
Expand All @@ -69,7 +85,7 @@ public class SketchTextArea extends RSyntaxTextArea {
private final static Logger LOG = Logger.getLogger(SketchTextArea.class.getName());

private PdeKeywords pdeKeywords;

public SketchTextArea(RSyntaxDocument document, PdeKeywords pdeKeywords) throws IOException {
super(document);
this.pdeKeywords = pdeKeywords;
Expand All @@ -81,6 +97,22 @@ public void setKeywords(PdeKeywords keywords) {
pdeKeywords = keywords;
setLinkGenerator(new DocLinkGenerator(pdeKeywords));
}

public void setupAutoComplete(Sketch sketch, CompletionProvider provider) {

SketchCompletionProvider completionProvider = new SketchCompletionProvider(sketch, this, provider);

AutoCompletion ac = new AutoCompletion( completionProvider );

ac.setAutoActivationEnabled(true);
ac.setShowDescWindow(false);
ac.setAutoCompleteSingleChoices(true);
ac.setParameterAssistanceEnabled(true);
// ac.setParamChoicesRenderer(new CompletionsRenderer());
// ac.setListCellRenderer(new CompletionsRenderer());
ac.install(this);

}

private void installFeatures() throws IOException {
setTheme(PreferencesData.get("editor.syntax_theme", "default"));
Expand Down
20 changes: 10 additions & 10 deletions arduino-core/.classpath
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,16 @@
<classpathentry kind="lib" path="lib/jssc-2.8.0.jar"/>
<classpathentry kind="lib" path="lib/jsch-0.1.50.jar"/>
<classpathentry kind="lib" path="lib/commons-exec-1.1.jar"/>
<classpathentry kind="lib" path="../app/lib/commons-codec-1.7.jar"/>
<classpathentry kind="lib" path="../app/lib/commons-compress-1.8.jar"/>
<classpathentry kind="lib" path="../app/lib/commons-exec-1.1.jar"/>
<classpathentry kind="lib" path="../app/lib/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="../app/lib/jackson-annotations-2.6.3.jar"/>
<classpathentry kind="lib" path="../app/lib/jackson-core-2.6.3.jar"/>
<classpathentry kind="lib" path="../app/lib/jackson-databind-2.6.3.jar"/>
<classpathentry kind="lib" path="../app/lib/jackson-module-mrbean-2.6.3.jar"/>
<classpathentry kind="lib" path="../app/lib/bcpg-jdk15on-152.jar"/>
<classpathentry kind="lib" path="../app/lib/bcprov-jdk15on-152.jar"/>
<classpathentry kind="lib" path="/app/lib/commons-codec-1.7.jar"/>
<classpathentry kind="lib" path="/app/lib/commons-compress-1.8.jar"/>
<classpathentry kind="lib" path="/app/lib/commons-exec-1.1.jar"/>
<classpathentry kind="lib" path="/app/lib/commons-httpclient-3.1.jar"/>
<classpathentry kind="lib" path="/app/lib/jackson-annotations-2.6.3.jar"/>
<classpathentry kind="lib" path="/app/lib/jackson-core-2.6.3.jar"/>
<classpathentry kind="lib" path="/app/lib/jackson-databind-2.6.3.jar"/>
<classpathentry kind="lib" path="/app/lib/jackson-module-mrbean-2.6.3.jar"/>
<classpathentry kind="lib" path="/app/lib/bcpg-jdk15on-152.jar"/>
<classpathentry kind="lib" path="/app/lib/bcprov-jdk15on-152.jar"/>
<classpathentry kind="lib" path="lib/bcpg-jdk15on-152.jar"/>
<classpathentry kind="lib" path="lib/bcprov-jdk15on-152.jar"/>
<classpathentry kind="lib" path="lib/commons-codec-1.7.jar"/>
Expand Down
2 changes: 1 addition & 1 deletion arduino-core/src/processing/app/SketchFile.java
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,7 @@ public boolean isModified() {
public boolean equals(Object o) {
return (o instanceof SketchFile) && file.equals(((SketchFile) o).file);
}

/**
* Load this piece of code from a file and return the contents. This
* completely ignores any changes in the linked storage, if any, and
Expand Down
1 change: 1 addition & 0 deletions build/windows/launcher/config.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<cp>%EXEDIR%/lib/jssc-2.8.0.jar</cp>
<cp>%EXEDIR%/lib/pde.jar</cp>
<cp>%EXEDIR%/lib/rsyntaxtextarea-2.6.1.jar</cp>
<cp>%EXEDIR%/lib/autocomplete-2.6.1.jar</cp>
<cp>%EXEDIR%/lib/xml-apis-1.3.04.jar</cp>
<cp>%EXEDIR%/lib/xml-apis-ext-1.3.04.jar</cp>
<cp>%EXEDIR%/lib/xmlgraphics-commons-2.0.jar</cp>
Expand Down
1 change: 1 addition & 0 deletions build/windows/launcher/config_debug.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<cp>%EXEDIR%/lib/jssc-2.8.0.jar</cp>
<cp>%EXEDIR%/lib/pde.jar</cp>
<cp>%EXEDIR%/lib/rsyntaxtextarea-2.6.1.jar</cp>
<cp>%EXEDIR%/lib/autocomplete-2.6.1.jar</cp>
<cp>%EXEDIR%/lib/xml-apis-1.3.04.jar</cp>
<cp>%EXEDIR%/lib/xml-apis-ext-1.3.04.jar</cp>
<cp>%EXEDIR%/lib/xmlgraphics-commons-2.0.jar</cp>
Expand Down