Added obsidian.nvim

This commit is contained in:
Radu Macocian (admac)
2026-03-05 15:28:06 +01:00
parent 618a85305d
commit d50d665994
4 changed files with 173 additions and 18 deletions

View File

@@ -5,6 +5,27 @@ local previewers = require("telescope.previewers")
local actions = require("telescope.actions")
local action_state = require("telescope.actions.state")
local STOP_WORDS = {
["a"] = true,
["an"] = true,
["and"] = true,
["as"] = true,
["at"] = true,
["by"] = true,
["for"] = true,
["from"] = true,
["in"] = true,
["into"] = true,
["is"] = true,
["of"] = true,
["on"] = true,
["or"] = true,
["that"] = true,
["the"] = true,
["to"] = true,
["with"] = true,
}
local function parse_query_mode(raw_query)
local query = vim.trim(raw_query or "")
if query:match("^text:%s*") then
@@ -26,6 +47,106 @@ local function parse_query_mode(raw_query)
return looks_like_type and "type" or "text", query
end
local function run_hoogle_query(query, count)
local cmd = { "hoogle", ("--count=%d"):format(count or 200), "--json", query }
local lines = vim.fn.systemlist(cmd)
if vim.v.shell_error ~= 0 then
return nil, "hoogle failed:\n" .. table.concat(lines, "\n")
end
local ok, parsed = pcall(vim.json.decode, table.concat(lines, "\n"))
if not ok or type(parsed) ~= "table" then
return nil, "hoogle returned unexpected output"
end
return parsed, nil
end
local function normalize_docs(docs)
return vim.trim((docs or ""):gsub("<.->", " "):gsub("%s+", " "):lower())
end
local function tokenize_text_query(query)
local tokens = {}
local seen = {}
for token in query:lower():gmatch("[%w_]+") do
if #token >= 3 and not STOP_WORDS[token] and not seen[token] then
seen[token] = true
table.insert(tokens, token)
end
end
return tokens
end
local function hoogle_text_search(query)
local tokens = tokenize_text_query(query)
if #tokens == 0 then
tokens = { query:lower() }
end
local ranked = {}
local order = {}
local function bump(entry, token, base_score)
local key = entry.url or entry.item or (entry.module and entry.module.name) or vim.inspect(entry)
local slot = ranked[key]
if not slot then
slot = { entry = entry, score = 0 }
ranked[key] = slot
table.insert(order, key)
end
local signature = (entry.item or ""):lower()
local docs = normalize_docs(entry.docs)
if signature:find(token, 1, true) then
slot.score = slot.score + base_score + 2
end
if docs:find(token, 1, true) then
slot.score = slot.score + base_score
end
end
local exact, err = run_hoogle_query(query, 200)
if exact then
for _, entry in ipairs(exact) do
bump(entry, query:lower(), 8)
end
end
for i = 1, math.min(#tokens, 6) do
local token = tokens[i]
local partial, partial_err = run_hoogle_query(token, 120)
if partial then
for _, entry in ipairs(partial) do
bump(entry, token, 3)
end
elseif not err then
err = partial_err
end
end
local items = {}
for _, key in ipairs(order) do
local slot = ranked[key]
if slot and slot.score > 0 then
table.insert(items, slot)
end
end
table.sort(items, function(a, b)
return a.score > b.score
end)
local out = {}
for _, slot in ipairs(items) do
table.insert(out, slot.entry)
end
if #out == 0 and err then
return nil, err
end
return out, nil
end
local function hoogle_picker(query)
if vim.fn.executable("hoogle") ~= 1 then
vim.notify("hoogle not found in PATH", vim.log.levels.ERROR)
@@ -37,24 +158,14 @@ local function hoogle_picker(query)
return
end
local cmd = { "hoogle", "--count=200", "--json" }
local decoded, err
if mode == "text" then
table.insert(cmd, "--text")
end
table.insert(cmd, normalized_query)
local lines = vim.fn.systemlist(cmd)
if vim.v.shell_error ~= 0 then
vim.notify("hoogle failed:\n" .. table.concat(lines, "\n"), vim.log.levels.ERROR)
return
end
local decoded = nil
local ok, parsed = pcall(vim.json.decode, table.concat(lines, "\n"))
if ok and type(parsed) == "table" then
decoded = parsed
decoded, err = hoogle_text_search(normalized_query)
else
vim.notify("hoogle returned unexpected output", vim.log.levels.ERROR)
decoded, err = run_hoogle_query(normalized_query, 200)
end
if not decoded then
vim.notify(err or "hoogle failed", vim.log.levels.ERROR)
return
end

View File

@@ -0,0 +1,22 @@
require("snacks").setup {
image = {
enabled = true,
resolve = function(path, src)
local api = require "obsidian.api"
if api.path_is_note(path) then
return api.resolve_attachment_path(src)
end
end
},
indent = {
enabled = true,
indent = {
enabled = true,
char = ""
},
scope = {
enabled = true,
char = ""
}
}
}

View File

@@ -14,7 +14,8 @@
"mason-lspconfig.nvim": { "branch": "main", "commit": "a324581a3c83fdacdb9804b79de1cbe00ce18550" },
"mason.nvim": { "branch": "main", "commit": "44d1e90e1f66e077268191e3ee9d2ac97cc18e65" },
"mini.icons": { "branch": "main", "commit": "5b9076dae1bfbe47ba4a14bc8b967cde0ab5d77e" },
"neogit": { "branch": "master", "commit": "515e8cb9c3430a064ec3d9affd499b94f71b3120" },
"neogit": { "branch": "master", "commit": "7073f3aafc9030d457838995106784a9d1873b3b" },
"nord.nvim": { "branch": "master", "commit": "80c1e5321505aeb22b7a9f23eb82f1e193c12470" },
"nvim-cmp": { "branch": "main", "commit": "da88697d7f45d16852c6b2769dc52387d1ddc45f" },
"nvim-dap": { "branch": "master", "commit": "b516f20b487b0ac6a281e376dfac1d16b5040041" },
"nvim-dap-python": { "branch": "master", "commit": "1808458eba2b18f178f990e01376941a42c7f93b" },
@@ -24,13 +25,15 @@
"nvim-scrollbar": { "branch": "main", "commit": "f8e87b96cd6362ef8579be456afee3b38fd7e2a8" },
"nvim-treesitter": { "branch": "master", "commit": "42fc28ba918343ebfd5565147a42a26580579482" },
"nvim-web-devicons": { "branch": "master", "commit": "737cf6c657898d0c697311d79d361288a1343d50" },
"obsidian.nvim": { "branch": "main", "commit": "eb2dde1e164ffcfba51216262bc43b9ed52da046" },
"odoo-neovim": { "branch": "main", "commit": "882aeb9bc0d6302cb99aa1235abe4820532fd416" },
"oil.nvim": { "branch": "master", "commit": "0fcc83805ad11cf714a949c98c605ed717e0b83e" },
"persistence.nvim": { "branch": "main", "commit": "b20b2a7887bd39c1a356980b45e03250f3dce49c" },
"plenary.nvim": { "branch": "master", "commit": "b9fd5226c2f76c951fc8ed5923d85e4de065e509" },
"render-markdown.nvim": { "branch": "main", "commit": "1641b434bda26e0f4e3610985b3357fc213cf834" },
"render-markdown.nvim": { "branch": "main", "commit": "bd482f9a4827c9422231a7db1439c5cff1e69ae0" },
"roslyn.nvim": { "branch": "main", "commit": "7deb9bb5b6afcb3c03c70741c6d364ffd8b59bda" },
"smear-cursor.nvim": { "branch": "main", "commit": "c85bdbb25db096fbcf616bc4e1357bd61fe2c199" },
"snacks.nvim": { "branch": "main", "commit": "9912042fc8bca2209105526ac7534e9a0c2071b2" },
"telescope-ui-select.nvim": { "branch": "master", "commit": "6e51d7da30bd139a6950adf2a47fda6df9fa06d2" },
"telescope.nvim": { "branch": "master", "commit": "5255aa27c422de944791318024167ad5d40aad20" },
"undotree": { "branch": "master", "commit": "d8f99084d98c32f651860eb0baaf89759f91debc" },

View File

@@ -28,6 +28,9 @@ require("lazy").setup({
vim.cmd('colorscheme everforest')
end
},
{
'shaunsingh/nord.nvim'
},
'odoo/odoo-neovim',
'nvim-treesitter/nvim-treesitter',
{
@@ -71,6 +74,22 @@ require("lazy").setup({
}
},
'williamboman/mason.nvim',
{
'obsidian-nvim/obsidian.nvim',
ft = "markdown",
--- @module 'obsidian'
--- @type obsidian.config
opts = {
legacy_commands = false,
workspaces = {
{
name = "personal",
path = "~/notes",
}
}
}
},
"folke/snacks.nvim",
'lewis6991/gitsigns.nvim',
'tpope/vim-projectionist',
'williamboman/mason-lspconfig.nvim',