4 // not sure why - but extending Gtk.SourceCompletionProvider seems to give an error..
7 public class CompletionProvider : Object, SourceCompletionProvider
10 WindowState windowstate;
11 //public List<Gtk.SourceCompletionItem> filtered_proposals;
13 public CompletionProvider(Editor editor)
16 this.windowstate = null; // not ready until the UI is built.
20 public string get_name ()
25 public int get_priority ()
30 public bool match (SourceCompletionContext context)
36 public void populate (SourceCompletionContext context)
38 if (this.windowstate == null) {
39 this.windowstate = this.editor.window.windowstate;
43 var buffer = context.completion.view.buffer;
44 var mark = buffer.get_insert ();
47 buffer.get_iter_at_mark (out end, mark);
50 var searchpos = endpos;
52 searchpos.backward_find_char(is_space, null);
53 searchpos.forward_char();
54 var search = endpos.get_text(searchpos);
55 print("got search %s\n", search);
57 if (search.length < 2) {
61 var filtered_proposals = this.windowstate.file.palete().suggestComplete(
62 this.windowstate.file,
68 filtered_proposals.sort((a, b) => {
69 return ((string)(a.text)).collate((string)(b.text));
72 context.add_proposals (this, filtered_proposals, true);
77 public bool activate_proposal (SourceCompletionProposal proposal, TextIter iter)
80 istart.backward_find_char(is_space, null);
81 istart.forward_char();
83 // var search = iter.get_text(istart);
85 var buffer = iter.get_buffer();
86 buffer.delete(ref istart, ref iter);
87 buffer.insert(ref istart, proposal.get_text(), -1);
92 public SourceCompletionActivation get_activation ()
94 //if(SettingsManager.Get_Setting("complete_auto") == "true"){
95 return SourceCompletionActivation.INTERACTIVE | SourceCompletionActivation.USER_REQUESTED;
97 // return Gtk.SourceCompletionActivation.USER_REQUESTED;
101 public int get_interactive_delay ()
106 public bool get_start_iter (SourceCompletionContext context, SourceCompletionProposal proposal, out TextIter iter)
111 public void update_info (SourceCompletionProposal proposal, SourceCompletionInfo info)
116 private bool is_space(unichar space){
117 return space.isspace() || space.to_string() == "";
120 private bool is_forward_space(unichar space){
122 space.to_string() == " "
124 space.to_string() == ""
126 space.to_string() == "\n"
128 space.to_string() == ")"
130 space.to_string() == "("