@@ -162,12 +162,17 @@ defmodule Mix.Task.Compiler do
162162 """
163163 @ callback manifests ( ) :: [ Path . t ( ) ]
164164
165+ @ doc """
166+ Lists persisted diagnostics from the compiler.
167+ """
168+ @ callback diagnostics ( ) :: [ Diagnostic . t ( ) ]
169+
165170 @ doc """
166171 Removes build artifacts and manifests.
167172 """
168173 @ callback clean ( ) :: any
169174
170- @ optional_callbacks clean: 0 , manifests: 0
175+ @ optional_callbacks clean: 0 , manifests: 0 , diagnostics: 0
171176
172177 @ doc """
173178 Adds a callback that runs after a given compiler.
@@ -199,6 +204,63 @@ defmodule Mix.Task.Compiler do
199204 end
200205 end
201206
207+ @ doc """
208+ Returns all compilers for the current project.
209+ """
210+ def compilers ( config \\ Mix.Project . config ( ) ) do
211+ compilers = config [ :compilers ] || Mix . compilers ( )
212+
213+ if :xref in compilers do
214+ IO . warn (
215+ "the :xref compiler is deprecated, please remove it from your mix.exs :compilers options"
216+ )
217+
218+ List . delete ( compilers , :xref )
219+ else
220+ compilers
221+ end
222+ |> maybe_prepend ( :leex )
223+ |> maybe_prepend ( :yecc )
224+ end
225+
226+ defp maybe_prepend ( compilers , compiler ) do
227+ if compiler in compilers do
228+ compilers
229+ else
230+ [ compiler | compilers ]
231+ end
232+ end
233+
234+ @ doc """
235+ Lists manifest files for all compilers in the current project.
236+ """
237+ def manifests ( config \\ Mix.Project . config ( ) ) do
238+ Enum . flat_map ( compilers ( config ) , fn compiler ->
239+ module = Mix.Task . get ( "compile.#{ compiler } " )
240+
241+ if module && function_exported? ( module , :manifests , 0 ) do
242+ module . manifests ( )
243+ else
244+ [ ]
245+ end
246+ end )
247+ end
248+
249+ @ doc """
250+ Lists persisted diagnostics from all compilers in the current project.
251+ """
252+ def diagnostics ( config \\ Mix.Project . config ( ) ) do
253+ Enum . flat_map ( compilers ( config ) , fn compiler ->
254+ module = Mix.Task . get ( "compile.#{ compiler } " )
255+
256+ if module && function_exported? ( module , :diagnostics , 0 ) do
257+ module . diagnostics ( )
258+ else
259+ [ ]
260+ end
261+ end )
262+ end
263+
202264 # Normalize the compiler result to a diagnostic tuple.
203265 @ doc false
204266 def normalize ( result , name ) do
0 commit comments