Skip to content

Commit a36d47e

Browse files
committed
fix serialization error
1 parent 6111aed commit a36d47e

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

apps/language_server/lib/language_server/providers/execute_command/llm_docs_aggregator.ex

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
158158
documentation: callback_info[:documentation] || "",
159159
spec: callback_info[:spec],
160160
kind: callback_info[:kind],
161-
metadata: callback_info[:metadata] || %{}
161+
metadata: format_metadata_section(callback_info[:metadata])
162162
}
163163
end)
164164

@@ -213,7 +213,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
213213
%{
214214
type: "moduledoc",
215215
content: moduledoc_content,
216-
metadata: moduledoc_metadata
216+
metadata: format_metadata_section(moduledoc_metadata)
217217
}
218218
else
219219
nil
@@ -255,7 +255,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
255255
signature: "#{name}/#{arity}",
256256
doc: nil,
257257
specs: [],
258-
metadata: %{}
258+
metadata: ""
259259
}
260260
end)
261261

@@ -370,7 +370,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
370370
%{
371371
module: module_name,
372372
moduledoc: moduledoc_content,
373-
moduledoc_metadata: moduledoc_metadata,
373+
moduledoc_metadata: format_metadata_section(moduledoc_metadata),
374374
functions: functions_list,
375375
macros: macros_list,
376376
types: types_list,
@@ -403,7 +403,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
403403
arity: doc_arity,
404404
signature: "#{function}/#{doc_arity}",
405405
doc: extract_doc(doc),
406-
metadata: metadata,
406+
metadata: format_metadata_section(metadata),
407407
specs: Map.get(specs, {name, doc_arity}, [])
408408
}
409409
end)
@@ -439,7 +439,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
439439
arity: doc_arity,
440440
spec: Map.get(type_specs_by_name_arity, {name, doc_arity}),
441441
documentation: doc_content || "",
442-
metadata: metadata
442+
metadata: format_metadata_section(metadata)
443443
}
444444
end)
445445
end
@@ -469,7 +469,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
469469
signature: format_function_signature(module, name, arity, metadata),
470470
doc: extract_doc(doc),
471471
specs: [],
472-
metadata: metadata
472+
metadata: format_metadata_section(metadata)
473473
}
474474

475475
_ ->
@@ -485,7 +485,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
485485
type: Atom.to_string(name),
486486
arity: arity,
487487
doc: extract_doc(doc),
488-
metadata: metadata
488+
metadata: format_metadata_section(metadata)
489489
}
490490

491491
_ ->
@@ -501,7 +501,7 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
501501
arity: arity,
502502
kind: kind,
503503
doc: extract_doc(doc),
504-
metadata: metadata
504+
metadata: format_metadata_section(metadata)
505505
}
506506

507507
_ ->
@@ -549,11 +549,9 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
549549
documentation: extract_doc(callback_info.doc),
550550
spec: callback_info.callback,
551551
kind: callback_info.kind,
552-
metadata: callback_info.metadata
552+
metadata: format_metadata_section(callback_info.metadata)
553553
}
554554

555-
callback_result = Map.put(callback_result, :metadata, callback_info.metadata)
556-
557555
callback_result
558556
end)
559557
end
@@ -687,6 +685,10 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregator do
687685
|> Enum.join("\n")
688686
end
689687

688+
defp format_metadata_section(metadata) when is_binary(metadata) and metadata != "" do
689+
if String.trim(metadata) != "", do: metadata, else: ""
690+
end
691+
690692
defp format_metadata_section(metadata) when is_map(metadata) and metadata != %{} do
691693
metadata_md = MarkdownUtils.get_metadata_md(metadata)
692694
if metadata_md != "", do: "\n\n" <> metadata_md, else: ""

apps/language_server/test/providers/execute_command/llm_docs_aggregator_test.exs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregatorTest
366366
module_result = hd(result.results)
367367
assert Map.has_key?(module_result, :moduledoc_metadata)
368368
# ModuleWithDocs has a @moduledoc since: "1.2.3"
369-
assert is_map(module_result.moduledoc_metadata)
369+
assert is_binary(module_result.moduledoc_metadata)
370+
assert String.contains?(module_result.moduledoc_metadata, "Since")
370371

371372
# Test function metadata
372373
assert {:ok, result} =
@@ -478,7 +479,8 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregatorTest
478479
assert Map.has_key?(callback_result, :metadata)
479480
assert callback_result.spec == "@callback some_callback(integer()) :: atom()"
480481
assert callback_result.kind == :callback
481-
assert callback_result.metadata.since == "1.1.0"
482+
assert String.contains?(callback_result.metadata, "Since")
483+
assert String.contains?(callback_result.metadata, "1.1.0")
482484

483485
# Test macrocallback spec
484486
assert {:ok, result} =
@@ -496,7 +498,8 @@ defmodule ElixirLS.LanguageServer.Providers.ExecuteCommand.LlmDocsAggregatorTest
496498
assert Map.has_key?(macrocallback_result, :metadata)
497499
assert macrocallback_result.spec == "@macrocallback some_macrocallback(integer()) :: atom()"
498500
assert macrocallback_result.kind == :macrocallback
499-
assert macrocallback_result.metadata.since == "1.1.0"
501+
assert String.contains?(macrocallback_result.metadata, "Since")
502+
assert String.contains?(macrocallback_result.metadata, "1.1.0")
500503
end
501504

502505
test "verifies function documentation contains specs" do

0 commit comments

Comments
 (0)