Skip to content

Commit

Permalink
fix(completions): correctly insert cursor position (#408)
Browse files Browse the repository at this point in the history
The cursor was being inserted in a strange matter, which made the
modified ast not have a `__cursor__()` function, so we couldn't find the
cursor.

Really, all we need to do is insert the cursor on its own line between
the line.

For example, if you were to put the cursor into the middle of this line
of code

```elixir
Enum.map(some_list, fn row ->   end)
```

It would insert the cursor like so

```elixir
Enum.map(some_list, fn row ->
__cursor__()
end)
```

Fixes #406
  • Loading branch information
mhanberg authored Apr 4, 2024
1 parent 9c7ff4d commit 5509b4e
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 8 deletions.
2 changes: 1 addition & 1 deletion flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@
src = self.outPath;
inherit version elixir;
pname = "next-ls-deps";
hash = "sha256-9LKtrNvNU8swcaaW3OuOCNKCa76+mvtu7MsWuy204/E=";
hash = "sha256-aGVoJJPK+2phB9HLoIp50Qz0s+3tA9PU+yg8nvOGNRY=";
mixEnv = "prod";
};

Expand Down
5 changes: 4 additions & 1 deletion lib/next_ls.ex
Original file line number Diff line number Diff line change
Expand Up @@ -581,7 +581,10 @@ defmodule NextLS do
document
|> List.update_at(position.line, fn row ->
{front, back} = String.split_at(row, position.character)
String.slice(front, -1..1) <> "__cursor__()" <> back
# all we need to do is insert the cursor so we can find the spot to then
# calculate the environment, it doens't really matter if its valid code,
# it probably isn't already
front <> "\n__cursor__()\n" <> back
end)
|> Enum.join("\n")

Expand Down
2 changes: 1 addition & 1 deletion mix.lock
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"req": {:hex, :req, "0.4.0", "1c759054dd64ef1b1a0e475c2d2543250d18f08395d3174c371b7746984579ce", [:mix], [{:brotli, "~> 0.3.1", [hex: :brotli, repo: "hexpm", optional: true]}, {:ezstd, "~> 1.0", [hex: :ezstd, repo: "hexpm", optional: true]}, {:finch, "~> 0.9", [hex: :finch, repo: "hexpm", optional: false]}, {:jason, "~> 1.0", [hex: :jason, repo: "hexpm", optional: false]}, {:mime, "~> 1.6 or ~> 2.0", [hex: :mime, repo: "hexpm", optional: false]}, {:nimble_csv, "~> 1.0", [hex: :nimble_csv, repo: "hexpm", optional: true]}, {:plug, "~> 1.0", [hex: :plug, repo: "hexpm", optional: true]}], "hexpm", "f53eadc32ebefd3e5d50390356ec3a59ed2b8513f7da8c6c3f2e14040e9fe989"},
"schematic": {:hex, :schematic, "0.2.1", "0b091df94146fd15a0a343d1bd179a6c5a58562527746dadd09477311698dbb1", [:mix], [{:telemetry, "~> 0.4 or ~> 1.0", [hex: :telemetry, repo: "hexpm", optional: false]}], "hexpm", "0b255d65921e38006138201cd4263fd8bb807d9dfc511074615cd264a571b3b1"},
"sourceror": {:hex, :sourceror, "1.0.2", "c5e86fdc14881f797749d1fe5df017ca66727a8146e7ee3e736605a3df78f3e6", [:mix], [], "hexpm", "832335e87d0913658f129d58b2a7dc0490ddd4487b02de6d85bca0169ec2bd79"},
"spitfire": {:git, "https://github.com/elixir-tools/spitfire.git", "26e68d4b184caf32ccee840ef0e862c911ff51ef", []},
"spitfire": {:git, "https://github.com/elixir-tools/spitfire.git", "d39f91d6e66f70cb3093bad4947d7e46bba40b43", []},
"ssl_verify_fun": {:hex, :ssl_verify_fun, "1.1.7", "354c321cf377240c7b8716899e182ce4890c5938111a1296add3ec74cf1715df", [:make, :mix, :rebar3], [], "hexpm", "fe4c190e8f37401d30167c8c405eda19469f34577987c76dde613e838bbc67f8"},
"styler": {:hex, :styler, "0.8.1", "f3c0f65023e4bfbf7e7aa752d128b8475fdabfd30f96ee7314b84480cc56e788", [:mix], [], "hexpm", "1aa48d3aa689a639289af3d8254d40e068e98c083d6e5e3d1a695e71a147b344"},
"telemetry": {:hex, :telemetry, "1.2.1", "68fdfe8d8f05a8428483a97d7aab2f268aaff24b49e0f599faa091f1d4e7f61c", [:rebar3], [], "hexpm", "dad9ce9d8effc621708f99eac538ef1cbe05d6a874dd741de2e689c47feafed5"},
Expand Down
5 changes: 0 additions & 5 deletions priv/monkey/_next_ls_private_compiler.ex
Original file line number Diff line number Diff line change
Expand Up @@ -254,11 +254,6 @@ defmodule :_next_ls_private_formatter do
ins: [text: :green, space: :green_background]
]

@callback features(Keyword.t()) :: [sigils: [atom()], extensions: [binary()]]

@callback format(String.t(), Keyword.t()) :: String.t()

@impl true
def run(args) do
cwd = File.cwd!()
{opts, args} = OptionParser.parse!(args, strict: @switches)
Expand Down

0 comments on commit 5509b4e

Please sign in to comment.