@@ -30,7 +30,6 @@ with Langkit_Support.Symbols;
3030with Langkit_Support.Text ;
3131with Libadalang.Analysis ; use Libadalang.Analysis;
3232with Libadalang.Sources ;
33- with Libadalang.Doc_Utils ;
3433with Libadalang.Iterators ;
3534
3635with VSS.String_Vectors ;
@@ -1764,6 +1763,7 @@ package body LSP.Ada_Documents is
17641763 BD : Libadalang.Analysis.Basic_Decl;
17651764 Label : VSS.Strings.Virtual_String;
17661765 Use_Snippets : Boolean;
1766+ Compute_Doc_And_Details : Boolean;
17671767 Named_Notation_Threshold : Natural;
17681768 Is_Dot_Call : Boolean;
17691769 Is_Visible : Boolean;
@@ -1776,8 +1776,6 @@ package body LSP.Ada_Documents is
17761776
17771777 Item : CompletionItem;
17781778 Subp_Spec_Node : Base_Subp_Spec;
1779- Doc_Text : VSS.Strings.Virtual_String;
1780- Loc_Text : VSS.Strings.Virtual_String;
17811779 Min_Width : constant Natural := Completions_Count'Img'Length - 1 ;
17821780
17831781 function Get_Sort_text (Base_Label : LSP_String) return LSP_String;
@@ -1815,9 +1813,6 @@ package body LSP.Ada_Documents is
18151813 Item.label := Label;
18161814 Item.kind := (True, To_Completion_Kind
18171815 (LSP.Lal_Utils.Get_Decl_Kind (BD)));
1818- Item.detail := (True,
1819- LSP.Types.To_LSP_String
1820- (LSP.Lal_Utils.Compute_Completion_Detail (BD)));
18211816
18221817 declare
18231818 Base_Label : constant LSP_String := LSP.Types.To_LSP_String
@@ -1836,41 +1831,39 @@ package body LSP.Ada_Documents is
18361831 end if ;
18371832 end ;
18381833
1839- -- Property_Errors can occur when calling
1840- -- Get_Documentation on unsupported docstrings, so
1841- -- add an exception handler to catch them and recover.
1842-
1843- begin
1844- Doc_Text :=
1845- VSS.Strings.To_Virtual_String
1846- (Libadalang.Doc_Utils.Get_Documentation
1847- (BD).Doc.To_String);
1848-
1849- -- Append the declaration's location.
1850- -- In addition, append the project's name if we are dealing with an
1851- -- aggregate project.
1852-
1853- Loc_Text.Append (LSP.Lal_Utils.Node_Location_Image (BD));
1854-
1855- if not Doc_Text.Is_Empty then
1856- Loc_Text.Append
1857- (VSS.Strings.To_Virtual_String
1858- ((1 .. 2 => Ada.Characters.Wide_Wide_Latin_1.LF)));
1859-
1860- Loc_Text.Append (Doc_Text);
1861- end if ;
1862-
1863- Item.documentation :=
1864- (Is_Set => True,
1865- Value => String_Or_MarkupContent'
1866- (Is_String => True,
1867- String => Loc_Text));
1868-
1869- exception
1870- when E : Libadalang.Common.Property_Error =>
1871- LSP.Common.Log (Context.Trace, E);
1872- Item.documentation := (others => <>);
1873- end ;
1834+ -- Compute the 'documentation' and 'detail' fields immediately if
1835+ -- requested (i.e: when the client does not support lazy computation
1836+ -- for these fields).
1837+ if Compute_Doc_And_Details then
1838+ Item.detail :=
1839+ (True,
1840+ LSP.Types.To_LSP_String
1841+ (LSP.Lal_Utils.Compute_Completion_Detail (BD)));
1842+
1843+ -- Property_Errors can occur when calling
1844+ -- Get_Documentation on unsupported docstrings, so
1845+ -- add an exception handler to catch them and recover.
1846+ begin
1847+ Item.documentation :=
1848+ (Is_Set => True,
1849+ Value => String_Or_MarkupContent'
1850+ (Is_String => True,
1851+ String => LSP.Lal_Utils.Compute_Completion_Doc (BD)));
1852+
1853+ exception
1854+ when E : Libadalang.Common.Property_Error =>
1855+ LSP.Common.Log (Context.Trace, E);
1856+ Item.documentation := (others => <>);
1857+ end ;
1858+ else
1859+ -- Set node's location to the 'data' field of the completion item, so
1860+ -- that we can retrieve it in the completionItem/resolve handler.
1861+ Item.data :=
1862+ (True,
1863+ (uri => File_To_URI (BD.Unit.Get_Filename),
1864+ span => LSP.Lal_Utils.To_Span (BD.Sloc_Range),
1865+ others => <>));
1866+ end if ;
18741867
18751868 -- Return immediately if we should not use snippets (e.g: completion for
18761869 -- invisible symbols).
@@ -2018,6 +2011,7 @@ package body LSP.Ada_Documents is
20182011 Pattern : LSP.Search.Search_Pattern'Class;
20192012 Limit : Ada.Containers.Count_Type;
20202013 Only_Public : Boolean;
2014+ Canceled : access function return Boolean;
20212015 Result : in out LSP.Ada_Completions.Completion_Maps.Map)
20222016 is
20232017 use type LSP.Messages.Search_Kind;
@@ -2121,19 +2115,23 @@ package body LSP.Ada_Documents is
21212115 then
21222116 Insert (Item);
21232117 end if ;
2118+
2119+ exit when Canceled.all ;
21242120 end loop ;
21252121
21262122 elsif Pattern.Match (Symbol_Maps.Key (Cursor)) then
21272123 -- Symbol_Cache is case insensitive so if the key is matched
21282124 -- this means that all elements are also matched the pattern
21292125 for Item of Self.Symbol_Cache (Cursor) loop
21302126 Insert (Item);
2127+
2128+ exit when Canceled.all ;
21312129 end loop ;
21322130
21332131 else
21342132 -- Symbol_Cache is ordered so we will not find any
21352133 -- matches more
2136- exit when Use_Celling;
2134+ exit when Use_Celling or else Canceled. all ;
21372135 end if ;
21382136
21392137 Symbol_Maps.Next (Cursor);
0 commit comments