Skip to content

Commit 9bc3ac2

Browse files
committed
add guards
1 parent 3919c85 commit 9bc3ac2

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

apps/language_server/lib/language_server/diagnostics.ex

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -222,7 +222,7 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
222222
JsonRpc.notify("textDocument/publishDiagnostics", message)
223223
end
224224

225-
def mixfile_diagnostic({file, line, message}, severity) do
225+
def mixfile_diagnostic({file, line, message}, severity) when not is_nil(file) do
226226
%Mix.Task.Compiler.Diagnostic{
227227
compiler_name: "ElixirLS",
228228
file: file,
@@ -237,7 +237,8 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
237237
severity: severity,
238238
message: message,
239239
position: position
240-
}) do
240+
})
241+
when not is_nil(file) do
241242
%Mix.Task.Compiler.Diagnostic{
242243
compiler_name: "ElixirLS",
243244
file: file,
@@ -247,7 +248,7 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
247248
}
248249
end
249250

250-
def error_to_diagnostic(kind, payload, stacktrace, path, project_dir) do
251+
def error_to_diagnostic(kind, payload, stacktrace, path, project_dir) when not is_nil(path) do
251252
path = SourceFile.Path.absname(path, project_dir)
252253
message = Exception.format(kind, payload, stacktrace)
253254

@@ -261,15 +262,15 @@ defmodule ElixirLS.LanguageServer.Diagnostics do
261262

262263
%Mix.Task.Compiler.Diagnostic{
263264
compiler_name: "ElixirLS",
264-
file: SourceFile.Path.absname(path, project_dir),
265+
file: path,
265266
position: line || 0,
266267
message: message,
267268
severity: :error,
268269
details: payload
269270
}
270271
end
271272

272-
def exception_to_diagnostic(error, path) do
273+
def exception_to_diagnostic(error, path) when not is_nil(path) do
273274
msg =
274275
case error do
275276
{:shutdown, 1} ->

apps/language_server/lib/language_server/source_file/path.ex

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ defmodule ElixirLS.LanguageServer.SourceFile.Path do
4141
uri |> from_uri |> absname()
4242
end
4343

44-
def absolute_from_uri(uri, project_dir) do
44+
def absolute_from_uri(uri, project_dir) when is_binary(project_dir) or is_nil(project_dir) do
4545
if project_dir == nil do
4646
uri |> from_uri |> absname()
4747
else
@@ -57,7 +57,7 @@ defmodule ElixirLS.LanguageServer.SourceFile.Path do
5757
path |> expand(project_dir) |> convert_separators_to_native()
5858
end
5959

60-
def to_uri(path) do
60+
def to_uri(path) when is_binary(path) do
6161
path =
6262
path
6363
|> expand()
@@ -66,7 +66,8 @@ defmodule ElixirLS.LanguageServer.SourceFile.Path do
6666
to_uri_impl(path)
6767
end
6868

69-
def to_uri(path, project_dir) do
69+
def to_uri(path, project_dir)
70+
when is_binary(path) and (is_binary(project_dir) or is_nil(project_dir)) do
7071
path =
7172
if project_dir == nil do
7273
expand(path)

0 commit comments

Comments
 (0)