@@ -50,7 +50,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
50
50
51
51
defp list_symbols ( src ) do
52
52
case ElixirSense . string_to_quoted ( src , 1 , @ max_parser_errors , line: 1 , token_metadata: true ) do
53
- { :ok , quoted_form } -> { :ok , extract_modules ( quoted_form ) }
53
+ { :ok , quoted_form } -> { :ok , extract_modules ( quoted_form ) |> Enum . reject ( & is_nil / 1 ) }
54
54
{ :error , _error } -> { :error , :compilation_error }
55
55
end
56
56
end
@@ -81,7 +81,7 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
81
81
82
82
defp extract_symbol ( _module_name , { defname , location , arguments } )
83
83
when defname in [ :defmodule , :defprotocol ] do
84
- { module_name , module_name_location , module_body } =
84
+ module_info =
85
85
case arguments do
86
86
# Handles `defmodule do\nend` type compile errors
87
87
[ [ do: module_body ] ] ->
@@ -101,36 +101,41 @@ defmodule ElixirLS.LanguageServer.Providers.DocumentSymbols do
101
101
# TODO extract module name location from Code.Fragment.surround_context?
102
102
# TODO better selection ranges for defimpl?
103
103
{ extract_module_name ( module_expression ) , module_name_location , module_body }
104
+ _ -> nil
104
105
end
105
106
106
- mod_defns =
107
- case module_body do
108
- { :__block__ , [ ] , mod_defns } -> mod_defns
109
- stmt -> [ stmt ]
110
- end
107
+ if module_info do
108
+ { module_name , module_name_location , module_body } = module_info
111
109
112
- module_symbols =
113
- mod_defns
114
- |> Enum . map ( & extract_symbol ( module_name , & 1 ) )
115
- |> Enum . reject ( & is_nil / 1 )
116
- |> Enum . map ( fn info ->
117
- % { info | location: Keyword . put ( info . location , :parent_location , location ) }
118
- end )
119
-
120
- type =
121
- case defname do
122
- :defmodule -> :module
123
- :defprotocol -> :interface
124
- end
110
+ mod_defns =
111
+ case module_body do
112
+ { :__block__ , [ ] , mod_defns } -> mod_defns
113
+ stmt -> [ stmt ]
114
+ end
125
115
126
- % Info {
127
- type: type ,
128
- name: module_name ,
129
- location: location ,
130
- selection_location: module_name_location ,
131
- children: module_symbols ,
132
- symbol: module_name
133
- }
116
+ module_symbols =
117
+ mod_defns
118
+ |> Enum . map ( & extract_symbol ( module_name , & 1 ) )
119
+ |> Enum . reject ( & is_nil / 1 )
120
+ |> Enum . map ( fn info ->
121
+ % { info | location: Keyword . put ( info . location , :parent_location , location ) }
122
+ end )
123
+
124
+ type =
125
+ case defname do
126
+ :defmodule -> :module
127
+ :defprotocol -> :interface
128
+ end
129
+
130
+ % Info {
131
+ type: type ,
132
+ name: module_name ,
133
+ location: location ,
134
+ selection_location: module_name_location ,
135
+ children: module_symbols ,
136
+ symbol: module_name
137
+ }
138
+ end
134
139
end
135
140
136
141
# Protocol implementations
0 commit comments