From 4dd40555353996b9d9e3a847435089c5041f7903 Mon Sep 17 00:00:00 2001 From: Nicolas Setton Date: Tue, 9 Apr 2024 11:37:22 +0100 Subject: [PATCH] Add test for the hover on incomplete types The hover should get the complete type when it is in the public part. For #1320 --- .../hover.incomplete_types/default.gpr | 2 + .../ada_lsp/hover.incomplete_types/main.adb | 9 + .../ada_lsp/hover.incomplete_types/p.ads | 17 ++ .../ada_lsp/hover.incomplete_types/test.json | 285 ++++++++++++++++++ .../ada_lsp/hover.incomplete_types/test.yaml | 1 + 5 files changed, 314 insertions(+) create mode 100644 testsuite/ada_lsp/hover.incomplete_types/default.gpr create mode 100644 testsuite/ada_lsp/hover.incomplete_types/main.adb create mode 100644 testsuite/ada_lsp/hover.incomplete_types/p.ads create mode 100644 testsuite/ada_lsp/hover.incomplete_types/test.json create mode 100644 testsuite/ada_lsp/hover.incomplete_types/test.yaml diff --git a/testsuite/ada_lsp/hover.incomplete_types/default.gpr b/testsuite/ada_lsp/hover.incomplete_types/default.gpr new file mode 100644 index 000000000..ee0d3ea36 --- /dev/null +++ b/testsuite/ada_lsp/hover.incomplete_types/default.gpr @@ -0,0 +1,2 @@ +project Default is +end Default; \ No newline at end of file diff --git a/testsuite/ada_lsp/hover.incomplete_types/main.adb b/testsuite/ada_lsp/hover.incomplete_types/main.adb new file mode 100644 index 000000000..42872cb89 --- /dev/null +++ b/testsuite/ada_lsp/hover.incomplete_types/main.adb @@ -0,0 +1,9 @@ +with P; + +procedure Main +is + Foo : P.Incomplete; + Bar : P.Incomplete_2; +begin + null; +end Main; diff --git a/testsuite/ada_lsp/hover.incomplete_types/p.ads b/testsuite/ada_lsp/hover.incomplete_types/p.ads new file mode 100644 index 000000000..294870995 --- /dev/null +++ b/testsuite/ada_lsp/hover.incomplete_types/p.ads @@ -0,0 +1,17 @@ +package P is + type Incomplete; + type Incomplete_2; + + type Something is record + X : Incomplete; + end record; + + type Incomplete is record + Y : Integer; + end record; + +private + type Incomplete_2 is record + Z : Integer; + end record; +end P; \ No newline at end of file diff --git a/testsuite/ada_lsp/hover.incomplete_types/test.json b/testsuite/ada_lsp/hover.incomplete_types/test.json new file mode 100644 index 000000000..612b2acc5 --- /dev/null +++ b/testsuite/ada_lsp/hover.incomplete_types/test.json @@ -0,0 +1,285 @@ +[ + { + "comment": [ + "This test checks that the textDocument/hover request works fine ", + "on predefined entities (pragmas, aspects, attributes)." + ] + }, + { + "start": { + "cmd": ["${ALS}"] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 1, + "method": "initialize", + "params": { + "processId": 2357134, + "rootUri": "$URI{.}", + "capabilities": { + "workspace": { + "applyEdit": true, + "workspaceEdit": { + "documentChanges": true, + "resourceOperations": ["rename"] + } + }, + "textDocument": { + "synchronization": {}, + "completion": { + "dynamicRegistration": true, + "completionItem": { + "snippetSupport": false, + "documentationFormat": ["plaintext", "markdown"], + "resolveSupport": { + "properties": ["detail", "documentation"] + } + } + }, + "hover": {}, + "signatureHelp": {}, + "declaration": {}, + "definition": {}, + "typeDefinition": {}, + "implementation": {}, + "documentSymbol": { + "hierarchicalDocumentSymbolSupport": true + }, + "codeAction": { + "codeActionLiteralSupport": { + "codeActionKind": { + "valueSet": [ + "", + "quickfix", + "refactor", + "refactor.extract", + "refactor.inline", + "refactor.rewrite", + "source", + "source.organizeImports" + ] + } + } + }, + "formatting": { + "dynamicRegistration": false + }, + "rangeFormatting": { + "dynamicRegistration": false + }, + "onTypeFormatting": { + "dynamicRegistration": false + }, + "publishDiagnostics": { + "relatedInformation": true + }, + "foldingRange": { + "lineFoldingOnly": true + } + }, + "experimental": { + "advanced_refactorings": ["add_parameter"] + } + } + } + }, + "wait": [ + { + "id": 1, + "result": { + "capabilities": { + "textDocumentSync": 2, + "completionProvider": { + "triggerCharacters": [".", ",", "'", "("], + "resolveProvider": true + }, + "hoverProvider": true, + "signatureHelpProvider": { + "triggerCharacters": [",", "("], + "retriggerCharacters": ["\b"] + }, + "declarationProvider": true, + "definitionProvider": true, + "typeDefinitionProvider": true, + "implementationProvider": true, + "referencesProvider": true, + "documentHighlightProvider": true, + "documentSymbolProvider": true, + "codeActionProvider": { + "workDoneProgress": false, + "codeActionKinds": ["quickfix", "refactor.rewrite"], + "resolveProvider": false + }, + "workspaceSymbolProvider": true, + "documentFormattingProvider": true, + "documentRangeFormattingProvider": true, + "documentOnTypeFormattingProvider": { + "firstTriggerCharacter": "\n" + }, + "renameProvider": { + "prepareProvider": true + }, + "foldingRangeProvider": true, + "executeCommandProvider": { + "commands": ["", "als-other-file"] + }, + "callHierarchyProvider": true, + "semanticTokensProvider": { + "legend": { + "tokenTypes": [], + "tokenModifiers": [] + }, + "range": true, + "full": true + }, + "workspace": {}, + "alsReferenceKinds": ["", "reference"] + } + } + } + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "method": "initialized" + }, + "wait": [] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "method": "workspace/didChangeConfiguration", + "params": { + "settings": { + "ada": { + "scenarioVariables": {}, + "defaultCharset": "ISO-8859-1", + "enableDiagnostics": false, + "followSymlinks": false, + "documentationStyle": "gnat", + "namedNotationThreshold": 3, + "foldComments": false + } + } + } + }, + "wait": [] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "method": "textDocument/didOpen", + "params": { + "textDocument": { + "uri": "$URI{main.adb}", + "languageId": "Ada", + "version": 0, + "text": "with P;\n\nprocedure Main\nis\n Foo : P.Incomplete;\n Bar : P.Incomplete_2;\nbegin\n null;\nend Main;" + } + } + }, + "wait": [] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 4, + "method": "textDocument/hover", + "params": { + "textDocument": { + "uri": "$URI{main.adb}" + }, + "position": { + "line": 4, + "character": 14 + } + } + }, + "wait": [ + { + "id": 4, + "result": { + "contents": [ + { + "language": "ada", + "value": "type Incomplete is record\n Y : Integer;\nend record;" + }, + "at p.ads (2:4)" + ] + } + } + ] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 5, + "method": "textDocument/hover", + "params": { + "textDocument": { + "uri": "$URI{main.adb}" + }, + "position": { + "line": 5, + "character": 14 + } + } + }, + "wait": [ + { + "id": 5, + "result": null + } + ] + } + }, + + { + "send": { + "request": { + "jsonrpc": "2.0", + "method": "textDocument/didClose", + "params": { + "textDocument": { + "uri": "$URI{main.adb}" + } + } + }, + "wait": [] + } + }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": 7, + "method": "shutdown" + }, + "wait": [ + { + "id": 7, + "result": null + } + ] + } + }, + { + "stop": { + "exit_code": 0 + } + } +] diff --git a/testsuite/ada_lsp/hover.incomplete_types/test.yaml b/testsuite/ada_lsp/hover.incomplete_types/test.yaml new file mode 100644 index 000000000..9ef50e18d --- /dev/null +++ b/testsuite/ada_lsp/hover.incomplete_types/test.yaml @@ -0,0 +1 @@ +title: 'hover.predefined_entities'