From 9b992b07732ca4bdaf2c7bf08ec706585937ad8b Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sun, 12 Jan 2025 16:46:37 -0500 Subject: [PATCH] fix: extract module line from debug info on 1.18 (#559) Fixes #558 fix: correctly index imported functions on 1.18 chore: change 1.17.0-dev to 1.17.0 chore(nix): update flake --- flake.lock | 6 +++--- flake.nix | 7 ++++++- priv/monkey/_next_ls_private_compiler.ex | 26 +++++++++++++++++------- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/flake.lock b/flake.lock index b99d5d17..15f815b9 100644 --- a/flake.lock +++ b/flake.lock @@ -2,11 +2,11 @@ "nodes": { "nixpkgs": { "locked": { - "lastModified": 1720418205, - "narHash": "sha256-cPJoFPXU44GlhWg4pUk9oUPqurPlCFZ11ZQPk21GTPU=", + "lastModified": 1735471104, + "narHash": "sha256-0q9NGQySwDQc7RhAV2ukfnu7Gxa5/ybJ2ANT8DQrQrs=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "655a58a72a6601292512670343087c2d75d859c1", + "rev": "88195a94f390381c6afcdaa933c2f6ff93959cb4", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 3b669825..d831f240 100644 --- a/flake.nix +++ b/flake.nix @@ -25,6 +25,11 @@ zpkgs = zigpkgs.legacyPackages.${system}; beamPackages = pkgs.beam_minimal.packages.erlang_27; elixir = beamPackages.elixir_1_17; + # example of overriding elixir with whatever you want + # elixir = beamPackages.elixir_1_18.override { + # rev = "f16fb5aa8162794616a738fc6e84bfcdf9892cff"; + # sha256 = "sha256-UYWsmih+0z+4tdPhxl2zf+4gUNEgRJR4yyvxVBOgJdQ="; + # }; in f {inherit system pkgs zpkgs beamPackages elixir;}); @@ -42,7 +47,7 @@ elixir, ... }: { - default = pkgs.callPackage ./package.nix { inherit beamPackages elixir; }; + default = pkgs.callPackage ./package.nix {inherit beamPackages elixir;}; }); devShells = forAllSystems ({ diff --git a/priv/monkey/_next_ls_private_compiler.ex b/priv/monkey/_next_ls_private_compiler.ex index 60f301ae..399856d5 100644 --- a/priv/monkey/_next_ls_private_compiler.ex +++ b/priv/monkey/_next_ls_private_compiler.ex @@ -19,7 +19,14 @@ defmodule NextLSPrivate.DepTracer do {:ok, {_, [{~c"Dbgi", bin}]}} = :beam_lib.chunks(bytecode, [~c"Dbgi"]) - {:debug_info_v1, _, {_, %{line: line, struct: struct}, _}} = :erlang.binary_to_term(bin) + {line, struct} = + case :erlang.binary_to_term(bin) do + {:debug_info_v1, _, {_, %{anno: anno, struct: struct}, _}} -> + {:erl_anno.line(anno), struct} + + {:debug_info_v1, _, {_, %{line: line, struct: struct}, _}} -> + {line, struct} + end Process.send( parent, @@ -125,11 +132,12 @@ defmodule NextLSPrivate.Tracer do :ok end - def trace({type, meta, module, func, arity}, env) when type in [:remote_function, :remote_macro, :imported_macro] do + def trace({type, meta, module, func, arity}, env) + when type in [:remote_function, :remote_macro, :imported_macro, :imported_function] do parent = parent_pid() condition = - if Version.match?(System.version(), ">= 1.17.0-dev") do + if Version.match?(System.version(), ">= 1.17.0") do is_nil(meta[:column]) else type == :remote_macro && meta[:closing][:line] != meta[:line] @@ -193,7 +201,14 @@ defmodule NextLSPrivate.Tracer do {:ok, {_, [{~c"Dbgi", bin}]}} = :beam_lib.chunks(bytecode, [~c"Dbgi"]) - {:debug_info_v1, _, {_, %{line: line, struct: struct}, _}} = :erlang.binary_to_term(bin) + {line, struct} = + case :erlang.binary_to_term(bin) do + {:debug_info_v1, _, {_, %{anno: anno, struct: struct}, _}} -> + {:erl_anno.line(anno), struct} + + {:debug_info_v1, _, {_, %{line: line, struct: struct}, _}} -> + {line, struct} + end Process.send( parent, @@ -1361,9 +1376,6 @@ if Version.match?(System.version(), ">= 1.17.0-dev") do {:function, module, fun} -> expand_remote(meta, module, fun, args, state, env) - :error -> - expand_local(meta, fun, args, state, env) - {:error, _} -> expand_local(meta, fun, args, state, env) end