1
-----------------------------------------------------------------------
4
-- Copyright (C) 2007-2010, AdaCore --
6
-- GPS is free software; you can redistribute it and/or modify it --
7
-- under the terms of the GNU General Public License as published by --
8
-- the Free Software Foundation; either version 2 of the License, or --
9
-- (at your option) any later version. --
11
-- This program is distributed in the hope that it will be useful, --
12
-- but WITHOUT ANY WARRANTY; without even the implied warranty of --
13
-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU --
14
-- General Public License for more details. You should have received --
15
-- a copy of the GNU General Public License along with this program; --
16
-- if not, write to the Free Software Foundation, Inc., 59 Temple --
17
-- Place - Suite 330, Boston, MA 02111-1307, USA. --
18
-----------------------------------------------------------------------
20
-- This package offers an history capability to the completion engine. This is
21
-- an optional capability, enabled by implementing the interface
22
-- Storable_Proposal to the Completion_Proposal.
24
with Ada.Containers.Indefinite_Doubly_Linked_Lists;
27
package Completion.History is
29
type Completion_History is new Completion_Resolver with private;
30
-- A completion history has to be populated by user chosen completion.
31
-- Later, the most recent proposals will be displayed in top of the list.
32
-- This resolver has to be the first one referenced in the manager. It's
33
-- implemented as a stack of unique stored proposals.
35
type Completion_History_Access is access all Completion_History'Class;
37
type Storable_Proposal is abstract new Completion_Proposal with null record;
38
-- This is the root type of any completion proposal that's supposed to
39
-- be able to manage history
40
-- ??? This should really be an interface.
42
type Stored_Proposal is abstract tagged null record;
43
-- This is the base type for a proposal stored in the history. Such a
44
-- proposal must have the capability of surviving during the whole
45
-- lifecycle of a tool session, beyond the usual completion resolver and
46
-- manager lifetime. The user is also responsible to check if the
47
-- completion is still possible or not.
49
type Stored_Proposal_Access is access all Stored_Proposal'Class;
51
function To_Stored_Proposal
52
(Proposal : Storable_Proposal) return Stored_Proposal_Access is abstract;
53
-- Extract the stored proposal from a storable proposal.
56
(Left : Stored_Proposal; Right : Stored_Proposal'Class)
57
return Boolean is abstract;
58
-- Return true if the two proposals are equals - the completion history
59
-- will only store unique proposals.
61
function From_Stored_Proposal
62
(Stored : Stored_Proposal;
63
Manager : Completion_Manager_Access;
64
Context : Completion_Context)
65
return Completion_Proposal_Access is abstract;
66
-- Recreates a completion proposal out of a stored proposal. If the
67
-- proposal cannot be retreived anymore, the implementer may return a null
70
function Is_Valid (Stored : Stored_Proposal) return Boolean is abstract;
71
-- The proposals stored in the history may be no longer valid after a
72
-- while - in which case, False should be return by this subprogram, True
75
procedure Free (Stored : in out Stored_Proposal) is abstract;
76
-- Free the data associated to this stored proposal;
79
procedure Get_Completion_Root
80
(Resolver : access Completion_History;
81
Offset : String_Index_Type;
82
Context : Completion_Context;
83
Result : in out Completion_List);
84
-- See inherited documentation
87
function Get_Id (Resolver : Completion_History) return String;
88
-- See inherited documentation
91
procedure Free (Resolver : in out Completion_History);
92
-- See inherited documentation
94
procedure Prepend_Proposal
95
(Resolver : access Completion_History;
96
Proposal : Completion_Proposal'Class
97
-- This proposal has to implement the interface Storable_Proposal in
98
-- order to be stored. If not, the proposal won't be stored.
100
-- This function has to be called each time a completion is applied by
101
-- the user. The proposal will be added in the front of the history list.
102
-- If the proposal given in parameter is already in the list, then it will
103
-- be moved to the front.
105
procedure Set_History_Size
106
(History : access Completion_History; Size : Natural);
107
-- Sets the history maximum size. By default, it has 50 elements.
111
package Proposal_Stack is new
112
Indefinite_Doubly_Linked_Lists (Stored_Proposal_Access);
116
type Completion_History is new Completion_Resolver with record
117
Stack : Proposal_Stack.List;
118
Size : Natural := 50;
121
end Completion.History;