1 /* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 4; tab-width: 4 -*- */
3 Copyright (C) 2009 Maxim Ermilov <zaspire@rambler.ru>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <libanjuta/anjuta-shell.h>
21 #include <libanjuta/anjuta-debug.h>
22 #include <libanjuta/interfaces/ianjuta-document-manager.h>
23 #include <libanjuta/interfaces/ianjuta-editor-assist.h>
27 #include "code-completion.h"
28 #include "database-symbol.h"
33 filter_list (GList
*list
, gchar
*prefix
)
35 GList
*ret
= NULL
, *i
;
36 for (i
= list
; i
; i
= g_list_next (i
))
40 if (strncmp ((gchar
*)i
->data
, prefix
, strlen (prefix
)) == 0)
42 ret
= g_list_append (ret
, i
->data
);
49 file_completion (IAnjutaEditor
*editor
, gint
*cur_depth
)
52 IAnjutaIterable
*position
= ianjuta_editor_get_position (IANJUTA_EDITOR (editor
), NULL
);
53 int line
= ianjuta_editor_get_line_from_position (IANJUTA_EDITOR (editor
), position
, NULL
);
54 gchar
*text
= ianjuta_editor_get_text (editor
,
55 ianjuta_editor_get_start_position (editor
, NULL
),
56 ianjuta_editor_get_line_begin_position (editor
, line
, NULL
),
59 if (strncmp (text
, "#!/", 3) == 0) // For Seed support (Remove "#!/usr/bin/env seed" )
60 strncpy (text
, "//", 2);
61 for (j
= 0, i
= 0, k
= strlen (text
); i
< k
; i
++)
70 gchar
*tmp
= g_new (gchar
, j
+ 1);
71 for (i
= 0; i
< j
; i
++)
74 tmp
= g_strconcat (text
, tmp
, NULL
);
77 gchar
*tmp_file
= tmpnam (NULL
);
78 FILE *f1
= fopen (tmp_file
, "w");
79 fprintf (f1
, "%s", text
);
85 code_completion_get_str (IAnjutaEditor
*editor
, gboolean last_dot
)
87 IAnjutaIterable
*position
= ianjuta_editor_get_position (IANJUTA_EDITOR (editor
), NULL
);
89 gchar
*text
= ianjuta_editor_get_text (editor
,
90 ianjuta_editor_get_line_begin_position (editor
, 1, NULL
),
93 if (code_is_in_comment_or_str (text
, TRUE
))
99 gchar
*i
= strlen (text
) - 1 + text
;
114 for (s
= IDENT
; i
!= text
; i
--)
126 if (!isalnum (*i
) && *i
!= '.' && *i
!= '_')
140 if (*i
== ' ' || *i
== '\t' || *i
== '\n')
156 g_assert_not_reached ();
164 g_assert (i
!= NULL
);
169 code_completion_get_func_tooltip (JSLang
*plugin
, const gchar
*var_name
)
171 if (plugin
->symbol
== NULL
)
172 plugin
->symbol
= database_symbol_new ();
173 if (plugin
->symbol
== NULL
)
176 IJsSymbol
*symbol
= ijs_symbol_get_member (IJS_SYMBOL (plugin
->symbol
), var_name
);
179 DEBUG_PRINT ("Can't find symbol %s", var_name
);
183 GList
*args
= ijs_symbol_get_arg_list (symbol
);
187 for (i
= args
; i
; i
= g_list_next (i
))
193 gchar
* t
= g_strdup_printf ("%s, %s", res
, (gchar
*)i
->data
);
198 g_object_unref (symbol
);
203 code_completion_is_symbol_func (JSLang
*plugin
, const gchar
*var_name
)
205 if (plugin
->symbol
== NULL
)
206 plugin
->symbol
= database_symbol_new ();
207 if (plugin
->symbol
== NULL
)
210 IJsSymbol
*symbol
= ijs_symbol_get_member (IJS_SYMBOL (plugin
->symbol
), var_name
);
213 DEBUG_PRINT ("Can't find symbol %s", var_name
);
216 g_object_unref (symbol
);
217 return ijs_symbol_get_base_type (symbol
) == BASE_FUNC
;
221 code_completion_get_list (JSLang
*plugin
, const gchar
*tmp_file
, const gchar
*var_name
, gint depth_level
)
223 GList
*suggestions
= NULL
;
224 if (plugin
->symbol
== NULL
)
225 plugin
->symbol
= database_symbol_new ();
226 if (plugin
->symbol
== NULL
)
228 database_symbol_set_file (plugin
->symbol
, tmp_file
);
230 if (!var_name
|| strlen (var_name
) == 0)
231 return database_symbol_list_member_with_line (plugin
->symbol
,
232 ianjuta_editor_get_lineno (IANJUTA_EDITOR (plugin
->current_editor
), NULL
));
233 IJsSymbol
*t
= ijs_symbol_get_member (IJS_SYMBOL (plugin
->symbol
), var_name
);//TODO:Corect
236 suggestions
= ijs_symbol_list_member (IJS_SYMBOL (t
));