Skip to content

Commit a3c8584

Browse files
authored
Add @moduledoc false and @doc false as snippets (#288)
* Add `@moduledoc false` and `@doc false` as snippets * Add changelog entry
1 parent d280515 commit a3c8584

File tree

3 files changed

+57
-10
lines changed

3 files changed

+57
-10
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ Improvements:
88
- Display the version of Elixir used to compile ELixirLS (thanks [Jason Axelson](https://github.com/axelson)) [#264](https://github.com/elixir-lsp/elixir-ls/pull/264)
99
- Support completion of callback function definitions (thanks [Marlus Saraiva](https://github.com/msaraiva)) [#265](https://github.com/elixir-lsp/elixir-ls/pull/265)
1010
- Give more direct warnings when mix.exs cannot be found (thanks [Jason Axelson](https://github.com/axelson)) [#297](https://github.com/elixir-lsp/elixir-ls/pull/297)
11+
- Add completions for `@moduledoc false` and `@doc false` (thanks [Jason Axelson](https://github.com/axelson)) [#288](https://github.com/elixir-lsp/elixir-ls/pull/288)
1112

1213
Changes:
1314
- Major improvement/change: Improve autocomplete and signature help (thanks [Marlus Saraiva](https://github.com/msaraiva)) [#273](https://github.com/elixir-lsp/elixir-ls/pull/273)

apps/language_server/lib/language_server/providers/completion.ex

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
1717
:documentation,
1818
:insert_text,
1919
:filter_text,
20+
# Lower priority is shown higher in the result list
2021
:priority,
2122
:tags,
2223
:command
2324
]
2425

26+
# Format:
27+
# {name, snippet, documentation, priority}
2528
@module_attr_snippets [
26-
{"doc", "doc \"\"\"\n$0\n\"\"\"", "Documents a function"},
27-
{"moduledoc", "moduledoc \"\"\"\n$0\n\"\"\"", "Documents a module"},
28-
{"typedoc", "typedoc \"\"\"\n$0\n\"\"\"", "Documents a type specification"}
29+
{~s(doc """"""), ~s(doc """\n$0\n"""), "Documents a function", 3},
30+
{"doc false", "doc false", "Marks this function as internal", 5},
31+
{~s(moduledoc """"""), ~s(moduledoc """\n$0\n"""), "Documents a module", 3},
32+
{"moduledoc false", "moduledoc false", "Marks this module as internal", 5},
33+
{"typedoc", ~s(typedoc """\n$0\n"""), "Documents a type specification", 3}
2934
]
3035

3136
@func_snippets %{
@@ -166,9 +171,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
166171
capture_before? = context.capture_before?
167172

168173
Enum.reject(suggestions, fn s ->
169-
s.type in [:function, :macro] &&
170-
!capture_before? &&
171-
s.arity < s.def_arity &&
174+
s.type in [:function, :macro] && !capture_before? && s.arity < s.def_arity &&
172175
signature_help_supported &&
173176
function_name_with_parens?(s.name, s.arity, locals_without_parens) &&
174177
function_name_with_parens?(s.name, s.def_arity, locals_without_parens)
@@ -197,7 +200,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
197200
detail: "module attribute",
198201
insert_text: insert_text,
199202
filter_text: name_only,
200-
priority: 3,
203+
priority: 4,
201204
tags: []
202205
}
203206
end
@@ -624,7 +627,7 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
624627
end
625628

626629
defp module_attr_snippets(%{prefix: prefix, scope: :module, def_before: nil}) do
627-
for {name, snippet, docs} <- @module_attr_snippets,
630+
for {name, snippet, docs, priority} <- @module_attr_snippets,
628631
label = "@" <> name,
629632
String.starts_with?(label, prefix) do
630633
snippet =
@@ -637,11 +640,11 @@ defmodule ElixirLS.LanguageServer.Providers.Completion do
637640
label: label,
638641
kind: :snippet,
639642
documentation: docs,
640-
detail: "module attribute",
643+
detail: "module attribute snippet",
641644
insert_text: snippet,
642645
filter_text: name,
643646
tags: [],
644-
priority: 6
647+
priority: priority
645648
}
646649
end
647650
end

apps/language_server/test/providers/completion_test.exs

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,5 +749,48 @@ defmodule ElixirLS.LanguageServer.Providers.CompletionTest do
749749
"""
750750
}
751751
end
752+
753+
test "moduledoc completion" do
754+
text = """
755+
defmodule MyModule do
756+
@mod
757+
# ^
758+
end
759+
"""
760+
761+
{line, char} = {1, 6}
762+
763+
TestUtils.assert_has_cursor_char(text, line, char)
764+
765+
assert {:ok, %{"items" => items}} = Completion.completion(text, line, char, @supports)
766+
labels = Enum.map(items, & &1["label"])
767+
768+
assert labels == [
769+
~s(@moduledoc """"""),
770+
"@moduledoc",
771+
"@moduledoc false"
772+
]
773+
end
774+
775+
test "doc completion" do
776+
text = """
777+
defmodule MyModule do
778+
@do
779+
# ^
780+
end
781+
"""
782+
783+
{line, char} = {1, 5}
784+
785+
TestUtils.assert_has_cursor_char(text, line, char)
786+
787+
assert {:ok, %{"items" => items}} = Completion.completion(text, line, char, @supports)
788+
labels = Enum.map(items, & &1["label"])
789+
790+
assert labels == [
791+
~s(@doc """"""),
792+
"@doc false"
793+
]
794+
end
752795
end
753796
end

0 commit comments

Comments
 (0)