@@ -24,6 +24,45 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
2424 results
2525 end
2626
27+ # Helper functions to make tests robust across Elixir versions by extracting only the essential fields
28+ defp extract_document_symbol_fields ( symbol ) do
29+ base_fields = % {
30+ name: symbol . name ,
31+ kind: symbol . kind ,
32+ range: symbol . range ,
33+ selection_range: symbol . selection_range ,
34+ children: Enum . map ( symbol . children || [ ] , & extract_document_symbol_fields / 1 )
35+ }
36+
37+ case symbol . detail do
38+ nil -> base_fields
39+ detail -> Map . put ( base_fields , :detail , detail )
40+ end
41+ end
42+
43+ defp extract_symbol_information_fields ( symbol ) do
44+ base_fields = % {
45+ name: symbol . name ,
46+ kind: symbol . kind ,
47+ range: symbol . location . range
48+ }
49+
50+ case symbol . container_name do
51+ nil -> base_fields
52+ container_name -> Map . put ( base_fields , :container_name , container_name )
53+ end
54+ end
55+
56+ defp assert_document_symbols_match ( actual , expected ) when is_list ( actual ) do
57+ actual_extracted = Enum . map ( actual , & extract_document_symbol_fields / 1 )
58+ assert actual_extracted == expected
59+ end
60+
61+ defp assert_symbol_information_match ( actual , expected ) when is_list ( actual ) do
62+ actual_extracted = Enum . map ( actual , & extract_symbol_information_fields / 1 )
63+ assert actual_extracted == expected
64+ end
65+
2766 test "returns hierarchical symbol information" do
2867 uri = "file:///project/file.ex"
2968 text = ~S[
@@ -2095,37 +2134,41 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
20952134
20962135 parser_context = ParserContextBuilder . from_string ( text )
20972136
2098- assert { :ok ,
2099- [
2100- % GenLSP.Structures.DocumentSymbol {
2101- children: [ ] ,
2102- kind: 20 ,
2103- name: "config :logger :console" ,
2104- range: range ( 1 , 0 , 5 , 23 ) ,
2105- selection_range: range ( 1 , 0 , 5 , 23 )
2106- } ,
2107- % GenLSP.Structures.DocumentSymbol {
2108- children: [ ] ,
2109- kind: 20 ,
2110- name: "config :app :key" ,
2111- range: range ( 6 , 0 , 6 , 25 ) ,
2112- selection_range: range ( 6 , 0 , 6 , 25 )
2113- } ,
2114- % GenLSP.Structures.DocumentSymbol {
2115- children: [ ] ,
2116- kind: 20 ,
2117- name: "config :my_app [:ecto_repos]" ,
2118- range: range ( 7 , 0 , 8 , 26 ) ,
2119- selection_range: range ( 7 , 0 , 8 , 26 )
2120- } ,
2121- % GenLSP.Structures.DocumentSymbol {
2122- children: [ ] ,
2123- kind: 20 ,
2124- name: "config :my_app MyApp.Repo" ,
2125- range: range ( 9 , 0 , 11 , 22 ) ,
2126- selection_range: range ( 9 , 0 , 11 , 22 )
2127- }
2128- ] } = get_document_symbols ( uri , parser_context , true )
2137+ assert { :ok , document_symbols } = get_document_symbols ( uri , parser_context , true )
2138+ assert length ( document_symbols ) == 4
2139+
2140+ expected_symbols = [
2141+ % {
2142+ children: [ ] ,
2143+ kind: 20 ,
2144+ name: "config :logger :console" ,
2145+ range: range ( 1 , 0 , 5 , 23 ) ,
2146+ selection_range: range ( 1 , 0 , 5 , 23 )
2147+ } ,
2148+ % {
2149+ children: [ ] ,
2150+ kind: 20 ,
2151+ name: "config :app :key" ,
2152+ range: range ( 6 , 0 , 6 , 25 ) ,
2153+ selection_range: range ( 6 , 0 , 6 , 25 )
2154+ } ,
2155+ % {
2156+ children: [ ] ,
2157+ kind: 20 ,
2158+ name: "config :my_app [:ecto_repos]" ,
2159+ range: range ( 7 , 0 , 8 , 26 ) ,
2160+ selection_range: range ( 7 , 0 , 8 , 26 )
2161+ } ,
2162+ % {
2163+ children: [ ] ,
2164+ kind: 20 ,
2165+ name: "config :my_app MyApp.Repo" ,
2166+ range: range ( 9 , 0 , 11 , 22 ) ,
2167+ selection_range: range ( 9 , 0 , 11 , 22 )
2168+ }
2169+ ]
2170+
2171+ assert_document_symbols_match ( document_symbols , expected_symbols )
21292172 end
21302173
21312174 test "[flat] handles config" do
@@ -2147,37 +2190,33 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbolsTest do
21472190
21482191 parser_context = ParserContextBuilder . from_string ( text )
21492192
2150- assert { :ok ,
2151- [
2152- % GenLSP.Structures.SymbolInformation {
2153- name: "config :logger :console" ,
2154- kind: 20 ,
2155- location: % {
2156- range: range ( 1 , 0 , 5 , 23 )
2157- }
2158- } ,
2159- % GenLSP.Structures.SymbolInformation {
2160- name: "config :app :key" ,
2161- kind: 20 ,
2162- location: % {
2163- range: range ( 6 , 0 , 6 , 25 )
2164- }
2165- } ,
2166- % GenLSP.Structures.SymbolInformation {
2167- name: "config :my_app [:ecto_repos]" ,
2168- kind: 20 ,
2169- location: % {
2170- range: range ( 7 , 0 , 8 , 26 )
2171- }
2172- } ,
2173- % GenLSP.Structures.SymbolInformation {
2174- name: "config :my_app MyApp.Repo" ,
2175- kind: 20 ,
2176- location: % {
2177- range: range ( 9 , 0 , 11 , 22 )
2178- }
2179- }
2180- ] } = get_document_symbols ( uri , parser_context , false )
2193+ assert { :ok , symbol_information } = get_document_symbols ( uri , parser_context , false )
2194+ assert length ( symbol_information ) == 4
2195+
2196+ expected_symbols = [
2197+ % {
2198+ name: "config :logger :console" ,
2199+ kind: 20 ,
2200+ range: range ( 1 , 0 , 5 , 23 )
2201+ } ,
2202+ % {
2203+ name: "config :app :key" ,
2204+ kind: 20 ,
2205+ range: range ( 6 , 0 , 6 , 25 )
2206+ } ,
2207+ % {
2208+ name: "config :my_app [:ecto_repos]" ,
2209+ kind: 20 ,
2210+ range: range ( 7 , 0 , 8 , 26 )
2211+ } ,
2212+ % {
2213+ name: "config :my_app MyApp.Repo" ,
2214+ kind: 20 ,
2215+ range: range ( 9 , 0 , 11 , 22 )
2216+ }
2217+ ]
2218+
2219+ assert_symbol_information_match ( symbol_information , expected_symbols )
21812220 end
21822221
21832222 test "[nested] handles a file with a top-level module without a name" do
0 commit comments