Skip to content

Commit 3215dde

Browse files
committed
make tests pass
1 parent 32fc59f commit 3215dde

File tree

8 files changed

+507
-178
lines changed

8 files changed

+507
-178
lines changed

apps/language_server/lib/language_server/parser.ex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -252,7 +252,7 @@ defmodule ElixirLS.LanguageServer.Parser do
252252
end
253253
end
254254

255-
defp do_parse(%Context{source_file: source_file = %SourceFile{}, path: path} = file, cursor_position \\ nil) do
255+
def do_parse(%Context{source_file: source_file = %SourceFile{}, path: path} = file, cursor_position \\ nil) do
256256
{ast, diagnostics} = parse_file(source_file.text, path, source_file.language_id)
257257

258258
{flag, ast, metadata} = if ast do

apps/language_server/test/providers/completion_test.exs

Lines changed: 225 additions & 80 deletions
Large diffs are not rendered by default.

apps/language_server/test/providers/definition_test.exs

Lines changed: 34 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,13 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
55
alias ElixirLS.LanguageServer.Protocol.Location
66
alias ElixirLS.LanguageServer.SourceFile
77
alias ElixirLS.LanguageServer.Test.FixtureHelpers
8+
alias ElixirLS.LanguageServer.Test.ParserContextBuilder
89
require ElixirLS.Test.TextLoc
910

1011
test "find definition remote function call" do
1112
file_path = FixtureHelpers.get_path("references_remote.ex")
12-
text = File.read!(file_path)
13+
parser_context = ParserContextBuilder.from_path(file_path)
14+
1315
uri = SourceFile.Path.to_uri(file_path)
1416

1517
b_file_path = FixtureHelpers.get_path("references_referenced.ex")
@@ -22,8 +24,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
2224
^
2325
""")
2426

27+
{line, char} = SourceFile.lsp_position_to_elixir(parser_context.source_file.text, {line, char})
28+
2529
assert {:ok, %Location{uri: ^b_uri, range: range}} =
26-
Definition.definition(uri, text, line, char, File.cwd!())
30+
Definition.definition(uri, parser_context, line, char, File.cwd!())
2731

2832
assert range == %{
2933
"start" => %{"line" => 1, "character" => 2},
@@ -33,7 +37,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
3337

3438
test "find definition remote macro call" do
3539
file_path = FixtureHelpers.get_path("references_remote.ex")
36-
text = File.read!(file_path)
40+
parser_context = ParserContextBuilder.from_path(file_path)
3741
uri = SourceFile.Path.to_uri(file_path)
3842

3943
b_file_path = FixtureHelpers.get_path("references_referenced.ex")
@@ -46,8 +50,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
4650
^
4751
""")
4852

53+
{line, char} = SourceFile.lsp_position_to_elixir(parser_context.source_file.text, {line, char})
54+
4955
assert {:ok, %Location{uri: ^b_uri, range: range}} =
50-
Definition.definition(uri, text, line, char, File.cwd!())
56+
Definition.definition(uri, parser_context, line, char, File.cwd!())
5157

5258
assert range == %{
5359
"start" => %{"line" => 8, "character" => 2},
@@ -57,7 +63,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
5763

5864
test "find definition imported function call" do
5965
file_path = FixtureHelpers.get_path("references_imported.ex")
60-
text = File.read!(file_path)
66+
parser_context = ParserContextBuilder.from_path(file_path)
6167
uri = SourceFile.Path.to_uri(file_path)
6268

6369
b_file_path = FixtureHelpers.get_path("references_referenced.ex")
@@ -70,8 +76,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
7076
^
7177
""")
7278

79+
{line, char} = SourceFile.lsp_position_to_elixir(parser_context.source_file.text, {line, char})
80+
7381
assert {:ok, %Location{uri: ^b_uri, range: range}} =
74-
Definition.definition(uri, text, line, char, File.cwd!())
82+
Definition.definition(uri, parser_context, line, char, File.cwd!())
7583

7684
assert range == %{
7785
"start" => %{"line" => 1, "character" => 2},
@@ -81,7 +89,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
8189

8290
test "find definition imported macro call" do
8391
file_path = FixtureHelpers.get_path("references_imported.ex")
84-
text = File.read!(file_path)
92+
parser_context = ParserContextBuilder.from_path(file_path)
8593
uri = SourceFile.Path.to_uri(file_path)
8694

8795
b_file_path = FixtureHelpers.get_path("references_referenced.ex")
@@ -94,8 +102,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
94102
^
95103
""")
96104

