Skip to content

Commit eb9fb7d

Browse files
committed
Improve README.md and code comments
1 parent cba292e commit eb9fb7d

File tree

5 files changed

+67
-59
lines changed

5 files changed

+67
-59
lines changed

README.md

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,10 +33,6 @@ extension at
3333
- [Dependencies](#dependencies)
3434
- [Usage](#usage)
3535
- [Supported LSP Server Requests](#supported-lsp-server-requests)
36-
- [General Requests](#general-requests)
37-
- [Workspace Requests](#workspace-requests)
38-
- [Synchronization Requests](#synchronization-requests)
39-
- [Text Document Requests](#text-document-requests)
4036
- [Protocol extensions](#protocol-extensions)
4137
- [How to use the VScode extension](#how-to-use-the-vscode-extension)
4238
- [Getting started](#getting-started)
@@ -45,12 +41,13 @@ extension at
4541
- [Commands and shortcuts](#commands-and-shortcuts)
4642
- [Launch the extension to debug it](#launch-the-extension-to-debug-it)
4743
- [Configuration](#configuration)
48-
- [Integration with Coc.NVim](#integration-with-cocnvim)
49-
- [Integration with vim-lsp](#integration-with-vim-lsp)
50-
- [Integration with LanguageClient-Neovim](#integration-with-languageclient-neovim)
51-
- [Integration with Neovim's built-in LSP client](#integration-with-neovims-built-in-lsp-client)
44+
- [Integration with other editors and IDEs](#integration-with-other-editors-and-ides)
45+
- [Integration with Coc.NVim](#integration-with-cocnvim)
46+
- [Integration with vim-lsp](#integration-with-vim-lsp)
47+
- [Integration with LanguageClient-Neovim](#integration-with-languageclient-neovim)
48+
- [Integration with Neovim's built-in LSP client](#integration-with-neovims-built-in-lsp-client)
5249
- [Integration with emacs lsp-mode](#integration-with-emacs-lsp-mode)
53-
- [Integration with QtCreator](#integration-with-qtcreator)
50+
- [Integration with QtCreator](#integration-with-qtcreator)
5451
- [Refactoring Tools](#refactoring-tools)
5552
- [Authors & Contributors](#authors--contributors)
5653
- [Contribute](#contribute)
@@ -78,7 +75,7 @@ To build the language server you need:
7875
* The [VSS](https://github.com/AdaCore/VSS) library
7976
* The [gnatdoc](https://github.com/AdaCore/gnatdoc) library
8077
* The [gpr](https://github.com/AdaCore/gpr) library
81-
* The a process [spawn](https://github.com/AdaCore/spawn) library
78+
* The process [spawn](https://github.com/AdaCore/spawn) library
8279

8380
Project files of the libraries must be available via the `GPR_PROJECT_PATH`
8481
environment variable.
@@ -127,6 +124,11 @@ formatting might no succeed on incomplete/illegal code.
127124

128125
* **Toooling support**: we currently provide minimal support for *SPARK* (see *Prove/Examine* tasks in the [Auto-detected tasks](#auto-detected-tasks) section), but there is no support for tools such as *CodePeer*, *GNATcheck*, *GNATtest* or *GNATcoverage*.
129126

127+
* **Alire support**: if the root folder contains an `alire.toml` file and
128+
there is `alr` executable in the `PATH`, then the language server fetches
129+
the project's search path, environment variables and the project's file
130+
name from the crate description.
131+
130132
* **Project support**: there is no `Scenario` view: users should configure scenarios via the *ada.scenarioVariables* setting (see the settings list available [here](doc/refactoring_tools.md)). You can execute the *Ada: Reload project* command to reload your project after saving the new scenario values (use the *Ctrl+P* shortcut to invoke the **Command Palette**, allowing you to execute commands).
131133

132134
Source directories from imported projects should be added in a [workspace file](https://code.visualstudio.com/docs/editor/workspaces#_multiroot-workspaces). If you already have a workspace file, the extension will propose you to automatically add all the source directories coming from imported projects to your workspace automatically at startup.

source/ada/lsp-ada_handlers-alire.adb

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,19 +138,14 @@ package body LSP.Ada_Handlers.Alire is
138138
end if;
139139

140140
Start_Alire (List (1), ALR.all, "--non-interactive", "show", Root);
141-
loop
142-
Spawn.Processes.Monitor_Loop (0.1);
143-
144-
exit when List (1).Process.Status = Spawn.Not_Running;
145-
end loop;
146-
147141
Start_Alire (List (2), ALR.all, "--non-interactive", "printenv", Root);
142+
148143
loop
149144
Spawn.Processes.Monitor_Loop (0.1);
150145

151-
exit when List (2).Process.Status = Spawn.Not_Running;
146+
exit when
147+
(for all Item of List => Item.Process.Status = Spawn.Not_Running);
152148
end loop;
153-
-- TODO: Fix spawn and wait both process with a single loop
154149

155150
Decoder.Initialize ("utf-8");
156151
GNAT.OS_Lib.Free (ALR);

source/ada/lsp-ada_handlers-alire.ads

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,6 @@ package LSP.Ada_Handlers.Alire is
3939
Error : out VSS.Strings.Virtual_String;
4040
Search_Path : out VSS.String_Vectors.Virtual_String_Vector;
4141
Scenario : in out Scenario_Variable_List);
42-
-- THe same, but when without fetching the project file.
42+
-- The same as above, but without fetching the project file
4343

4444
end LSP.Ada_Handlers.Alire;

source/ada/lsp-ada_handlers.adb

Lines changed: 47 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -275,16 +275,16 @@ package body LSP.Ada_Handlers is
275275
-- * if a project (and optionally a scenario) was specified by
276276
-- the user via the workspace/didChangeConfiguration notification or
277277
-- Initialize request, attempt to use this.
278-
-- If there is `alire.toml` in the root, then run `alr` to find
279-
-- search path and extra scenario variables.
278+
-- If there is an `alire.toml` file in the root directory, then run
279+
-- `alr` to find search path and extra scenario variables.
280280
-- If this fails to load, then report an error, but do not attempt to
281281
-- load another project.
282-
-- => This case is handled by a call to Load_Project in
282+
-- => This case is handled by a call to Reload_Project in
283283
-- Change_Configuration.
284284
--
285285
-- * if no project was specified by the user, then run `alr` in the
286286
-- root directory to get project file name from alire.toml (take the
287-
-- vefy first project if many or crate name if none).
287+
-- very first project if many or crate name if none).
288288
-- Otherwise look in the root directory, mimicking the behavior of
289289
-- gprbuild :
290290
-- * if there are zero .gpr files in this directory, load the
@@ -331,21 +331,29 @@ package body LSP.Ada_Handlers is
331331
Charset : VSS.Strings.Virtual_String;
332332
Status : Load_Project_Status);
333333
-- Attempt to load the given project file, with the scenario provided.
334-
-- This unloads all currently loaded project contexts.
334+
-- This unloads all currently loaded project contexts. This factorizes code
335+
-- between Load_Project_With_Alire and Ensure_Project_Loaded.
335336

336337
procedure Load_Project_With_Alire
337338
(Self : access Message_Handler;
338-
Project_File : VSS.Strings.Virtual_String;
339+
Project_File : VSS.Strings.Virtual_String := "";
339340
Scenario_Variables : Scenario_Variable_List;
340-
Charset : VSS.Strings.Virtual_String;
341-
Status : Load_Project_Status);
341+
Charset : VSS.Strings.Virtual_String);
342+
-- Core procedure to find project, search path, scenario and load the
343+
-- project.
344+
--
345+
-- @param Self The message handler itself
346+
-- @param Project_File GPR, if set by the user in settings
347+
-- @param Scenario_Variables Scenario as set by the user in settings
348+
-- @param Charset Charset, if set by the user in settings
349+
--
342350
-- Load a project with a help of alire. If there is `alire.toml` in the
343-
-- root directory and `alr` in the `PATH`, then
344-
-- * use Alire to setup project search path, extra scenario variables (and
345-
-- a project file name if Project_File is empty).
346-
-- * load project
347-
-- If Project_File is not empty then load it even if there is no alire.toml
348-
-- or `alr`.
351+
-- root directory and `alr` in the `PATH`, then use Alire to setup project
352+
-- search path, extra scenario variables (and a project file name if
353+
-- Project_File is empty). If Alire reports error then show it to the
354+
-- user and fallback to an implicit project.
355+
--
356+
-- If Alire succeed or no alire/crate then load project if provided.
349357

350358
procedure Mark_Source_Files_For_Indexing (Self : access Message_Handler);
351359
-- Mark all sources in all projects for indexing. This factorizes code
@@ -674,8 +682,7 @@ package body LSP.Ada_Handlers is
674682
Self.Load_Project_With_Alire
675683
(Self.Project_File,
676684
Self.Scenario_Variables,
677-
Self.Charset,
678-
Self.Project_Status);
685+
Self.Charset);
679686
end if;
680687
end Reload_Project;
681688

@@ -772,8 +779,7 @@ package body LSP.Ada_Handlers is
772779
Self.Load_Project_With_Alire
773780
(Project_File => VSS.Strings.Empty_Virtual_String,
774781
Scenario_Variables => Self.Scenario_Variables,
775-
Charset => Self.Charset,
776-
Status => Alire_Project);
782+
Charset => Self.Charset);
777783

778784
if not Self.Contexts.Is_Empty then
779785
-- Some project was found by alire and loaded. We are done!
@@ -4963,13 +4969,13 @@ package body LSP.Ada_Handlers is
49634969

49644970
procedure Load_Project_With_Alire
49654971
(Self : access Message_Handler;
4966-
Project_File : VSS.Strings.Virtual_String;
4972+
Project_File : VSS.Strings.Virtual_String := "";
49674973
Scenario_Variables : Scenario_Variable_List;
4968-
Charset : VSS.Strings.Virtual_String;
4969-
Status : Load_Project_Status)
4974+
Charset : VSS.Strings.Virtual_String)
49704975
is
49714976

49724977
Has_Alire : Boolean;
4978+
Status : Load_Project_Status;
49734979
Errors : VSS.Strings.Virtual_String;
49744980
Project : VSS.Strings.Virtual_String := Project_File;
49754981
Search_Path : VSS.String_Vectors.Virtual_String_Vector;
@@ -4992,6 +4998,8 @@ package body LSP.Ada_Handlers is
49924998
Project => Project,
49934999
Search_Path => Search_Path,
49945000
Scenario => Scenario);
5001+
5002+
Status := Alire_Project;
49955003
else
49965004

49975005
LSP.Ada_Handlers.Alire.Run_Alire
@@ -5000,6 +5008,8 @@ package body LSP.Ada_Handlers is
50005008
Error => Errors,
50015009
Search_Path => Search_Path,
50025010
Scenario => Scenario);
5011+
5012+
Status := Valid_Project_Configured;
50035013
end if;
50045014

50055015
if Has_Alire and then not Errors.Is_Empty then
@@ -5026,47 +5036,48 @@ package body LSP.Ada_Handlers is
50265036
pragma Assert (not Project.Is_Empty);
50275037

50285038
Self.Trace.Trace
5029-
("Project:" & VSS.Strings.Conversions.To_UTF_8_String (Project));
5039+
(Message => "Project:"
5040+
& VSS.Strings.Conversions.To_UTF_8_String (Project));
50305041

5031-
Self.Trace.Trace ("Search Path:");
5042+
Self.Trace.Trace (Message => "Search Path:");
50325043
for Item of Search_Path loop
50335044
Self.Trace.Trace
5034-
(VSS.Strings.Conversions.To_UTF_8_String (Item));
5045+
(Message => VSS.Strings.Conversions.To_UTF_8_String (Item));
50355046
end loop;
50365047

50375048
Self.Trace.Trace ("Scenario:");
50385049
for J in 1 .. Scenario.Names.Length loop
50395050
Self.Trace.Trace
5040-
(VSS.Strings.Conversions.To_UTF_8_String
5051+
(Message => VSS.Strings.Conversions.To_UTF_8_String
50415052
(Scenario.Names (J))
50425053
& "="
50435054
& VSS.Strings.Conversions.To_UTF_8_String
50445055
(Scenario.Values (J)));
50455056
end loop;
50465057

50475058
Self.Load_Project
5048-
(Project,
5049-
Search_Path,
5050-
Scenario,
5051-
(if Charset.Is_Empty then UTF_8 else Charset),
5052-
Status);
5059+
(Project_File => Project,
5060+
Search_Path => Search_Path,
5061+
Scenario => Scenario,
5062+
Charset => (if Charset.Is_Empty then UTF_8 else Charset),
5063+
Status => Status);
50535064
-- Alire projects tend to use utf-8
50545065

50555066
return;
50565067
else
5057-
Self.Trace.Trace ("No alr in the PATH.");
5068+
Self.Trace.Trace (Message => "No alr in the PATH.");
50585069
end if;
50595070
end if;
50605071

50615072
-- There is no alire.toml or no alr, but we know the project, load it
50625073
if not Project.Is_Empty then
50635074

50645075
Self.Load_Project
5065-
(Project,
5066-
VSS.String_Vectors.Empty_Virtual_String_Vector,
5067-
Scenario_Variables,
5068-
Charset,
5069-
Status);
5076+
(Project_File => Project,
5077+
Search_Path => VSS.String_Vectors.Empty_Virtual_String_Vector,
5078+
Scenario => Scenario_Variables,
5079+
Charset => Charset,
5080+
Status => Valid_Project_Configured);
50705081
end if;
50715082
end Load_Project_With_Alire;
50725083

testsuite/ada_lsp/show_dependencies.aggregate/test.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -179,19 +179,19 @@
179179
"result": [
180180
{
181181
"uri": "$URI{common/common_pack.ads}",
182-
"projectUri": "$URI{}/"
182+
"projectUri": "$URI{}${DIR_SEP}"
183183
},
184184
{
185185
"uri": "$URI{common/common_pack.ads}",
186-
"projectUri": "$URI{}/"
186+
"projectUri": "$URI{}${DIR_SEP}"
187187
},
188188
{
189189
"uri": "$URI{p/main.adb}",
190-
"projectUri": "$URI{}/"
190+
"projectUri": "$URI{}${DIR_SEP}"
191191
},
192192
{
193193
"uri": "$URI{q/main.adb}",
194-
"projectUri": "$URI{}/"
194+
"projectUri": "$URI{}${DIR_SEP}"
195195
}
196196
]
197197
}

0 commit comments

Comments
 (0)