From 279867eaf52ed6a5c011b6021ab945f6818a5273 Mon Sep 17 00:00:00 2001 From: Erlend Storsve Date: Thu, 20 Feb 2025 11:18:37 +0100 Subject: [PATCH 1/5] feat: monorepo support --- lua/goto-alias/init.lua | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/lua/goto-alias/init.lua b/lua/goto-alias/init.lua index 66ad604..187f747 100644 --- a/lua/goto-alias/init.lua +++ b/lua/goto-alias/init.lua @@ -1,18 +1,22 @@ --TODO: --tests --does .nuxt directory detection using string.concat have better preformance? ---newly created components do not seem to workb +--newly created components do not seem to work local M = {} M.is_nuxt_project = false M.original_definition = vim.lsp.buf.definition -M.setup = function() - local dirList = vim.fn.systemlist("ls -a") +local default_check_directories = { "" } - for _, dirname in ipairs(dirList) do - if dirname == ".nuxt" then +M.setup = function(opts) + opts = opts or {} + + local check_directories = vim.list_extend(default_check_directories, opts.check_directories or {}) + + for _, dir in ipairs(check_directories) do + if vim.fn.isdirectory(vim.loop.cwd() .. dir .. "/.nuxt") == 1 then M.is_nuxt_project = true end end @@ -38,7 +42,11 @@ M.watch = function() local file = vim.fn.expand("%") if string.find(file, "components.d.ts") then - vim.cmd("edit " .. path) + vim.api.nvim_buf_delete(0, { force = false }) + vim.cmd("edit apps/web/" .. path) + elseif string.find(line, "components.d.ts") then + vim.cmd("cclose") + vim.cmd("edit apps/web/" .. path) end end, 100) end From cabef11152d97e39f914948b10d97978a2f7baec Mon Sep 17 00:00:00 2001 From: Erlend Storsve Date: Thu, 20 Feb 2025 11:47:04 +0100 Subject: [PATCH 2/5] fix: use .nuxt path in edit cmd --- lua/goto-alias/init.lua | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/lua/goto-alias/init.lua b/lua/goto-alias/init.lua index 187f747..dd725ef 100644 --- a/lua/goto-alias/init.lua +++ b/lua/goto-alias/init.lua @@ -7,6 +7,7 @@ local M = {} M.is_nuxt_project = false M.original_definition = vim.lsp.buf.definition +M.nuxt_directory_path = "" local default_check_directories = { "" } @@ -15,9 +16,12 @@ M.setup = function(opts) local check_directories = vim.list_extend(default_check_directories, opts.check_directories or {}) - for _, dir in ipairs(check_directories) do - if vim.fn.isdirectory(vim.loop.cwd() .. dir .. "/.nuxt") == 1 then + for _, directory in ipairs(check_directories) do + if vim.fn.isdirectory(vim.loop.cwd() .. directory .. "/.nuxt") == 1 then M.is_nuxt_project = true + if directory ~= "" then + M.nuxt_directory_path = string.sub(directory, 2) + end end end @@ -43,10 +47,10 @@ M.watch = function() if string.find(file, "components.d.ts") then vim.api.nvim_buf_delete(0, { force = false }) - vim.cmd("edit apps/web/" .. path) + vim.cmd("edit " .. M.nuxt_directory_path .. "/" .. path) elseif string.find(line, "components.d.ts") then vim.cmd("cclose") - vim.cmd("edit apps/web/" .. path) + vim.cmd("edit " .. M.nuxt_directory_path .. "/" .. path) end end, 100) end From 6c498d4967d1c330b698c8f6cbf3071129a62c5a Mon Sep 17 00:00:00 2001 From: Erlend Storsve Date: Thu, 20 Feb 2025 11:52:26 +0100 Subject: [PATCH 3/5] fix: stop searching when .nuxt folder is found --- lua/goto-alias/init.lua | 1 + 1 file changed, 1 insertion(+) diff --git a/lua/goto-alias/init.lua b/lua/goto-alias/init.lua index dd725ef..d0da3bd 100644 --- a/lua/goto-alias/init.lua +++ b/lua/goto-alias/init.lua @@ -22,6 +22,7 @@ M.setup = function(opts) if directory ~= "" then M.nuxt_directory_path = string.sub(directory, 2) end + break end end From 6ffb79ad5efd283882ca458a67291fbd41110332 Mon Sep 17 00:00:00 2001 From: Erlend Storsve Date: Mon, 13 Oct 2025 02:18:44 +0200 Subject: [PATCH 4/5] fix: composables, utils and stores --- lua/goto-alias/init.lua | 44 ++++++++++++++++++++++++++++++++++------- 1 file changed, 37 insertions(+), 7 deletions(-) diff --git a/lua/goto-alias/init.lua b/lua/goto-alias/init.lua index d0da3bd..a672c8a 100644 --- a/lua/goto-alias/init.lua +++ b/lua/goto-alias/init.lua @@ -9,7 +9,7 @@ M.is_nuxt_project = false M.original_definition = vim.lsp.buf.definition M.nuxt_directory_path = "" -local default_check_directories = { "" } +local default_check_directories = { "/apps/web", "/apps/nuxt", "/apps/frontend", "/apps/website" } M.setup = function(opts) opts = opts or {} @@ -36,22 +36,52 @@ M.setup = function(opts) vim.lsp.buf.definition = M.watch end, }) + + -- this is in the original repo. whyyy??? + -- - maybe for when you change repo without closing neovim? + -- M.is_nuxt_project = false + -- M.original_definition = vim.lsp.buf.definition + -- M.nuxt_directory_path = "" end M.watch = function() M.original_definition() + if not M.is_nuxt_project then + return + end + vim.defer_fn(function() local line = vim.fn.getline(".") local path = string.match(line, '".-/(.-)"') local file = vim.fn.expand("%") - if string.find(file, "components.d.ts") then - vim.api.nvim_buf_delete(0, { force = false }) - vim.cmd("edit " .. M.nuxt_directory_path .. "/" .. path) - elseif string.find(line, "components.d.ts") then - vim.cmd("cclose") - vim.cmd("edit " .. M.nuxt_directory_path .. "/" .. path) + local auto_import_files = { "components.d.ts", "imports.d.ts" } + + for _, auto_import_file in ipairs(auto_import_files) do + if string.find(file, auto_import_file) then + vim.api.nvim_buf_delete(0, { force = false }) + vim.cmd("edit " .. M.nuxt_directory_path .. "/" .. path) + break + elseif string.find(line, auto_import_file) then + if string.find(line, "stores") then + local storePath = string.match(line, "'.-/(.-)'") + vim.cmd("cclose") + vim.cmd("edit " .. M.nuxt_directory_path .. "/stores/" .. storePath .. ".ts") + elseif string.find(line, "composables") then + local composablePath = string.match(line, "'.-/(.-)'") + vim.cmd("cclose") + vim.cmd("edit " .. M.nuxt_directory_path .. "/composables/" .. composablePath .. ".ts") + elseif string.find(line, "utils") then + local utilsPath = string.match(line, "'.-/(.-)'") + vim.cmd("cclose") + vim.cmd("edit " .. M.nuxt_directory_path .. "/utils/" .. utilsPath .. ".ts") + else + vim.cmd("cclose") + vim.cmd("edit " .. M.nuxt_directory_path .. "/" .. path) + end + break + end end end, 100) end From 7a67b8bab8e7da018ea52070a74a116dde074538 Mon Sep 17 00:00:00 2001 From: Erlend Storsve Date: Mon, 13 Oct 2025 03:03:10 +0200 Subject: [PATCH 5/5] feat: check multiple times in case typescript is slow --- lua/goto-alias/init.lua | 84 ++++++++++++++++++++++++----------------- 1 file changed, 50 insertions(+), 34 deletions(-) diff --git a/lua/goto-alias/init.lua b/lua/goto-alias/init.lua index a672c8a..5117288 100644 --- a/lua/goto-alias/init.lua +++ b/lua/goto-alias/init.lua @@ -5,11 +5,12 @@ local M = {} -M.is_nuxt_project = false M.original_definition = vim.lsp.buf.definition +M.is_nuxt_project = false M.nuxt_directory_path = "" +M.it_worked = false -local default_check_directories = { "/apps/web", "/apps/nuxt", "/apps/frontend", "/apps/website" } +local default_check_directories = { "", "/apps/web", "/apps/nuxt", "/apps/frontend", "/apps/website" } M.setup = function(opts) opts = opts or {} @@ -44,46 +45,61 @@ M.setup = function(opts) -- M.nuxt_directory_path = "" end -M.watch = function() - M.original_definition() - - if not M.is_nuxt_project then +local redirect_if_auto_import = function() + if M.it_worked then return end - vim.defer_fn(function() - local line = vim.fn.getline(".") - local path = string.match(line, '".-/(.-)"') - local file = vim.fn.expand("%") + local line = vim.fn.getline(".") + local path = string.match(line, '".-/(.-)"') + local file = vim.fn.expand("%") - local auto_import_files = { "components.d.ts", "imports.d.ts" } + local auto_import_files = { "components.d.ts", "imports.d.ts" } - for _, auto_import_file in ipairs(auto_import_files) do - if string.find(file, auto_import_file) then - vim.api.nvim_buf_delete(0, { force = false }) + for _, auto_import_file in ipairs(auto_import_files) do + if string.find(file, auto_import_file) then + vim.api.nvim_buf_delete(0, { force = false }) + vim.cmd("edit " .. M.nuxt_directory_path .. "/" .. path) + M.it_worked = true + break + elseif string.find(line, auto_import_file) then + if string.find(line, "stores") then + local storePath = string.match(line, "'.-/(.-)'") + vim.cmd("cclose") + vim.cmd("edit " .. M.nuxt_directory_path .. "/stores/" .. storePath .. ".ts") + elseif string.find(line, "composables") then + local composablePath = string.match(line, "'.-/(.-)'") + vim.cmd("cclose") + vim.cmd("edit " .. M.nuxt_directory_path .. "/composables/" .. composablePath .. ".ts") + elseif string.find(line, "utils") then + local utilsPath = string.match(line, "'.-/(.-)'") + vim.cmd("cclose") + vim.cmd("edit " .. M.nuxt_directory_path .. "/utils/" .. utilsPath .. ".ts") + else + vim.cmd("cclose") vim.cmd("edit " .. M.nuxt_directory_path .. "/" .. path) - break - elseif string.find(line, auto_import_file) then - if string.find(line, "stores") then - local storePath = string.match(line, "'.-/(.-)'") - vim.cmd("cclose") - vim.cmd("edit " .. M.nuxt_directory_path .. "/stores/" .. storePath .. ".ts") - elseif string.find(line, "composables") then - local composablePath = string.match(line, "'.-/(.-)'") - vim.cmd("cclose") - vim.cmd("edit " .. M.nuxt_directory_path .. "/composables/" .. composablePath .. ".ts") - elseif string.find(line, "utils") then - local utilsPath = string.match(line, "'.-/(.-)'") - vim.cmd("cclose") - vim.cmd("edit " .. M.nuxt_directory_path .. "/utils/" .. utilsPath .. ".ts") - else - vim.cmd("cclose") - vim.cmd("edit " .. M.nuxt_directory_path .. "/" .. path) - end - break end + M.it_worked = true + break end - end, 100) + end +end + +M.watch = function() + M.original_definition() + + if not M.is_nuxt_project then + return + end + + -- retry with exponential backoff + vim.defer_fn(redirect_if_auto_import, 10) + vim.defer_fn(redirect_if_auto_import, 50) + vim.defer_fn(redirect_if_auto_import, 100) + vim.defer_fn(redirect_if_auto_import, 1000) + vim.defer_fn(function() + M.it_worked = false + end, 1100) end return M