Skip to content

Commit

Permalink
PR feedback: strip snippet trailing newlines in one place
Browse files Browse the repository at this point in the history
  • Loading branch information
zachallaun committed Oct 13, 2023
1 parent a3ca499 commit 078e645
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 22 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Builder do

@impl Builder
def text_edit_snippet(%Env{} = env, text, {start_char, end_char}, options \\ []) do
snippet = String.trim_trailing(text, "\n")
line_number = env.position.line

range =
Expand All @@ -62,7 +63,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Builder do
Position.new(env.document, line_number, end_char)
)

edits = Document.Changes.new(env.document, Edit.new(text, range))
edits = Document.Changes.new(env.document, Edit.new(snippet, range))

options
|> Keyword.put(:text_edit, edits)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
def ${1:name}($2) do
$0
end\
end
"""

env
Expand All @@ -44,7 +44,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
defp ${1:name}($2) do
$0
end\
end
"""

env
Expand All @@ -63,7 +63,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
defmodule ${1:#{suggestion}} do
$0
end\
end
"""

env
Expand All @@ -81,7 +81,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
defmacro ${1:name}($2) do
$0
end\
end
"""

env
Expand All @@ -99,7 +99,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
defmacrop ${1:name}($2) do
$0
end\
end
"""

env
Expand All @@ -117,7 +117,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
defprotocol ${1:protocol_name} do
$0
end\
end
"""

env
Expand All @@ -135,7 +135,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
defimpl ${1:protocol_name}, for: ${2:struct_name} do
$0
end\
end
"""

env
Expand Down Expand Up @@ -277,7 +277,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
quote $1 do
$0
end\
end
"""

env
Expand All @@ -295,7 +295,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
receive do
${1:pattern} -> $0
end\
end
"""

env
Expand All @@ -313,7 +313,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
try do
$0
end\
end
"""

env
Expand All @@ -331,7 +331,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
with ${1:pattern} <- ${2:expression} do
$0
end\
end
"""

env
Expand All @@ -349,7 +349,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
case $1 do
${2:pattern} -> $0
end\
end
"""

env
Expand All @@ -367,7 +367,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
if $1 do
$0
end\
end
"""

env
Expand Down Expand Up @@ -399,7 +399,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
unless $1 do
$0
end\
end
"""

env
Expand All @@ -418,7 +418,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
cond do
${1:test} ->
$0
end\
end
"""

env
Expand All @@ -436,7 +436,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
for ${1:pattern} <- ${2:enumerable} do
$0
end\
end
"""

env
Expand Down Expand Up @@ -472,7 +472,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
plain_snippet = """
test "${1:message}" do
$0
end\
end
"""

env
Expand All @@ -490,7 +490,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
context_snippet = """
test "${1:message}", %{${2:context}} do
$0
end\
end
"""

env
Expand All @@ -506,7 +506,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.Macro do
snippet = """
describe "${1:message}" do
$0
end\
end
"""

env
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.ModuleAttribut
doc_snippet = ~s'''
@moduledoc """
$0
"""\
"""
'''

case fetch_range(env) do
Expand Down Expand Up @@ -44,7 +44,7 @@ defmodule Lexical.Server.CodeIntelligence.Completion.Translations.ModuleAttribut
doc_snippet = ~s'''
@doc """
$0
"""\
"""
'''

case fetch_range(env) do
Expand Down

0 comments on commit 078e645

Please sign in to comment.