Skip to content

Commit a259ba1

Browse files
Merge branch 'topic/als.1358.remove_implicit_fallback_for_configured_project' into 'edge'
Second pass on project loading See merge request eng/ide/ada_language_server!1665
2 parents a25d0b0 + b35c13b commit a259ba1

File tree

114 files changed

+5072
-384
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

114 files changed

+5072
-384
lines changed

integration/vscode/ada/src/ExtensionState.ts

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ export class ExtensionState {
4747
/**
4848
* The following fields are caches for ALS requests or costly properties.
4949
*/
50-
cachedProjectFile: string | undefined;
50+
cachedProjectUri: vscode.Uri | undefined;
5151
cachedObjectDir: string | undefined;
5252
cachedMains: string[] | undefined;
5353
cachedExecutables: string[] | undefined;
@@ -57,7 +57,7 @@ export class ExtensionState {
5757
private sparkTaskProvider?: SimpleTaskProvider;
5858

5959
public clearALSCache() {
60-
this.cachedProjectFile = undefined;
60+
this.cachedProjectUri = undefined;
6161
this.cachedObjectDir = undefined;
6262
this.cachedMains = undefined;
6363
this.cachedExecutables = undefined;
@@ -184,16 +184,26 @@ export class ExtensionState {
184184
};
185185

186186
/**
187-
* @returns the full path of the main project file from the ALS
187+
* @returns the URI of the main project file from the ALS
188188
*/
189-
public async getProjectFile(): Promise<string> {
190-
if (!this.cachedProjectFile) {
191-
this.cachedProjectFile = (await this.adaClient.sendRequest(ExecuteCommandRequest.type, {
189+
public async getProjectUri(): Promise<vscode.Uri | undefined> {
190+
if (!this.cachedProjectUri) {
191+
const strUri = (await this.adaClient.sendRequest(ExecuteCommandRequest.type, {
192192
command: 'als-project-file',
193193
})) as string;
194+
if (strUri != '') {
195+
this.cachedProjectUri = vscode.Uri.parse(strUri, true);
196+
}
194197
}
195198

196-
return this.cachedProjectFile;
199+
return this.cachedProjectUri;
200+
}
201+
202+
/**
203+
* @returns the full path of the main project file from the ALS
204+
*/
205+
public async getProjectFile(): Promise<string> {
206+
return (await this.getProjectUri())?.fsPath ?? '';
197207
}
198208

199209
/**

integration/vscode/ada/test/suite/general/extension.test.ts

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
import * as assert from 'assert';
22
import { adaExtState } from '../../../src/extension';
3-
import { getProjectFile, getObjectDir } from '../../../src/helpers';
4-
import { assertEqualToFileContent, activate } from '../utils';
3+
import { getObjectDir } from '../../../src/helpers';
4+
import { activate, assertEqualToFileContent } from '../utils';
55

6-
import * as vscode from 'vscode';
76
import { readFileSync, writeFileSync } from 'fs';
8-
import { basename } from 'path';
7+
import * as vscode from 'vscode';
98

109
suite('Extensions Test Suite', function () {
1110
// Make sure the extension is activated
@@ -14,9 +13,14 @@ suite('Extensions Test Suite', function () {
1413
});
1514
test('Project File Response', async () => {
1615
if (vscode.workspace.workspaceFolders !== undefined) {
17-
const result: string = await getProjectFile(adaExtState.adaClient);
18-
const name = basename(result);
19-
assert.strictEqual(name, 'prj.gpr');
16+
// Uri obtained from the ALS
17+
const alsUri = await adaExtState.getProjectUri();
18+
// Uri manually computed based on the loaded workspace
19+
const wsUri = vscode.Uri.joinPath(vscode.workspace.workspaceFolders[0].uri, 'prj.gpr');
20+
// Ask for fsPath, it will resolve wsUri._fsPath
21+
wsUri.fsPath != null
22+
// Both should match
23+
assert.deepStrictEqual(alsUri, wsUri);
2024
} else {
2125
throw new Error('No workspace folder found for the specified URI');
2226
}

source/ada/lsp-ada_handlers-other_file_commands.adb

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -132,13 +132,17 @@ package body LSP.Ada_Handlers.Other_File_Commands is
132132
begin
133133
-- First look in the closure of sources, then in the
134134
-- runtime project.
135-
Unit := Handler.Project_Tree.Root_Project.Unit (F.Base_Name);
135+
if Handler.Project_Tree.Is_Defined then
136+
Unit := Handler.Project_Tree.Root_Project.Unit (F.Base_Name);
136137

137-
if not Unit.Is_Defined then
138-
Unit := Handler.Project_Tree.Runtime_Project.Unit
139-
(F.Base_Name);
138+
if not Unit.Is_Defined then
139+
Unit := Handler.Project_Tree.Runtime_Project.Unit
140+
(F.Base_Name);
141+
end if;
142+
return Unit;
143+
else
144+
return GPR2.Build.Compilation_Unit.Undefined;
140145
end if;
141-
return Unit;
142146
end Unit_For_File;
143147

144148
begin

source/ada/lsp-ada_handlers-project_file_commands.adb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717

1818
with GPR2.Project.View;
1919

20+
with URIs;
21+
2022
with VSS.JSON.Streams;
2123

2224
package body LSP.Ada_Handlers.Project_File_Commands is
@@ -60,7 +62,7 @@ package body LSP.Ada_Handlers.Project_File_Commands is
6062
if Handler.Project_Tree.Is_Defined then
6163
Element := Handler.Project_Tree.Root_Project;
6264
Value := VSS.Strings.Conversions.To_Virtual_String
63-
(String (Element.Path_Name.Value));
65+
(URIs.Conversions.From_File (String (Element.Path_Name.Value)));
6466
end if;
6567

6668
Response := (Is_Null => False, Value => <>);

0 commit comments

Comments
 (0)