anjuta r4038 - in trunk: . plugins/language-support-cpp-java plugins/sourceview



Author: jhs
Date: Sat Jun 28 22:48:26 2008
New Revision: 4038
URL: http://svn.gnome.org/viewvc/anjuta?rev=4038&view=rev

Log:
2008-06-29  Johannes Schmid  <jhs gnome org>

	* plugins/language-support-cpp-java/cpp-java-assist.c
	(create_completion),
	(cpp_java_assist_create_word_completion_cache),
	(cpp_java_assist_show_autocomplete):
	* plugins/sourceview/sourceview.c (iassist_get_suggestions):
	
	#449620 â Implement autocompletion for gtksourceview editor

Modified:
   trunk/ChangeLog
   trunk/plugins/language-support-cpp-java/cpp-java-assist.c
   trunk/plugins/sourceview/sourceview.c

Modified: trunk/plugins/language-support-cpp-java/cpp-java-assist.c
==============================================================================
--- trunk/plugins/language-support-cpp-java/cpp-java-assist.c	(original)
+++ trunk/plugins/language-support-cpp-java/cpp-java-assist.c	Sat Jun 28 22:48:26 2008
@@ -173,6 +173,8 @@
 	}
 	while (ianjuta_iterable_next (iter, NULL));
 	
+	
+	
 	suggestions = g_list_sort (suggestions, completion_compare);
 	g_completion_add_items (completion, suggestions);
 	return completion;
@@ -348,6 +350,7 @@
 {
 	gint max_completions;
 	GCompletion *completion = NULL;
+	GList* editor_completions = NULL;
 	max_completions =
 		anjuta_preferences_get_int_with_default (assist->priv->preferences,
 												 PREF_AUTOCOMPLETE_CHOICES,
@@ -378,10 +381,32 @@
 	if (iter_globals)
 	{
 		DEBUG_PRINT ("cpp_java_assist_create_word_completion_cache () 2");
-		completion = create_completion (assist->priv->iassist, iter_project, completion);
+		completion = create_completion (assist->priv->iassist, iter_globals, completion);
 		g_object_unref (iter_globals);		
 	}
 	
+	editor_completions = ianjuta_editor_assist_get_suggestions (assist->priv->iassist,
+																pre_word,
+																NULL);
+	if (editor_completions)
+	{
+		GList* tag_list = NULL;
+		GList* node;
+		for (node = editor_completions; node != NULL; node = g_list_next (node))
+		{
+			CppJavaAssistTag *tag = g_new0 (CppJavaAssistTag, 1);
+			tag->name = node->data;
+			tag->type = 0;
+			tag->is_func = FALSE;
+			tag_list = g_list_append (tag_list, tag);
+		}
+		if (!completion)
+			completion = g_completion_new(completion_function);
+		tag_list = g_list_sort (tag_list, completion_compare);
+		g_completion_add_items (completion, tag_list);		
+		g_list_free (editor_completions);
+	}
+	
 	assist->priv->completion_cache = completion;
 	assist->priv->search_cache = g_strdup (pre_word);
 }
@@ -419,8 +444,7 @@
 	 */
 	else if (!pre_word)
 		completion_list = assist->priv->completion_cache->items;
-	
-	/* If there is no cache and no pre_word, it means something else (?) */
+		
 	else
 		return FALSE;
 	
@@ -458,6 +482,7 @@
 										   NULL);
 			g_list_foreach (suggestions, (GFunc) g_free, NULL);
 			g_list_free (suggestions);
+			g_object_unref (position);
 			return TRUE;
 		}
 	}

Modified: trunk/plugins/sourceview/sourceview.c
==============================================================================
--- trunk/plugins/sourceview/sourceview.c	(original)
+++ trunk/plugins/sourceview/sourceview.c	Sat Jun 28 22:48:26 2008
@@ -2000,12 +2000,42 @@
 	iface->set_language = ilanguage_set_language;
 }
 
+/* Maximal found autocompletition words */
+const gchar* AUTOCOMPLETE_REGEX = "\\s%s[\\w_*]*\\s";
 static GList*
 iassist_get_suggestions (IAnjutaEditorAssist *iassist, const gchar *context, GError **err)
 {
-	/* Sourceview* sv = ANJUTA_SOURCEVIEW(iassist); */
-	/* We don't make own suggestions yet */
-	return NULL;
+	GList* words = NULL;
+	GError* error = NULL;
+	GMatchInfo *match_info;
+	gchar* text = ianjuta_editor_get_text_all (IANJUTA_EDITOR(iassist), NULL);
+	gchar* expr = g_strdup_printf (AUTOCOMPLETE_REGEX, context);
+	GRegex* regex = g_regex_new (expr, 0, 0, &error);
+	g_free(expr);
+	
+	if (error)
+	{
+		g_regex_unref(regex);
+		g_error_free(error);
+		return NULL;
+	}
+	
+	g_regex_match (regex, text, 0, &match_info);
+	while (g_match_info_matches (match_info))
+	{
+		gchar* word = g_match_info_fetch (match_info, 0);
+		g_strstrip(word);
+		if (strlen(word) <= 3 || g_str_equal (word, context) ||
+			g_list_find_custom (words, word, (GCompareFunc)strcmp) != NULL)
+			g_free(word);
+		else
+			words = g_list_prepend (words, word);
+		g_match_info_next (match_info, NULL);
+	}
+	g_match_info_free (match_info);
+	g_regex_unref (regex);
+	
+	return words;
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]