ebresie commented on a change in pull request #2820:
URL: https://github.com/apache/netbeans/pull/2820#discussion_r598307074
##########
File path:
ide/db.sql.editor/src/org/netbeans/modules/db/sql/editor/completion/SQLCompletionProvider.java
##########
@@ -41,42 +57,190 @@
* @author Andrei Badea
*/
public class SQLCompletionProvider implements CompletionProvider {
+ private static final String SQL_CONNECTION_HINT_ID = "sql_connection_hint";
+ private String selection;
+ private static JTextComponent component = null;
+ private static DatabaseConnection dbconn = null;
+ @Override
public CompletionTask createTask(int queryType, JTextComponent component) {
- if (queryType == CompletionProvider.COMPLETION_QUERY_TYPE || queryType
== CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
+ if (queryType == CompletionProvider.COMPLETION_QUERY_TYPE ||
+ queryType == CompletionProvider.COMPLETION_ALL_QUERY_TYPE) {
+
+ /* to support DB related completion tasks (i.e. auto populating
table
+ names or db columns for given schema) check for connection */
DatabaseConnection dbconn = findDBConn(component);
- if (dbconn == null) {
- // XXX perhaps should have an item in the completion instead?
- Completion.get().hideAll();
- SQLExecutionBaseAction.notifyNoDatabaseConnection();
- return null;
+ // No database connection set or active
+ if (SQLCompletionProvider.dbconn == null) {
+ createSuggestions(component,dbconn);
}
+
return new AsyncCompletionTask(new SQLCompletionQuery(dbconn),
component);
}
+
+ // not a completion query type so return nothing
return null;
}
+ /**
+ * getAutoQueryTypes is invoked to check whether a popup with suggestions
+ * should be shown without the user explicitly asking for it.
+ *
+ * If either #getAutoQueryTypes return a non-zero value or the user
+ * explicitly asks for completion, #createTask is invoked with the
+ * requested type. In case of SQL see
+ * org.netbeans.modules.db.sql.editor.completion.SQLCompletionQuery.
+ *
+ * @param component
+ * @param typedText
+ * @return
+ */
public int getAutoQueryTypes(JTextComponent component, String typedText) {
+ /* TODO: Need to check "enable/disable" autocomplete is setting.
+ See NETBEANS-188 */
+
+ // If "." has not been typed then acceptable to start checking for
options.
if (!".".equals(typedText)) { // NOI18N
return 0;
}
+ // check typed text if dot is present at the selected offset
if (!isDotAtOffset(component, component.getSelectionStart() - 1)) {
return 0;
}
+
+// List<Fix> fixes = new ArrayList<>(Collections.emptyList());
+// Document doc = component.getDocument();
+// List<ErrorDescription> warnings = new
ArrayList<>(Collections.emptyList());
Review comment:
I thought I had removed those but must have missed some cases. Will
correct.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
For further information about the NetBeans mailing lists, visit:
https://cwiki.apache.org/confluence/display/NETBEANS/Mailing+lists