From 90cd35a750f724a323232023fffe70df7aeff1be Mon Sep 17 00:00:00 2001 From: Mitchell Hanberg Date: Sat, 20 Apr 2024 08:22:29 -0400 Subject: [PATCH] fix(credo): calculate accurate span from trigger (#427) --- lib/next_ls/extensions/credo_extension.ex | 6 ++++-- test/next_ls/extensions/credo_extension_test.exs | 6 +++--- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/lib/next_ls/extensions/credo_extension.ex b/lib/next_ls/extensions/credo_extension.ex index 46423c04..b3200af6 100644 --- a/lib/next_ls/extensions/credo_extension.ex +++ b/lib/next_ls/extensions/credo_extension.ex @@ -111,15 +111,17 @@ defmodule NextLS.CredoExtension do {{:credo, path} = namespace, refs} = Map.pop(refs, ref) for issue <- issues do + column = (issue.column || 1) - 1 + diagnostic = %Diagnostic{ range: %Range{ start: %Position{ line: issue.line_no - 1, - character: (issue.column || 1) - 1 + character: column }, end: %Position{ line: issue.line_no - 1, - character: 999 + character: column + String.length(issue.trigger) } }, severity: category_to_severity(issue.category), diff --git a/test/next_ls/extensions/credo_extension_test.exs b/test/next_ls/extensions/credo_extension_test.exs index 441a4c3f..c4817f79 100644 --- a/test/next_ls/extensions/credo_extension_test.exs +++ b/test/next_ls/extensions/credo_extension_test.exs @@ -108,7 +108,7 @@ defmodule NextLS.CredoExtensionTest do }, "message" => "There should be no calls to `dbg/1`.", "range" => %{ - "end" => %{"character" => 999, "line" => 2}, + "end" => %{"character" => 7, "line" => 2}, "start" => %{"character" => 4, "line" => 2} }, "severity" => 2, @@ -146,7 +146,7 @@ defmodule NextLS.CredoExtensionTest do }, "message" => "There should be no calls to `dbg/1`.", "range" => %{ - "end" => %{"character" => 999, "line" => 2}, + "end" => %{"character" => 7, "line" => 2}, "start" => %{"character" => 4, "line" => 2} }, "severity" => 2, @@ -163,7 +163,7 @@ defmodule NextLS.CredoExtensionTest do }, "message" => "Modules should have a @moduledoc tag.", "range" => %{ - "end" => %{"character" => 999, "line" => 0}, + "end" => %{"character" => 13, "line" => 0}, "start" => %{"character" => 10, "line" => 0} }, "severity" => 3,