@@ -20,17 +20,20 @@ defmodule ElixirLS.LanguageServer.MixProjectCache do
2020 GenServer . call ( __MODULE__ , :loaded? )
2121 end
2222
23- @ spec get ( ) :: module | nil
23+ @ spec get ( ) :: { :ok , module | nil } | { :error , :not_loaded }
2424 def get do
2525 GenServer . call ( __MODULE__ , { :get , :get } )
2626 end
2727
2828 @ spec get! ( ) :: module
2929 def get! do
30- get ( ) || raise Mix.NoProjectError , [ ]
30+ case get ( ) do
31+ { :ok , project } when not is_nil ( project ) -> project
32+ _ -> raise Mix.NoProjectError , [ ]
33+ end
3134 end
3235
33- @ spec project_file ( ) :: binary | nil
36+ @ spec project_file ( ) :: { :ok , binary | nil } | { :error , :not_loaded }
3437 def project_file ( ) do
3538 GenServer . call ( __MODULE__ , { :get , :project_file } )
3639 end
@@ -39,47 +42,47 @@ defmodule ElixirLS.LanguageServer.MixProjectCache do
3942 # @spec parent_umbrella_project_file() :: binary | nil
4043 # defdelegate parent_umbrella_project_file(), to: Mix.ProjectStack
4144
42- @ spec config ( ) :: keyword
45+ @ spec config ( ) :: { :ok , keyword } | { :error , :not_loaded }
4346 def config do
4447 GenServer . call ( __MODULE__ , { :get , :config } )
4548 end
4649
47- @ spec config_files ( ) :: [ Path . t ( ) ]
50+ @ spec config_files ( ) :: { :ok , [ Path . t ( ) ] } | { :error , :not_loaded }
4851 def config_files do
4952 GenServer . call ( __MODULE__ , { :get , :config_files } )
5053 end
5154
52- @ spec config_mtime ( ) :: posix_mtime when posix_mtime: integer ( )
55+ @ spec config_mtime ( ) :: { :ok , posix_mtime } | { :error , :not_loaded } when posix_mtime: integer ( )
5356 def config_mtime do
5457 GenServer . call ( __MODULE__ , { :get , :config_mtime } )
5558 end
5659
57- @ spec umbrella? ( ) :: boolean
60+ @ spec umbrella? ( ) :: { :ok , boolean } | { :error , :not_loaded }
5861 def umbrella? ( ) do
5962 GenServer . call ( __MODULE__ , { :get , :umbrella? } )
6063 end
6164
62- @ spec apps_paths ( ) :: % { optional ( atom ) => Path . t ( ) } | nil
65+ @ spec apps_paths ( ) :: { :ok , % { optional ( atom ) => Path . t ( ) } | nil } | { :error , :not_loaded }
6366 def apps_paths ( ) do
6467 GenServer . call ( __MODULE__ , { :get , :apps_paths } )
6568 end
6669
67- @ spec deps_path ( ) :: Path . t ( )
70+ @ spec deps_path ( ) :: { :ok , Path . t ( ) } | { :error , :not_loaded }
6871 def deps_path ( ) do
6972 GenServer . call ( __MODULE__ , { :get , :deps_path } )
7073 end
7174
72- @ spec deps_apps ( ) :: [ atom ( ) ]
75+ @ spec deps_apps ( ) :: { :ok , [ atom ( ) ] } | { :error , :not_loaded }
7376 def deps_apps ( ) do
7477 GenServer . call ( __MODULE__ , { :get , :deps_apps } )
7578 end
7679
77- @ spec deps_scms ( ) :: % { optional ( atom ) => Mix.SCM . t ( ) }
80+ @ spec deps_scms ( ) :: { :ok , % { optional ( atom ) => Mix.SCM . t ( ) } } | { :error , :not_loaded }
7881 def deps_scms ( ) do
7982 GenServer . call ( __MODULE__ , { :get , :deps_scms } )
8083 end
8184
82- @ spec deps_paths ( ) :: % { optional ( atom ) => Path . t ( ) }
85+ @ spec deps_paths ( ) :: { :ok , % { optional ( atom ) => Path . t ( ) } } | { :error , :not_loaded }
8386 def deps_paths ( ) do
8487 GenServer . call ( __MODULE__ , { :get , :deps_paths } )
8588 end
@@ -90,24 +93,25 @@ defmodule ElixirLS.LanguageServer.MixProjectCache do
9093 # traverse_deps(opts, fn %{deps: deps} -> Enum.map(deps, & &1.app) end)
9194 # end
9295
93- @ spec build_path ( ) :: Path . t ( )
96+ @ spec build_path ( ) :: { :ok , Path . t ( ) } | { :error , :not_loaded }
9497 def build_path ( ) do
9598 GenServer . call ( __MODULE__ , { :get , :build_path } )
9699 end
97100
98- @ spec manifest_path ( ) :: Path . t ( )
101+ @ spec manifest_path ( ) :: { :ok , Path . t ( ) } | { :error , :not_loaded }
99102 def manifest_path ( ) do
100103 GenServer . call ( __MODULE__ , { :get , :manifest_path } )
101104 end
102105
103- @ spec app_path ( ) :: Path . t ( )
106+ @ spec app_path ( ) :: { :ok , Path . t ( ) } | { :error , :not_loaded }
104107 def app_path ( ) do
105- config = config ( )
108+ { :ok , config } = config ( )
106109
107110 config [ :deps_app_path ] ||
108111 cond do
109112 app = config [ :app ] ->
110- Path . join ( [ build_path ( ) , "lib" , Atom . to_string ( app ) ] )
113+ { :ok , build_path } = build_path ( )
114+ Path . join ( [ build_path , "lib" , Atom . to_string ( app ) ] )
111115
112116 config [ :apps_path ] ->
113117 raise "trying to access Mix.Project.app_path/1 for an umbrella project but umbrellas have no app"
@@ -121,9 +125,11 @@ defmodule ElixirLS.LanguageServer.MixProjectCache do
121125 end
122126 end
123127
124- @ spec compile_path ( ) :: Path . t ( )
128+ @ spec compile_path ( ) :: { :ok , Path . t ( ) } | { :error , :not_loaded }
125129 def compile_path ( ) do
126- Path . join ( app_path ( ) , "ebin" )
130+ with { :ok , app_path } <- app_path ( ) do
131+ { :ok , Path . join ( app_path , "ebin" ) }
132+ end
127133 end
128134
129135 # @spec consolidation_path() :: Path.t()
@@ -168,8 +174,12 @@ defmodule ElixirLS.LanguageServer.MixProjectCache do
168174 end
169175
170176 @ impl GenServer
177+ def handle_call ( { :get , _key } , _from , nil = state ) do
178+ { :reply , { :error , :not_loaded } , state }
179+ end
180+
171181 def handle_call ( { :get , key } , _from , state ) do
172- { :reply , Map . fetch! ( state , key ) , state }
182+ { :reply , { :ok , Map . fetch! ( state , key ) } , state }
173183 end
174184
175185 def handle_call ( { :store , state } , _from , _state ) do
0 commit comments