File tree Expand file tree Collapse file tree 2 files changed +22
-6
lines changed
apps/language_server/lib/language_server Expand file tree Collapse file tree 2 files changed +22
-6
lines changed Original file line number Diff line number Diff line change @@ -4,10 +4,6 @@ defmodule ElixirLS.LanguageServer.Build do
4
4
require Logger
5
5
6
6
def build ( parent , root_path , opts ) when is_binary ( root_path ) do
7
- if Path . absname ( File . cwd! ( ) ) != Path . absname ( root_path ) do
8
- Logger . info ( "Skipping build because cwd changed from #{ root_path } to #{ File . cwd! ( ) } " )
9
- { nil , nil }
10
- else
11
7
spawn_monitor ( fn ->
12
8
with_build_lock ( fn ->
13
9
{ us , result } =
@@ -71,7 +67,6 @@ defmodule ElixirLS.LanguageServer.Build do
71
67
} )
72
68
end )
73
69
end )
74
- end
75
70
end
76
71
77
72
def clean ( clean_deps? \\ false ) do
Original file line number Diff line number Diff line change @@ -1240,7 +1240,28 @@ defmodule ElixirLS.LanguageServer.Server do
1240
1240
not state . build_running? and build_automatically ->
1241
1241
fetch_deps? = Map . get ( state . settings || % { } , "fetchDeps" , false )
1242
1242
1243
- { _pid , build_ref } = Build . build ( self ( ) , project_dir , fetch_deps?: fetch_deps? )
1243
+ { _pid , build_ref } = case File . cwd ( ) do
1244
+ { :ok , cwd } ->
1245
+ if Path . absname ( cwd ) == Path . absname ( project_dir ) do
1246
+ Build . build ( self ( ) , project_dir , fetch_deps?: fetch_deps? )
1247
+ else
1248
+ Logger . info ( "Skipping build because cwd changed from #{ project_dir } to #{ cwd } " )
1249
+ { nil , nil }
1250
+ end
1251
+ { :error , reason } ->
1252
+ Logger . warning ( "cwd is not accessible: #{ inspect ( reason ) } , trying to change directory back to #{ project_dir } " )
1253
+ # cwd is not accessible
1254
+ # try to change back to project dir
1255
+ case File . cd ( project_dir ) do
1256
+ :ok ->
1257
+ Build . build ( self ( ) , project_dir , fetch_deps?: fetch_deps? )
1258
+ { :error , reason } ->
1259
+ message = "Cannot change directory to project dir #{ project_dir } : #{ inspect ( reason ) } "
1260
+ Logger . error ( message )
1261
+ JsonRpc . show_message ( :error , message )
1262
+ { nil , nil }
1263
+ end
1264
+ end
1244
1265
1245
1266
% __MODULE__ {
1246
1267
state
You can’t perform that action at this time.
0 commit comments