105+
{line, char} = SourceFile.lsp_position_to_elixir(parser_context.source_file.text, {line, char})
106+
97107
assert {:ok, %Location{uri: ^b_uri, range: range}} =
98-
Definition.definition(uri, text, line, char, File.cwd!())
108+
Definition.definition(uri, parser_context, line, char, File.cwd!())
99109

100110
assert range == %{
101111
"start" => %{"line" => 8, "character" => 2},
@@ -105,7 +115,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
105115

106116
test "find definition local function call" do
107117
file_path = FixtureHelpers.get_path("references_referenced.ex")
108-
text = File.read!(file_path)
118+
parser_context = ParserContextBuilder.from_path(file_path)
109119
uri = SourceFile.Path.to_uri(file_path)
110120

111121
b_file_path = FixtureHelpers.get_path("references_referenced.ex")
@@ -118,8 +128,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
118128
^
119129
""")
120130

131+
{line, char} = SourceFile.lsp_position_to_elixir(parser_context.source_file.text, {line, char})
132+
121133
assert {:ok, %Location{uri: ^b_uri, range: range}} =
122-
Definition.definition(uri, text, line, char, File.cwd!())
134+
Definition.definition(uri, parser_context, line, char, File.cwd!())
123135

124136
assert range == %{
125137
"start" => %{"line" => 1, "character" => 2},
@@ -129,7 +141,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
129141

130142
test "find definition local macro call" do
131143
file_path = FixtureHelpers.get_path("references_referenced.ex")
132-
text = File.read!(file_path)
144+
parser_context = ParserContextBuilder.from_path(file_path)
133145
uri = SourceFile.Path.to_uri(file_path)
134146

135147
b_file_path = FixtureHelpers.get_path("references_referenced.ex")
@@ -142,8 +154,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
142154
^
143155
""")
144156

157+
{line, char} = SourceFile.lsp_position_to_elixir(parser_context.source_file.text, {line, char})
158+
145159
assert {:ok, %Location{uri: ^b_uri, range: range}} =
146-
Definition.definition(uri, text, line, char, File.cwd!())
160+
Definition.definition(uri, parser_context, line, char, File.cwd!())
147161

148162
assert range == %{
149163
"start" => %{"line" => 8, "character" => 2},
@@ -153,7 +167,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
153167

154168
test "find definition variable" do
155169
file_path = FixtureHelpers.get_path("references_referenced.ex")
156-
text = File.read!(file_path)
170+
parser_context = ParserContextBuilder.from_path(file_path)
157171
uri = SourceFile.Path.to_uri(file_path)
158172

159173
b_file_path = FixtureHelpers.get_path("references_referenced.ex")
@@ -166,8 +180,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
166180
^
167181
""")
168182

183+
{line, char} = SourceFile.lsp_position_to_elixir(parser_context.source_file.text, {line, char})
184+
169185
assert {:ok, %Location{uri: ^b_uri, range: range}} =
170-
Definition.definition(uri, text, line, char, File.cwd!())
186+
Definition.definition(uri, parser_context, line, char, File.cwd!())
171187

172188
assert range == %{
173189
"start" => %{"line" => 2, "character" => 4},
@@ -177,7 +193,7 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
177193

178194
test "find definition attribute" do
179195
file_path = FixtureHelpers.get_path("references_referenced.ex")
180-
text = File.read!(file_path)
196+
parser_context = ParserContextBuilder.from_path(file_path)
181197
uri = SourceFile.Path.to_uri(file_path)
182198

183199
b_file_path = FixtureHelpers.get_path("references_referenced.ex")
@@ -190,8 +206,10 @@ defmodule ElixirLS.LanguageServer.Providers.DefinitionTest do
190206
^
191207
""")
192208

209+
{line, char} = SourceFile.lsp_position_to_elixir(parser_context.source_file.text, {line, char})
210+
193211
assert {:ok, %Location{uri: ^b_uri, range: range}} =
194-
Definition.definition(uri, text, line, char, File.cwd!())
212+
Definition.definition(uri, parser_context, line, char, File.cwd!())
195213

196214
assert range == %{
197215
"start" => %{"line" => 24, "character" => 2},

0 commit comments

Comments
 (0)