From ace9a4d43162fbb4e79dd85b444786471b0d0000 Mon Sep 17 00:00:00 2001 From: sadguitarius Date: Fri, 15 Mar 2024 22:40:19 -0700 Subject: [PATCH 1/4] fix doc search for methods on lines starting with class name and respect windows path separators --- lua/scnvim/help.lua | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/lua/scnvim/help.lua b/lua/scnvim/help.lua index 6316cdeb..e05846d6 100644 --- a/lua/scnvim/help.lua +++ b/lua/scnvim/help.lua @@ -26,16 +26,16 @@ local M = {} --- The default is to open a split buffer. ---@param err nil on success or reason of error ---@param uri Help file URI ----@param pattern (optional) move cursor to line matching regex pattern -M.on_open = action.new(function(err, uri, pattern) +---@param method (optional) move cursor to line matching regex pattern +M.on_open = action.new(function(err, uri, subject, method) if err then utils.print(err) return end local is_open = vim.fn.win_gotoid(win_id) == 1 local expr = string.format('edit %s', uri) - if pattern then - expr = string.format('edit +/%s %s', pattern, uri) + if method then + expr = string.format('edit +/^\\\\(%s\\\\)\\\\?%s %s', subject, method, uri) end if is_open then vim.cmd(expr) @@ -112,13 +112,19 @@ local function open_from_quickfix(index) local item = list[index] if item then local uri = vim.fn.bufname(item.bufnr) + local isWindows = (vim.fn.has 'win32' == 1) and not vim.env.MSYSTEM + if isWindows then + uri = uri:gsub('\\', '/') + end + local cmd = string.format('SCNvim.getFileNameFromUri("%s")', uri) if uv.fs_stat(uri) then - M.on_open(nil, uri, item.pattern) + sclang.eval(cmd, function(subject) + M.on_open(nil, uri, subject, item.text) + end) else - local cmd = string.format('SCNvim.getFileNameFromUri("%s")', uri) sclang.eval(cmd, function(subject) render_help_file(subject, function(result) - M.on_open(nil, result, item.pattern) + M.on_open(nil, result, subject, item.text) end) end) end @@ -169,7 +175,6 @@ local function find_methods(name, target_dir) table.insert(results, { filename = destpath, text = string.format('.%s', name), - pattern = string.format('^\\.%s', name), }) end end From 4559e85a4a6baab43393657dfdaff084439d00ad Mon Sep 17 00:00:00 2001 From: sadguitarius Date: Tue, 19 Mar 2024 08:09:11 -0700 Subject: [PATCH 2/4] replace Windows check with built-in function --- lua/scnvim/help.lua | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lua/scnvim/help.lua b/lua/scnvim/help.lua index e05846d6..ea6725bc 100644 --- a/lua/scnvim/help.lua +++ b/lua/scnvim/help.lua @@ -112,8 +112,7 @@ local function open_from_quickfix(index) local item = list[index] if item then local uri = vim.fn.bufname(item.bufnr) - local isWindows = (vim.fn.has 'win32' == 1) and not vim.env.MSYSTEM - if isWindows then + if _path.get_system() == 'windows' then uri = uri:gsub('\\', '/') end local cmd = string.format('SCNvim.getFileNameFromUri("%s")', uri) From 7c3e849e30140bfbc744d79693ab837d8888734a Mon Sep 17 00:00:00 2001 From: sadguitarius Date: Mon, 8 Apr 2024 23:49:16 -0700 Subject: [PATCH 3/4] PR changes --- lua/scnvim/help.lua | 24 +++++++++--------------- 1 file changed, 9 insertions(+), 15 deletions(-) diff --git a/lua/scnvim/help.lua b/lua/scnvim/help.lua index ea6725bc..372dc030 100644 --- a/lua/scnvim/help.lua +++ b/lua/scnvim/help.lua @@ -26,16 +26,17 @@ local M = {} --- The default is to open a split buffer. ---@param err nil on success or reason of error ---@param uri Help file URI ----@param method (optional) move cursor to line matching regex pattern -M.on_open = action.new(function(err, uri, subject, method) +---@param pattern (optional) move cursor to line matching regex pattern +M.on_open = action.new(function(err, uri, pattern) if err then utils.print(err) return end local is_open = vim.fn.win_gotoid(win_id) == 1 local expr = string.format('edit %s', uri) - if method then - expr = string.format('edit +/^\\\\(%s\\\\)\\\\?%s %s', subject, method, uri) + if pattern then + local subject = vim.fn.fnamemodify(uri, ':t:r') + expr = string.format('edit +/^\\\\(%s\\\\)\\\\?%s %s', subject, pattern, uri) end if is_open then vim.cmd(expr) @@ -112,19 +113,12 @@ local function open_from_quickfix(index) local item = list[index] if item then local uri = vim.fn.bufname(item.bufnr) - if _path.get_system() == 'windows' then - uri = uri:gsub('\\', '/') - end - local cmd = string.format('SCNvim.getFileNameFromUri("%s")', uri) + local subject = vim.fn.fnamemodify(uri, ':t:r') if uv.fs_stat(uri) then - sclang.eval(cmd, function(subject) - M.on_open(nil, uri, subject, item.text) - end) + M.on_open(nil, uri, subject, item.text) else - sclang.eval(cmd, function(subject) - render_help_file(subject, function(result) - M.on_open(nil, result, subject, item.text) - end) + render_help_file(subject, function(result) + M.on_open(nil, result, item.text) end) end end From 5bb0faa26e512f9991a63fac5cd1998380f2013b Mon Sep 17 00:00:00 2001 From: sadguitarius Date: Thu, 18 Apr 2024 11:29:36 -0700 Subject: [PATCH 4/4] fix incorrect on_open method call --- lua/scnvim/help.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/scnvim/help.lua b/lua/scnvim/help.lua index 372dc030..0f47b1ff 100644 --- a/lua/scnvim/help.lua +++ b/lua/scnvim/help.lua @@ -115,7 +115,7 @@ local function open_from_quickfix(index) local uri = vim.fn.bufname(item.bufnr) local subject = vim.fn.fnamemodify(uri, ':t:r') if uv.fs_stat(uri) then - M.on_open(nil, uri, subject, item.text) + M.on_open(nil, uri, item.text) else render_help_file(subject, function(result) M.on_open(nil, result, item.text)