diff --git a/source/gpr/lsp-gpr_files.adb b/source/gpr/lsp-gpr_files.adb index 565785145..ef2f7cbec 100644 --- a/source/gpr/lsp-gpr_files.adb +++ b/source/gpr/lsp-gpr_files.adb @@ -505,7 +505,10 @@ package body LSP.GPR_Files is New_Symbol : Symbol := (New_Id, - Current_Symbol.Id, + (if Kind = K_When + and then Current_Symbol.Kind = K_When + then Current_Symbol.Parent_Id + else Current_Symbol.Id), Token.Ref, Kind, To_Valid_Name (Name), diff --git a/testsuite/gpr_lsp/get_symbols_hierarchy/case_support.gpr b/testsuite/gpr_lsp/get_symbols_hierarchy/case_support.gpr new file mode 100644 index 000000000..59a1463de --- /dev/null +++ b/testsuite/gpr_lsp/get_symbols_hierarchy/case_support.gpr @@ -0,0 +1,42 @@ +project Case_Support is + A := ""; + case A is + when "a" => + B := ""; + when others => + C := ""; + case A is + when "a" => + D := ""; + when others => + E := ""; + end case; + F := ""; + end case; + G := ""; + case G is + when "" => + H := ""; + -- testing auto case/when closing on package declaration + package Compiler is + I := ""; + case H is + when "" => + J := ""; + case J is + -- testing auto case closing on package declaration + package Linker is + K := ""; + -- testing package auto closing on package declaration + package Builder is + L := ""; + -- testing package auto closing on type declaration + type T1 is ("a"); + M := ""; + case M is + when "" => + N := ""; + -- testing case auto closing on type declaration + type T2 is (""); + O := ""; +end Case_Support; \ No newline at end of file diff --git a/testsuite/gpr_lsp/get_symbols_hierarchy/test.json b/testsuite/gpr_lsp/get_symbols_hierarchy/test.json index 0d8b99ecf..e3d27b51d 100644 --- a/testsuite/gpr_lsp/get_symbols_hierarchy/test.json +++ b/testsuite/gpr_lsp/get_symbols_hierarchy/test.json @@ -659,6 +659,876 @@ ] } }, + { + "send": { + "request": { + "jsonrpc": "2.0", + "id": "3", + "method": "textDocument/documentSymbol", + "params": { + "textDocument": { + "uri": "$URI{case_support.gpr}" + } + } + }, + "wait": [ + { + "jsonrpc": "2.0", + "id": "3", + "result": [ + { + "name": "Case_Support", + "kind": 2, + "range": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 7 + } + }, + "selectionRange": { + "start": { + "line": 0, + "character": 0 + }, + "end": { + "line": 0, + "character": 7 + } + }, + "children": [ + { + "name": "A", + "kind": 13, + "range": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 3 + } + }, + "selectionRange": { + "start": { + "line": 1, + "character": 2 + }, + "end": { + "line": 1, + "character": 3 + } + } + }, + { + "name": "case A", + "kind": 4, + "range": { + "start": { + "line": 2, + "character": 2 + }, + "end": { + "line": 2, + "character": 6 + } + }, + "selectionRange": { + "start": { + "line": 2, + "character": 2 + }, + "end": { + "line": 2, + "character": 6 + } + }, + "children": [ + { + "name": "when \"a\"", + "kind": 4, + "range": { + "start": { + "line": 3, + "character": 4 + }, + "end": { + "line": 3, + "character": 8 + } + }, + "selectionRange": { + "start": { + "line": 3, + "character": 4 + }, + "end": { + "line": 3, + "character": 8 + } + }, + "children": [ + { + "name": "B", + "kind": 13, + "range": { + "start": { + "line": 4, + "character": 6 + }, + "end": { + "line": 4, + "character": 7 + } + }, + "selectionRange": { + "start": { + "line": 4, + "character": 6 + }, + "end": { + "line": 4, + "character": 7 + } + } + } + ] + }, + { + "name": "when others", + "kind": 4, + "range": { + "start": { + "line": 5, + "character": 4 + }, + "end": { + "line": 5, + "character": 8 + } + }, + "selectionRange": { + "start": { + "line": 5, + "character": 4 + }, + "end": { + "line": 5, + "character": 8 + } + }, + "children": [ + { + "name": "C", + "kind": 13, + "range": { + "start": { + "line": 6, + "character": 6 + }, + "end": { + "line": 6, + "character": 7 + } + }, + "selectionRange": { + "start": { + "line": 6, + "character": 6 + }, + "end": { + "line": 6, + "character": 7 + } + } + }, + { + "name": "case A", + "kind": 4, + "range": { + "start": { + "line": 7, + "character": 6 + }, + "end": { + "line": 7, + "character": 10 + } + }, + "selectionRange": { + "start": { + "line": 7, + "character": 6 + }, + "end": { + "line": 7, + "character": 10 + } + }, + "children": [ + { + "name": "when \"a\"", + "kind": 4, + "range": { + "start": { + "line": 8, + "character": 8 + }, + "end": { + "line": 8, + "character": 12 + } + }, + "selectionRange": { + "start": { + "line": 8, + "character": 8 + }, + "end": { + "line": 8, + "character": 12 + } + }, + "children": [ + { + "name": "D", + "kind": 13, + "range": { + "start": { + "line": 9, + "character": 10 + }, + "end": { + "line": 9, + "character": 11 + } + }, + "selectionRange": { + "start": { + "line": 9, + "character": 10 + }, + "end": { + "line": 9, + "character": 11 + } + } + } + ] + }, + { + "name": "when others", + "kind": 4, + "range": { + "start": { + "line": 10, + "character": 8 + }, + "end": { + "line": 10, + "character": 12 + } + }, + "selectionRange": { + "start": { + "line": 10, + "character": 8 + }, + "end": { + "line": 10, + "character": 12 + } + }, + "children": [ + { + "name": "E", + "kind": 13, + "range": { + "start": { + "line": 11, + "character": 10 + }, + "end": { + "line": 11, + "character": 11 + } + }, + "selectionRange": { + "start": { + "line": 11, + "character": 10 + }, + "end": { + "line": 11, + "character": 11 + } + } + } + ] + } + ] + }, + { + "name": "F", + "kind": 13, + "range": { + "start": { + "line": 13, + "character": 6 + }, + "end": { + "line": 13, + "character": 7 + } + }, + "selectionRange": { + "start": { + "line": 13, + "character": 6 + }, + "end": { + "line": 13, + "character": 7 + } + } + } + ] + } + ] + }, + { + "name": "G", + "kind": 13, + "range": { + "start": { + "line": 15, + "character": 2 + }, + "end": { + "line": 15, + "character": 3 + } + }, + "selectionRange": { + "start": { + "line": 15, + "character": 2 + }, + "end": { + "line": 15, + "character": 3 + } + } + }, + { + "name": "case G", + "kind": 4, + "range": { + "start": { + "line": 16, + "character": 2 + }, + "end": { + "line": 16, + "character": 6 + } + }, + "selectionRange": { + "start": { + "line": 16, + "character": 2 + }, + "end": { + "line": 16, + "character": 6 + } + }, + "children": [ + { + "name": "when \"\"", + "kind": 4, + "range": { + "start": { + "line": 17, + "character": 4 + }, + "end": { + "line": 17, + "character": 8 + } + }, + "selectionRange": { + "start": { + "line": 17, + "character": 4 + }, + "end": { + "line": 17, + "character": 8 + } + }, + "children": [ + { + "name": "H", + "kind": 13, + "range": { + "start": { + "line": 18, + "character": 6 + }, + "end": { + "line": 18, + "character": 7 + } + }, + "selectionRange": { + "start": { + "line": 18, + "character": 6 + }, + "end": { + "line": 18, + "character": 7 + } + } + } + ] + } + ] + }, + { + "name": "Compiler", + "kind": 4, + "range": { + "start": { + "line": 20, + "character": 10 + }, + "end": { + "line": 20, + "character": 18 + } + }, + "selectionRange": { + "start": { + "line": 20, + "character": 10 + }, + "end": { + "line": 20, + "character": 18 + } + }, + "children": [ + { + "name": "I", + "kind": 13, + "range": { + "start": { + "line": 21, + "character": 4 + }, + "end": { + "line": 21, + "character": 5 + } + }, + "selectionRange": { + "start": { + "line": 21, + "character": 4 + }, + "end": { + "line": 21, + "character": 5 + } + } + }, + { + "name": "case H", + "kind": 4, + "range": { + "start": { + "line": 22, + "character": 4 + }, + "end": { + "line": 22, + "character": 8 + } + }, + "selectionRange": { + "start": { + "line": 22, + "character": 4 + }, + "end": { + "line": 22, + "character": 8 + } + }, + "children": [ + { + "name": "when \"\"", + "kind": 4, + "range": { + "start": { + "line": 23, + "character": 6 + }, + "end": { + "line": 23, + "character": 10 + } + }, + "selectionRange": { + "start": { + "line": 23, + "character": 6 + }, + "end": { + "line": 23, + "character": 10 + } + }, + "children": [ + { + "name": "J", + "kind": 13, + "range": { + "start": { + "line": 24, + "character": 8 + }, + "end": { + "line": 24, + "character": 9 + } + }, + "selectionRange": { + "start": { + "line": 24, + "character": 8 + }, + "end": { + "line": 24, + "character": 9 + } + } + }, + { + "name": "case J", + "kind": 4, + "range": { + "start": { + "line": 25, + "character": 8 + }, + "end": { + "line": 25, + "character": 12 + } + }, + "selectionRange": { + "start": { + "line": 25, + "character": 8 + }, + "end": { + "line": 25, + "character": 12 + } + } + } + ] + } + ] + } + ] + }, + { + "name": "Linker", + "kind": 4, + "range": { + "start": { + "line": 27, + "character": 10 + }, + "end": { + "line": 27, + "character": 16 + } + }, + "selectionRange": { + "start": { + "line": 27, + "character": 10 + }, + "end": { + "line": 27, + "character": 16 + } + }, + "children": [ + { + "name": "K", + "kind": 13, + "range": { + "start": { + "line": 28, + "character": 4 + }, + "end": { + "line": 28, + "character": 5 + } + }, + "selectionRange": { + "start": { + "line": 28, + "character": 4 + }, + "end": { + "line": 28, + "character": 5 + } + } + } + ] + }, + { + "name": "Builder", + "kind": 4, + "range": { + "start": { + "line": 30, + "character": 10 + }, + "end": { + "line": 30, + "character": 17 + } + }, + "selectionRange": { + "start": { + "line": 30, + "character": 10 + }, + "end": { + "line": 30, + "character": 17 + } + }, + "children": [ + { + "name": "L", + "kind": 13, + "range": { + "start": { + "line": 31, + "character": 4 + }, + "end": { + "line": 31, + "character": 5 + } + }, + "selectionRange": { + "start": { + "line": 31, + "character": 4 + }, + "end": { + "line": 31, + "character": 5 + } + } + } + ] + }, + { + "name": "T1", + "kind": 10, + "range": { + "start": { + "line": 33, + "character": 7 + }, + "end": { + "line": 33, + "character": 9 + } + }, + "selectionRange": { + "start": { + "line": 33, + "character": 7 + }, + "end": { + "line": 33, + "character": 9 + } + } + }, + { + "name": "M", + "kind": 13, + "range": { + "start": { + "line": 34, + "character": 2 + }, + "end": { + "line": 34, + "character": 3 + } + }, + "selectionRange": { + "start": { + "line": 34, + "character": 2 + }, + "end": { + "line": 34, + "character": 3 + } + } + }, + { + "name": "case M", + "kind": 4, + "range": { + "start": { + "line": 35, + "character": 2 + }, + "end": { + "line": 35, + "character": 6 + } + }, + "selectionRange": { + "start": { + "line": 35, + "character": 2 + }, + "end": { + "line": 35, + "character": 6 + } + }, + "children": [ + { + "name": "when \"\"", + "kind": 4, + "range": { + "start": { + "line": 36, + "character": 4 + }, + "end": { + "line": 36, + "character": 8 + } + }, + "selectionRange": { + "start": { + "line": 36, + "character": 4 + }, + "end": { + "line": 36, + "character": 8 + } + }, + "children": [ + { + "name": "N", + "kind": 13, + "range": { + "start": { + "line": 37, + "character": 6 + }, + "end": { + "line": 37, + "character": 7 + } + }, + "selectionRange": { + "start": { + "line": 37, + "character": 6 + }, + "end": { + "line": 37, + "character": 7 + } + } + } + ] + } + ] + }, + { + "name": "T2", + "kind": 10, + "range": { + "start": { + "line": 39, + "character": 7 + }, + "end": { + "line": 39, + "character": 9 + } + }, + "selectionRange": { + "start": { + "line": 39, + "character": 7 + }, + "end": { + "line": 39, + "character": 9 + } + } + }, + { + "name": "O", + "kind": 13, + "range": { + "start": { + "line": 40, + "character": 2 + }, + "end": { + "line": 40, + "character": 3 + } + }, + "selectionRange": { + "start": { + "line": 40, + "character": 2 + }, + "end": { + "line": 40, + "character": 3 + } + } + } + ] + } + ] + } + ] + } + }, { "send": { "request": {