From 87afce33982e532d14931a5c5feecdf97ee9d7d2 Mon Sep 17 00:00:00 2001
From: n451 <2020200706@ruc.edu.cn>
Date: Sun, 6 Oct 2024 23:39:51 +0800
Subject: [PATCH] feat: telescope integration with highted buffer and line wrap
fix: remove a few test files for treedoc
---
lua/telescope/_extensions/feed.lua | 20 ++---
spec/conv_spec.lua | 60 ---------------
spec/date_spec.lua | 10 ---
spec/treedoc_spec.lua | 117 -----------------------------
4 files changed, 10 insertions(+), 197 deletions(-)
delete mode 100644 spec/conv_spec.lua
delete mode 100644 spec/treedoc_spec.lua
diff --git a/lua/telescope/_extensions/feed.lua b/lua/telescope/_extensions/feed.lua
index e016ae3..0af685d 100644
--- a/lua/telescope/_extensions/feed.lua
+++ b/lua/telescope/_extensions/feed.lua
@@ -9,6 +9,7 @@ local conf = require("telescope.config").values
local actions = require "telescope.actions"
local action_state = require "telescope.actions.state"
local previewers = require "telescope.previewers"
+local highlighter = require("telescope.previewers.utils").highlighter
local config = require "feed.config"
local db = require("feed.db").db(config.db_dir)
@@ -25,38 +26,37 @@ local function feed(opts)
pickers
.new(opts, {
prompt_title = "Feeds",
+
previewer = previewers.new_buffer_previewer {
- --- TODO: attach highlighter! format content on disk to markdown
define_preview = function(self, entry, _)
local db_entry = db:address(db.index[entry.index])
conf.buffer_previewer_maker(db_entry, self.state.bufnr, {
bufname = self.state.bufname,
- winid = self.state.winid,
- preview = opts.preview,
- file_encoding = opts.file_encoding,
})
+ highlighter(self.state.bufnr, "markdown")
+ vim.api.nvim_set_option_value("wrap", true, { win = self.state.winid })
end,
},
finder = finders.new_table {
results = lines,
},
- attach_mappings = function(prompt_bufnr, map)
+ attach_mappings = function(prompt_bufnr)
actions.select_default:replace(function()
actions.close(prompt_bufnr)
local selection = action_state.get_selected_entry()
- local entry = db.index[selection.index]
- render.show(format.entry(entry, db:get(entry)), render.buf.entry[2], ut.highlight_entry)
+ if not render.buf then
+ render.prepare_bufs(require("feed.commands").cmds)
+ end
+ render.show_entry(selection.index)
end)
return true
end,
- sorter = conf.generic_sorter(opts), -- TODO: sort by date?
+ sorter = conf.generic_sorter(opts),
})
:find()
end
return telescope.register_extension {
- setup = function(ext_config, usr_config) end,
- -- health = lp_health,
exports = {
feed = feed,
},
diff --git a/spec/conv_spec.lua b/spec/conv_spec.lua
deleted file mode 100644
index 2871528..0000000
--- a/spec/conv_spec.lua
+++ /dev/null
@@ -1,60 +0,0 @@
-local treedoc = require "treedoc"
-local conv = require "treedoc.conv.markdown"
-
-package.path = package.path .. ";/home/n451/.local/share/nvim/lazy/plenary.nvim/lua/?.lua"
-local eq = assert.are.same
-
-local function md(str)
- vim.treesitter.language.add("html", {
- path = vim.fn.expand "~/.local/share/nvim/lazy/nvim-treesitter/parser/html.so",
- })
- return conv(treedoc.parse(str, { language = "html" })[1])
-end
-
-describe("markdown", function()
- it("should convert simple element", function()
- local res = md [[
sdasdad
]]
- local expected = "## sdasdad"
- eq(expected, res)
- end)
-
- it("should do attr", function()
- local res = md [[google]]
- local expected = "[google](google.com)"
- eq(expected, res)
- end)
-
- it("should do nested", function()
- local res = md [[]]
- local expected = "# [google](g.com)"
- eq(expected, res)
- end)
-
- it("img", function()
- local src = [[]]
- local expected = "![image](https://erbingeditor.diershoubing.com/38/2024/09/06/0938026436.jpg)"
- local res = md(src)
- eq(expected, res)
- end)
-
- it("should convert markdown to html", function()
- local src = [[
-
-
Heading
-
Heading2
-
- - google is shasdasd
- - Item 2
-
-
-
-]]
- local expected = [[# Heading
-## Heading2
-1. [google](g.com) is shasdasd
-2. Item 2
-3. ![image](https://erbingeditor.diershoubing.com/38/2024/09/06/0938026436.jpg)]]
- local res = md(src)
- eq(expected, res)
- end)
-end)
diff --git a/spec/date_spec.lua b/spec/date_spec.lua
index 86039ba..80cad45 100644
--- a/spec/date_spec.lua
+++ b/spec/date_spec.lua
@@ -1,13 +1,3 @@
--- local tests = {
--- { "@5-days-ago--3-days-ago", 5, 3 },
--- { "@3-days-ago--5-days-ago", 5, 3 },
--- { "@2019-06-01", 23 },
--- { "@2019-06-20--2019-06-01", 23, 4 },
--- { "@2019-06-01--2019-06-20", 23, 4 },
--- { "@2019-06-01--4-days-ago", 23, 4 },
--- { "@4-days-ago--2019-06-01", 23, 4 },
--- }
-
local M = require "feed.date"
describe("new_from", function()
diff --git a/spec/treedoc_spec.lua b/spec/treedoc_spec.lua
deleted file mode 100644
index c6d6d4c..0000000
--- a/spec/treedoc_spec.lua
+++ /dev/null
@@ -1,117 +0,0 @@
-package.path = package.path .. ";/home/n451/.local/share/nvim/lazy/plenary.nvim/lua/?.lua"
-
-vim.treesitter.language.add("html", {
- path = vim.fn.expand "~/.local/share/nvim/lazy/nvim-treesitter/parser/html.so",
-})
-
-vim.treesitter.language.add("xml", {
- path = vim.fn.expand "~/.local/share/nvim/lazy/nvim-treesitter/parser/xml.so",
-})
-
-local treedoc = require "treedoc"
-local eq = assert.are.same
-
-local sourced_file = require("plenary.debug_utils").sourced_filepath()
-local data_dir = vim.fn.fnamemodify(sourced_file, ":h") .. "/data/"
-
-local function xml(src)
- return treedoc.parse(src, { language = "xml" })
-end
-
-local function html(src)
- return treedoc.parse(src, { language = "html" })
-end
-
-describe("xml", function()
- it("should do simple elements", function()
- eq({ title = "arch by the way" }, xml("arch by the way")[1])
- end)
- it("should do nested elements", function()
- local src2 = [[
-
- arch
- https://archlinux.org/feeds/news/
-
-
]]
- local expected = {
- pre = {
- channel = {
- title = "arch",
- link = "https://archlinux.org/feeds/news/",
- },
- },
- }
- eq(expected, xml(src2)[1])
- end)
- it("should do attrs", function()
- local src = [[rss feeds here]]
- local expected = { rss = { version = "2.0", [1] = "rss feeds here" } }
- eq(expected, xml(src)[1])
- end)
- it("should do self closing tags", function()
- local src = [[]]
- eq({ outline = { a = "b", c = "d" } }, xml(src)[1])
- end)
- it("should put same named tags into one array", function()
- local src = [[
-- 1
-- 2
-- 3
-]]
- local expected = { rss = { item = { "1", "2", "3" } } }
- eq(expected, xml(src)[1])
- end)
-end)
-
-local function readfile(path)
- local str = vim.fn.readfile(data_dir .. path)
- return table.concat(str)
-end
-
-describe("acutual opml list", function()
- it("should produce simple lua table", function()
- -- local str = readfile "opml_example.opml"
- local str =
- [[中文独立博客列表
-
-
-]]
- local ast = xml(str)[1]
- Pr(ast)
- eq("中文独立博客列表", ast.opml.head.title)
- eq("1.0", ast.opml.version)
- end)
-end)
-
-describe("html", function()
- it("should parse simple elements", function()
- local src = [[asdasd]]
- local ast = html(src)[1]
- eq({ tag = "html", a = "sda", "asdasd" }, ast)
- end)
- it("should parse self closing tags", function()
- local src = [[