ada_language_server_23.0.0_66f2e7fb/source/ada/lsp-ada_highlighters.ads

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
------------------------------------------------------------------------------
--                         Language Server Protocol                         --
--                                                                          --
--                       Copyright (C) 2022, AdaCore                        --
--                                                                          --
-- This is free software;  you can redistribute it  and/or modify it  under --
-- terms of the  GNU General Public License as published  by the Free Soft- --
-- ware  Foundation;  either version 3,  or (at your option) any later ver- --
-- sion.  This software is distributed in the hope  that it will be useful, --
-- but WITHOUT ANY WARRANTY;  without even the implied warranty of MERCHAN- --
-- TABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public --
-- License for  more details.  You should have  received  a copy of the GNU --
-- General  Public  License  distributed  with  this  software;   see  file --
-- COPYING3.  If not, go to http://www.gnu.org/licenses for a complete copy --
-- of the license.                                                          --
------------------------------------------------------------------------------

with Ada.Containers.Hashed_Maps;
with Ada.Strings.Wide_Wide_Unbounded;

with GNATCOLL.Traces;

with Libadalang.Analysis;

with LSP.Messages;
with LSP.Types;

package LSP.Ada_Highlighters is

   type Ada_Highlighter is tagged limited private;

   procedure Initialize
     (Self   : in out Ada_Highlighter'Class;
      Client : LSP.Messages.SemanticTokensClientCapabilities;
      Legend : out LSP.Messages.SemanticTokensLegend);

   function Get_Tokens
     (Self  : Ada_Highlighter'Class;
      Unit  : Libadalang.Analysis.Analysis_Unit;
      Trace : GNATCOLL.Traces.Trace_Handle;
      Span  : LSP.Messages.Span)
      return LSP.Messages.uinteger_Vector;
   --  If Span isn't empty then return unit tokens in given Span, otherwise
   --  return all tokens in the Unit.

private

   function Hash (Value : LSP.Messages.SemanticTokenTypes)
     return Ada.Containers.Hash_Type is
       (Ada.Containers.Hash_Type
          (LSP.Messages.SemanticTokenTypes'Pos (Value)));

   package Token_Type_Maps is new Ada.Containers.Hashed_Maps
     (LSP.Messages.SemanticTokenTypes,
      LSP.Messages.uinteger,
      Hash,
      LSP.Messages."=",
      LSP.Types."=");

   function Hash (Value : LSP.Messages.SemanticTokenModifiers)
     return Ada.Containers.Hash_Type is
       (Ada.Containers.Hash_Type
          (LSP.Messages.SemanticTokenModifiers'Pos (Value)));

   package Token_Modifier_Maps is new Ada.Containers.Hashed_Maps
     (LSP.Messages.SemanticTokenModifiers,
      LSP.Messages.uinteger,
      Hash,
      LSP.Messages."=",
      LSP.Types."=");

   subtype Unbounded_Text_Type is
     Ada.Strings.Wide_Wide_Unbounded.Unbounded_Wide_Wide_String;

   type Ada_Highlighter is tagged limited record
      Token_Types     : Token_Type_Maps.Map;
      Token_Modifiers : Token_Modifier_Maps.Map;
      Obsolescent     : Unbounded_Text_Type;
      Ada             : Unbounded_Text_Type;
      System          : Unbounded_Text_Type;
      Interfaces      : Unbounded_Text_Type;
   end record;

end LSP.Ada_Highlighters;