From 2e9cbda5cf7bf8a2cb9680cb337a2565fd52f138 Mon Sep 17 00:00:00 2001 From: JINNOUCHI Yasushi Date: Fri, 25 Aug 2023 20:49:45 +0900 Subject: [PATCH] fix: use the default filetype for the prompt (#134) --- lua/frecency/picker.lua | 26 ++++++++++++++++++++++---- lua/frecency/types.lua | 2 ++ syntax/frecency.vim | 5 ----- 3 files changed, 24 insertions(+), 9 deletions(-) delete mode 100644 syntax/frecency.vim diff --git a/lua/frecency/picker.lua b/lua/frecency/picker.lua index bf2911c..97e8520 100644 --- a/lua/frecency/picker.lua +++ b/lua/frecency/picker.lua @@ -14,6 +14,7 @@ local uv = vim.loop or vim.uv ---@field private finder FrecencyFinder ---@field private fs FrecencyFS ---@field private lsp_workspaces string[] +---@field private namespace integer ---@field private recency FrecencyRecency ---@field private results table[] ---@field private workspace string? @@ -48,11 +49,12 @@ Picker.new = function(database, finder, fs, recency, config) finder = finder, fs = fs, lsp_workspaces = {}, + namespace = vim.api.nvim_create_namespace "frecency", recency = recency, results = {}, }, { __index = Picker }) local d = self.config.filter_delimiter - self.workspace_tag_regex = "^%s*(" .. d .. "(%S+)" .. d .. ")" + self.workspace_tag_regex = "^%s*" .. d .. "(%S+)" .. d return self end @@ -234,13 +236,30 @@ function Picker:on_input_filter_cb(state, picker_opts) local filepath_formatter = self:filepath_formatter(picker_opts) return function(prompt) local workspace - local matched, tag = prompt:match(self.workspace_tag_regex) - local opts = { prompt = matched and prompt:sub(matched:len() + 1) or prompt } + local start, finish, tag = prompt:find(self.workspace_tag_regex) + local opts = { prompt = start and prompt:sub(finish + 1) or prompt } if prompt == "" then workspace = self:get_workspace(picker_opts.cwd, self.config.initial_workspace_tag) else workspace = self:get_workspace(picker_opts.cwd, tag) or self.workspace end + local picker = state:get() + if picker then + local buf = picker.prompt_bufnr + vim.api.nvim_buf_clear_namespace(buf, self.namespace, 0, -1) + if start then + local prefix = picker.prompt_prefix + local start_col = #prefix + start - 1 + local end_col = #prefix + finish + vim.api.nvim_buf_set_extmark( + buf, + self.namespace, + 0, + start_col, + { end_row = 0, end_col = end_col, hl_group = "TelescopeQueryFilter" } + ) + end + end if self.workspace ~= workspace then self.workspace = workspace self.results = self:fetch_results(workspace) @@ -273,7 +292,6 @@ end ---@param bufnr integer ---@return nil function Picker:set_prompt_options(bufnr) - vim.bo[bufnr].filetype = "frecency" vim.bo[bufnr].completefunc = "v:lua.require'telescope'.extensions.frecency.complete" vim.keymap.set("i", "", "pumvisible() ? '' : ''", { buffer = bufnr, expr = true }) vim.keymap.set("i", "", "pumvisible() ? '' : ''", { buffer = bufnr, expr = true }) diff --git a/lua/frecency/types.lua b/lua/frecency/types.lua index 7fb44fa..e7fcd72 100644 --- a/lua/frecency/types.lua +++ b/lua/frecency/types.lua @@ -122,6 +122,8 @@ function PlenaryAsyncUtil.sleep(ms) end ---@field clear_extra_rows fun(self: TelescopePicker, results_bufnr: integer): nil ---@field get_row fun(self: TelescopePicker, index: integer): integer ---@field manager TelescopeEntryManager|false +---@field prompt_bufnr integer +---@field prompt_prefix string ---@field results_bufnr integer? ---@field results_win integer? ---@field sorting_strategy 'ascending'|'descending' diff --git a/syntax/frecency.vim b/syntax/frecency.vim deleted file mode 100644 index 92ad9e9..0000000 --- a/syntax/frecency.vim +++ /dev/null @@ -1,5 +0,0 @@ -if exists('b:current_syntax') | finish| endif - -syntax match WorkspaceFilter /:.\{-}:/ -hi def link WorkspaceFilter TelescopeQueryFilter -