11-- ----------------------------------------------------------------------------
22-- Language Server Protocol --
33-- --
4- -- Copyright (C) 2022-2024 , AdaCore --
4+ -- Copyright (C) 2022-2025 , AdaCore --
55-- --
66-- This is free software; you can redistribute it and/or modify it under --
77-- terms of the GNU General Public License as published by the Free Soft- --
@@ -23,14 +23,15 @@ with GPR2.Path_Name.Set;
2323
2424with Langkit_Support.Slocs ;
2525
26- with LSP.GPR_Completions ;
2726with LSP.Constants ;
2827with LSP.Enumerations ;
2928with LSP.Generic_Cancel_Check ;
29+ with LSP.GPR_Completions ;
3030with LSP.GPR_Documentation ;
3131with LSP.GPR_File_Readers ;
3232with LSP.GPR_Files.References ;
3333with LSP.GPR_Files.Symbols ;
34+ with LSP.Structures.Unwrap ;
3435with LSP.Text_Documents.Langkit_Documents ;
3536with LSP.Utils ;
3637
@@ -398,7 +399,8 @@ package body LSP.GPR_Handlers is
398399 Value : LSP.Structures.InitializeParams)
399400 is
400401 Response : LSP.Structures.InitializeResult;
401- Capabilities : LSP.Structures.ServerCapabilities;
402+ Capabilities : LSP.Structures.ServerCapabilities renames
403+ Response.capabilities;
402404
403405 begin
404406 Self.File_Reader := LSP.GPR_File_Readers.Create (Self'Unchecked_Access);
@@ -414,9 +416,7 @@ package body LSP.GPR_Handlers is
414416 resolveProvider => LSP.Constants.True,
415417 others => <>));
416418
417- Response.capabilities := Capabilities;
418-
419- Response.capabilities.textDocumentSync :=
419+ Capabilities.textDocumentSync :=
420420 (Is_Set => True,
421421 Value => (Is_TextDocumentSyncOptions => True,
422422 TextDocumentSyncOptions =>
@@ -427,7 +427,7 @@ package body LSP.GPR_Handlers is
427427 (Is_Set => True, Value => (True, True)),
428428 others => <>)));
429429
430- Response.capabilities .documentSymbolProvider :=
430+ Capabilities .documentSymbolProvider :=
431431 (Is_Set => True,
432432 Value =>
433433 (Is_Boolean => False,
@@ -442,6 +442,32 @@ package body LSP.GPR_Handlers is
442442 and then Value.capabilities.textDocument.Value.documentSymbol.Value
443443 .hierarchicalDocumentSymbolSupport.Value;
444444
445+ declare
446+ use LSP.Structures.Unwrap;
447+
448+ Types : LSP.Structures.Virtual_String_Vector :=
449+ tokenTypes
450+ (semanticTokens (Value.capabilities.textDocument));
451+
452+ Modifiers : LSP.Structures.Virtual_String_Vector :=
453+ tokenModifiers
454+ (semanticTokens (Value.capabilities.textDocument));
455+ begin
456+ Self.Highlighter.Initialize (Types, Modifiers);
457+
458+ Capabilities.semanticTokensProvider :=
459+ (Is_Set => True,
460+ Value =>
461+ (Is_SemanticTokensOptions => True,
462+ SemanticTokensOptions =>
463+ (full => LSP.Constants.True,
464+ a_range => <>,
465+ legend =>
466+ (tokenTypes => Types,
467+ tokenModifiers => Modifiers),
468+ others => <>)));
469+ end ;
470+
445471 Self.Sender.On_Initialize_Response (Id, Response);
446472 end On_Initialize_Request ;
447473
@@ -713,6 +739,27 @@ package body LSP.GPR_Handlers is
713739 end loop ;
714740 end On_DidChangeConfiguration_Notification ;
715741
742+ -- --------------------------
743+ -- On_Tokens_Full_Request --
744+ -- --------------------------
745+
746+ overriding procedure On_Tokens_Full_Request
747+ (Self : in out Message_Handler;
748+ Id : LSP.Structures.Integer_Or_Virtual_String;
749+ Value : LSP.Structures.SemanticTokensParams)
750+ is
751+ File : constant LSP.GPR_Files.File_Access :=
752+ LSP.GPR_Files.Parse
753+ (File_Provider => Self'Unchecked_Access,
754+ Path => Self.To_File (Value.textDocument.uri));
755+
756+ Response : LSP.Structures.SemanticTokens_Or_Null (Is_Null => False);
757+ begin
758+ Self.Highlighter.Get_Tokens (File, Response.Value.data);
759+
760+ Self.Sender.On_Tokens_Full_Response (Id, Response);
761+ end On_Tokens_Full_Request ;
762+
716763 -- -----------------------
717764 -- Publish_Diagnostics --
718765 -- -----------------------
0 commit comments