[anjuta] language-support-vala: use code completion preferences from -cpp-java
- From: Johannes Schmid <jhs src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [anjuta] language-support-vala: use code completion preferences from -cpp-java
- Date: Tue, 17 Aug 2010 17:44:29 +0000 (UTC)
commit 7bd73c8349b59732eb877dc487688e2d4c18b442
Author: Abderrahim Kitouni <a kitouni gmail com>
Date: Wed Aug 11 09:23:49 2010 +0100
language-support-vala: use code completion preferences from -cpp-java
.../anjuta-language-cpp-java.ui | 2 +-
plugins/language-support-vala/plugin.vala | 12 +++---
plugins/language-support-vala/provider.vala | 44 +++++++++++++++++++-
3 files changed, 49 insertions(+), 9 deletions(-)
---
diff --git a/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui b/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
index 8d647c1..54be1de 100644
--- a/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
+++ b/plugins/language-support-cpp-java/anjuta-language-cpp-java.ui
@@ -385,7 +385,7 @@
<property name="visible">True</property>
<property name="xalign">0</property>
<property name="yalign">0</property>
- <property name="label" translatable="yes">Autocompletion (C/C++/Java only)</property>
+ <property name="label" translatable="yes">Autocompletion</property>
<attributes>
<attribute name="weight" value="bold"/>
</attributes>
diff --git a/plugins/language-support-vala/plugin.vala b/plugins/language-support-vala/plugin.vala
index 3c12635..c941187 100644
--- a/plugins/language-support-vala/plugin.vala
+++ b/plugins/language-support-vala/plugin.vala
@@ -20,6 +20,7 @@ using Anjuta;
public class ValaPlugin : Plugin {
internal weak IAnjuta.Editor current_editor;
+ internal Anjuta.Preferences prefs;
uint editor_watch_id;
Vala.CodeContext context;
@@ -42,6 +43,7 @@ public class ValaPlugin : Plugin {
context.report = report;
context.profile = Vala.Profile.GOBJECT;
+ prefs = shell.get_preferences ();
var project = (IAnjuta.ProjectManager) shell.get_object("IAnjutaProjectManager");
weak List<string> packages = project.get_packages();
add_package(context, "glib-2.0");
@@ -172,13 +174,11 @@ public class ValaPlugin : Plugin {
}
public void on_char_added (IAnjuta.EditorTip editor, Object position, char ch) {
- var current_position = (IAnjuta.Iterable) position;
- /* include the just added char */
- current_position.next ();
+ if (!prefs.get_bool_with_default (ValaProvider.PREF_CALLTIP_ENABLE, true))
+ return;
+
if (ch == '(') {
- var line_start = editor.get_line_begin_position(current_editor.get_lineno());
- var current_text = editor.get_text(line_start, current_position);
- provider.show_call_tip (editor, current_text);
+ provider.show_call_tip (editor);
} else if (ch == ')') {
editor.cancel ();
}
diff --git a/plugins/language-support-vala/provider.vala b/plugins/language-support-vala/provider.vala
index 34c70b7..4df90f3 100644
--- a/plugins/language-support-vala/provider.vala
+++ b/plugins/language-support-vala/provider.vala
@@ -23,6 +23,11 @@ public class ValaProvider : Object, IAnjuta.Provider {
static Regex member_access_split;
static Regex function_call;
+ const string PREF_AUTOCOMPLETE_ENABLE = "language.cpp.code.completion.enable";
+ const string PREF_SPACE_AFTER_FUNC = "language.cpp.code.completion.space.after.func";
+ const string PREF_BRACE_AFTER_FUNC = "language.cpp.code.completion.brace.after.func";
+ const string PREF_CALLTIP_ENABLE = "language.cpp.code.calltip.enable";
+
static construct {
try {
member_access = new Regex("""((?:\w+(?:\s*\([^()]*\))?\.)*)(\w*)$""");
@@ -40,6 +45,9 @@ public class ValaProvider : Object, IAnjuta.Provider {
return "Vala";
}
public void populate (IAnjuta.Iterable iter) throws GLib.Error {
+ if (!plugin.prefs.get_bool_with_default (PREF_AUTOCOMPLETE_ENABLE, true))
+ return;
+
var editor = plugin.current_editor as IAnjuta.EditorAssist;
var line_start = editor.get_line_begin_position(editor.get_lineno());
var current_text = editor.get_text(line_start, iter);
@@ -78,13 +86,45 @@ public class ValaProvider : Object, IAnjuta.Provider {
public void activate (IAnjuta.Iterable iter, void* data) {
var sym = data as Vala.Symbol;
var editor = plugin.current_editor as IAnjuta.EditorAssist;
+ var assist = sym.name;
+ var is_func = false;
+ var calltip = false;
+
+ if (sym is Vala.Method || sym is Vala.Signal) {
+ is_func = true;
+ } else if (sym is Vala.Variable) {
+ if (((Vala.Variable) sym).variable_type is Vala.DelegateType) {
+ is_func = true;
+ }
+ }
+
+ if (is_func) {
+ if (plugin.prefs.get_bool_with_default (PREF_SPACE_AFTER_FUNC, true)) {
+ assist += " ";
+ }
+ if (plugin.prefs.get_bool_with_default (PREF_BRACE_AFTER_FUNC, true)) {
+ assist += "(";
+ if (plugin.prefs.get_bool_with_default (PREF_CALLTIP_ENABLE, true)) {
+ calltip = true;
+ }
+ }
+ }
+
(editor as IAnjuta.Document).begin_undo_action();
editor.erase(start_pos, iter);
- editor.insert(start_pos, sym.name, -1);
+ editor.insert(start_pos, assist, -1);
(editor as IAnjuta.Document).end_undo_action();
+
+ if (calltip && editor is IAnjuta.EditorTip) {
+ show_call_tip ((IAnjuta.EditorTip) editor);
+ }
}
- public void show_call_tip (IAnjuta.EditorTip editor, string to_complete) {
+ public void show_call_tip (IAnjuta.EditorTip editor) {
+ var current_position = editor.get_position ();
+ var line_start = editor.get_line_begin_position(editor.get_lineno());
+ var to_complete = editor.get_text(line_start, current_position);
+
List<string> tips = null;
MatchInfo match_info;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]