diff --git a/source/ada/lsp-ada_handlers-project_diagnostics.adb b/source/ada/lsp-ada_handlers-project_diagnostics.adb index eefa239bd..57898092d 100644 --- a/source/ada/lsp-ada_handlers-project_diagnostics.adb +++ b/source/ada/lsp-ada_handlers-project_diagnostics.adb @@ -90,11 +90,7 @@ package body LSP.Ada_Handlers.Project_Diagnostics is --------------------------------------- procedure Create_Project_Loading_Diagnostic is - Project_File : GNATCOLL.VFS.Virtual_File renames - Self.Handler.Project_Status.Project_File; - URI : constant LSP.Structures.DocumentUri := - Self.Handler.To_URI (Project_File.Display_Full_Name); - Sloc : constant LSP.Structures.A_Range := + Sloc : constant LSP.Structures.A_Range := (start => (0, 0), an_end => (0, 0)); begin @@ -112,15 +108,24 @@ package body LSP.Ada_Handlers.Project_Diagnostics is Parent_Diagnostic.message := Project_Loading_Status_Messages (Self.Last_Status); else - Parent_Diagnostic.message := "Project Problems"; - Parent_Diagnostic.relatedInformation.Append - (LSP .Structures.DiagnosticRelatedInformation' - (location => LSP.Structures.Location' - (uri => URI, - a_range => Sloc, - others => <>), - message => Project_Loading_Status_Messages - (Self.Last_Status))); + declare + Project_File : GNATCOLL.VFS.Virtual_File renames + Self.Handler.Project_Status.Project_File; + URI : constant LSP.Structures.DocumentUri := + Self.Handler.To_URI + (Project_File.Display_Full_Name); + begin + Parent_Diagnostic.message := "Project Problems"; + Parent_Diagnostic.relatedInformation.Append + (LSP.Structures.DiagnosticRelatedInformation' + (location => + LSP.Structures.Location' + (uri => URI, a_range => Sloc, + others => <>), + message => + Project_Loading_Status_Messages + (Self.Last_Status))); + end; end if; end Create_Project_Loading_Diagnostic; diff --git a/testsuite/ada_lsp/project_config.multiple_project_diagnostics/a.gpr b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/a.gpr new file mode 100644 index 000000000..77580cb9e --- /dev/null +++ b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/a.gpr @@ -0,0 +1,2 @@ +project A is +end A; diff --git a/testsuite/ada_lsp/project_config.multiple_project_diagnostics/b.gpr b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/b.gpr new file mode 100644 index 000000000..a97f22fac --- /dev/null +++ b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/b.gpr @@ -0,0 +1,2 @@ +project B is +end B; \ No newline at end of file diff --git a/testsuite/ada_lsp/project_config.multiple_project_diagnostics/main.adb b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/main.adb new file mode 100644 index 000000000..e0d8401fa --- /dev/null +++ b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/main.adb @@ -0,0 +1,4 @@ +procedure Main is +begin + null; +end Main; diff --git a/testsuite/ada_lsp/project_config.multiple_project_diagnostics/test.json b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/test.json new file mode 100644 index 000000000..e966530d3 --- /dev/null +++ b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/test.json @@ -0,0 +1,231 @@ +[ + { + "comment": [ + "Test the project diagnostics when we have several .gpr files in the ", + "root directory, without having set the 'ada.projectFile' setting.", + "It also checks that we propose a quickfix to set 'ada.projectFile'." + ] + }, + { + "start": { + "cmd": ["${ALS}"] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 1, + "method": "initialize", + "params": { + "rootUri": "$URI{.}", + "capabilities": {} + } + }, + "wait": [ + { + "id": 1, + "result": { + "capabilities": { + "executeCommandProvider": { + "commands": ["", "als-refactor-add-parameters"] + } + } + } + } + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "method": "initialized", + "params": {} + }, + "wait": [] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "method": "textDocument/didOpen", + "params": { + "textDocument": { + "uri": "$URI{main.adb}", + "languageId": "ada", + "version": 1, + "text": "procedure Main is\nbegin\n null;\nend Main;\n" + } + } + }, + "wait": [] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 2, + "method": "workspace/executeCommand", + "params": { + "command": "als-source-dirs" + } + }, + "wait": [ + { + "method": "textDocument/publishDiagnostics", + "params": { + "uri": "$URI{main.adb}", + "diagnostics": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "severity": 1, + "source": "project", + "message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file." + } + ] + } + } + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 6, + "method": "textDocument/codeAction", + "params": { + "textDocument": { + "uri": "$URI{main.adb}" + }, + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "context": { + "diagnostics": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file.", + "severity": 1, + "source": "project" + } + ], + "triggerKind": 2 + } + } + }, + "wait": [] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 13, + "method": "textDocument/codeAction", + "params": { + "textDocument": { + "uri": "$URI{main.adb}" + }, + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "context": { + "diagnostics": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file.", + "severity": 1, + "source": "project" + } + ], + "triggerKind": 2 + } + } + }, + "wait": [ + { + "id": 13, + "result": [ + { + "title": "Open settings for ada.projectFile", + "kind": "quickfix", + "diagnostics": [ + { + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 0 + } + }, + "severity": 1, + "source": "project", + "message": "No project was loaded, because more than one project file has been found in the root directory. Please change configuration to point a correct project file." + } + ], + "isPreferred": true, + "command": { + "title": "Open settings for ada.projectFile", + "command": "workbench.action.openSettings", + "arguments": "ada.projectFile" + } + } + ] + } + ] + } + }, + { + "stop": { + "exit_code": 0 + } + } +] diff --git a/testsuite/ada_lsp/project_config.multiple_project_diagnostics/test.yaml b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/test.yaml new file mode 100644 index 000000000..523c27b84 --- /dev/null +++ b/testsuite/ada_lsp/project_config.multiple_project_diagnostics/test.yaml @@ -0,0 +1 @@ +title: 'project_config.multiple_project_diagnostics'