-
Notifications
You must be signed in to change notification settings - Fork 215
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support blink.nvim Autocomplete #770
Comments
https://github.com/benlubas/cmp2lsp may do the trick in the meantime? I don't know what obsidian.nvim's source name would be though, nor if it's guaranteed to be exposed |
Especially, now that lazyvim has an extra for blink.nvim, I guess more and more will switch. There is also https://github.com/Saghen/blink.compat. It would be great to have an example in the docs how to configure it properly. 🤗 Edit: return {
{ "saghen/blink.compat" },
{
"saghen/blink.cmp",
dependencies = {
{ "epwalsh/obsidian.nvim" },
},
opts_extend = { "sources.completion.enabled_providers" },
---@module 'blink.cmp'
---@type blink.cmp.Config
opts = {
sources = {
completion = {
enabled_providers = {
"lsp",
"path",
"snippets",
"buffer",
"obsidian",
"obsidian_new",
"obsidian_tags",
},
},
providers = {
obsidian = {
name = "obsidian",
module = "blink.compat.source",
},
obsidian_new = {
name = "obsidian_new",
module = "blink.compat.source",
},
obsidian_tags = {
name = "obsidian_tags",
module = "blink.compat.source",
},
},
},
},
},
} The error:
I guess https://github.com/epwalsh/obsidian.nvim/blob/main/lua/obsidian/init.lua#L143-L158 this block should be guarded. |
I got autocomplete for links at least (not sure what else obsidian.nvim might provide) using the marksman language server |
The permanent solution would be a LSP, not support for any given completion, cpm and blinks comes and goes. For example Neorg has its own mini LSP, you wont need to configure cmp for it |
LazyVim last update removed nvim-cmp in favor of blink-cmd. It would be great to see Obsidian.nvim support it ! |
Actually I take this back, I say obsidian notes are markdowns anyway, and we already have markdown LSP, so we don't need to reinvent the wheel, the mentioned LSP already supports document linking auto complete, tag auto complete, insert TOC, tree sitter highlights are also available, other functionality like toggle checkboxs etc. actually I disabled the obsidian plugin entirely and I could do almost my daily workflow on my vaults. In my humble opinion, the easiest, still most maintainable and extendable breakthrough, is to keep obsidian plugin, only related to obsidian specific functionalities like managing the vaults, referencing the tags/files (BY USING THE MD LSP, again not reinventing the wheel), front matter, opening the MD in obsidian etc. Managing the highlights, auto complete anything, toggle the checkbox etc are done more maturely in markdown lsp |
Yep, would be awesome! My workaround is to enable nvim-cmp again in the extras. |
|
@yuchenfei doesn't this still require nvim cmp to be installed? |
It does. You're registering obsidian sources with cmp and then using them in blink. It's a workaround not a replacement right now. |
Yes, it still requires nvim-cmp, but it only loads when completing in Obsidian notes. This is a workaround configuration to make it work for now. |
Oh, thank you. I initially did that without registering the source. I'll do this. |
@yuchenfei @sebszyller @Muizzyranking author of blink.compat here. FYI, when using blink.compat, nvim-cmp should not be installed. blink.compat mirrors the cmp api, including the |
I have been using the same above change mentioned by @yuchenfei and I am not sure if I am doing something wrong. I keep getting this error: Here's my obsidian lua configuration: return {
{
"epwalsh/obsidian.nvim",
version = "*",
lazy = false,
ft = "markdown",
dependencies = {
"nvim-lua/plenary.nvim",
},
opts = {
workspaces = {
{
name = "wiki",
path = "/Users/shivayanbora/PKM/My-Wiki-Vault",
},
},
new_notes_location = "notes_subdir",
notes_subdir = "0_inbox",
note_frontmatter_func = function(note)
-- Add the title of the note as an alias.
if note.title then
note:add_alias(note.title)
end
local out = {
id = note.id,
aliases = note.aliases,
tags = note.tags,
}
-- `note.metadata` contains any manually added fields in the frontmatter.
-- So here we just make sure those fields are kept in the frontmatter.
if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then
for k, v in pairs(note.metadata) do
out[k] = v
end
end
return out
end,
-- Optional, customize how note IDs are generated given an optional title.
---@param title string|?
---@return string
note_id_func = function(title)
-- Create note IDs in a Zettelkasten format with a timestamp and a suffix.
-- In this case a note with the title 'My new note' will be given an ID that looks
-- like '1657296016-my-new-note', and therefore the file name '1657296016-my-new-note.md'
local suffix = ""
if title ~= nil then
-- If title is given, transform it into valid file name.
suffix = title:gsub(" ", "-"):gsub("[^A-Za-z0-9-]", ""):lower()
else
-- If title is nil, just add 4 random uppercase letters to the suffix.
for _ = 1, 4 do
suffix = suffix .. string.char(math.random(65, 90))
end
end
return tostring(os.time()) .. "-" .. suffix
end,
-- Optional, customize how note file names are generated given the ID, target directory, and title.
---@param spec { id: string, dir: obsidian.Path, title: string|? }
---@return string|obsidian.Path The full path to the new note.
note_path_func = function(spec)
-- This is equivalent to the default behavior.
local path = spec.dir / tostring(spec.id)
return path:with_suffix(".md")
end,
templates = {
folder = "templates",
date_format = "%Y-%m-%d",
time_format = "%H:%M:%S",
},
completion = {
nvim_cmp = false,
min_chars = 2,
},
ui = {
enable = false,
},
},
config = function(_, opts)
require("obsidian").setup(opts)
local cmp = require("cmp")
cmp.register_source("obsidian", require("cmp_obsidian").new())
cmp.register_source("obsidian_new", require("cmp_obsidian_new").new())
cmp.register_source("obsidian_tags", require("cmp_obsidian_tags").new())
end,
},
{
"saghen/blink.cmp",
dependencies = { "saghen/blink.compat" },
opts = {
sources = {
default = { "obsidian", "obsidian_new", "obsidian_tags" },
providers = {
obsidian = {
name = "obsidian",
module = "blink.compat.source",
},
obsidian_new = {
name = "obsidian_new",
module = "blink.compat.source",
},
obsidian_tags = {
name = "obsidian_tags",
module = "blink.compat.source",
},
},
},
},
},
} |
@stefanboca could you post a config here to make it work with obsidian or maybe mention it in the blink readme? 😬 |
Just switch the blink.compat to main branch |
@CaeChao Am I doing this correctly? Sorry I am quite new to Neovim. return {
{
"epwalsh/obsidian.nvim",
version = "*",
lazy = false,
ft = "markdown",
dependencies = {
"nvim-lua/plenary.nvim",
},
opts = {
workspaces = {
{
name = "wiki",
path = "/Users/shivayanbora/PKM/My-Wiki-Vault",
},
},
new_notes_location = "notes_subdir",
notes_subdir = "0_inbox",
note_frontmatter_func = function(note)
-- Add the title of the note as an alias.
if note.title then
note:add_alias(note.title)
end
local out = {
id = note.id,
aliases = note.aliases,
tags = note.tags,
}
-- `note.metadata` contains any manually added fields in the frontmatter.
-- So here we just make sure those fields are kept in the frontmatter.
if note.metadata ~= nil and not vim.tbl_isempty(note.metadata) then
for k, v in pairs(note.metadata) do
out[k] = v
end
end
return out
end,
-- Optional, customize how note IDs are generated given an optional title.
---@param title string|?
---@return string
note_id_func = function(title)
-- Create note IDs in a Zettelkasten format with a timestamp and a suffix.
-- In this case a note with the title 'My new note' will be given an ID that looks
-- like '1657296016-my-new-note', and therefore the file name '1657296016-my-new-note.md'
local suffix = ""
if title ~= nil then
-- If title is given, transform it into valid file name.
suffix = title:gsub(" ", "-"):gsub("[^A-Za-z0-9-]", ""):lower()
else
-- If title is nil, just add 4 random uppercase letters to the suffix.
for _ = 1, 4 do
suffix = suffix .. string.char(math.random(65, 90))
end
end
return tostring(os.time()) .. "-" .. suffix
end,
-- Optional, customize how note file names are generated given the ID, target directory, and title.
---@param spec { id: string, dir: obsidian.Path, title: string|? }
---@return string|obsidian.Path The full path to the new note.
note_path_func = function(spec)
-- This is equivalent to the default behavior.
local path = spec.dir / tostring(spec.id)
return path:with_suffix(".md")
end,
templates = {
folder = "templates",
date_format = "%Y-%m-%d",
time_format = "%H:%M:%S",
},
completion = {
nvim_cmp = false,
min_chars = 2,
},
ui = {
enable = false,
},
},
config = function(_, opts)
require("obsidian").setup(opts)
local cmp = require("cmp")
cmp.register_source("obsidian", require("cmp_obsidian").new())
cmp.register_source("obsidian_new", require("cmp_obsidian_new").new())
cmp.register_source("obsidian_tags", require("cmp_obsidian_tags").new())
end,
},
{
"saghen/blink.cmp",
dependencies = {
{ "saghen/blink.compat", branch = "main" },
},
opts = {
sources = {
default = { "obsidian", "obsidian_new", "obsidian_tags" },
providers = {
obsidian = {
name = "obsidian",
module = "blink.compat.source",
},
obsidian_new = {
name = "obsidian_new",
module = "blink.compat.source",
},
obsidian_tags = {
name = "obsidian_tags",
module = "blink.compat.source",
},
},
},
},
},
} If yes, I am still getting the error: UPDATE: I deleted |
@shivayan-bora remove the part where you registered the source with CMP, blink compat's author said it wasn't necessary. |
@shivayan-bora I believe you also need |
@shivayan-bora my guess is that you are using LazyVim, so you need to put @Muizzyranking I think you still need the registered part above to make it work, |
It's working perfectly for me with this configuration: |
@CaeChao blink.compat author said it wasn't neccessary. @Alan-TheGentleman this is very similar to what I have too. |
Well, I've tried to follow all pieces of advice, but it doesn't work on my side… No more completion with my LazyVim config. I had to set nvim-cpm to false :( I guess I'll wait for the next obsidian.nvim version and I hope it will be able to auto-detect the config (for newbies like me !) when nvim-cmp is set to true. |
@celfred can you share a snippet of what you did? Because for LazyVim, there is a custom spec to pass in custom sources as a list so you won't have to add the module, look at this extra for example. I am not with my pc at the moment but if I see your config, I could help you write LazyVim compatible config. |
Thanks @Muizzyranking for this quick reply. What I've done so far :
Don't know if that explains anything… But thanks for your time ! |
@celfred As a workaround I suggest you use |
Well, I've read that suggestion too earlier, but I had no idea how to set up marksman LSP instead of what I'm using right now… |
@celfred I just got hold of my PC, first of all remove the hack to register source in obsidian with cmp, blink compat has it covered for blink {
"saghen/blink.cmp",
dependencies = {
{ "epwalsh/obsidian.nvim", "saghen/blink.compat" },
},
opts = {
sources = {
-- LazyVim as custom option copmpat to pass in external sources with blink.compat
compat = { "obsidian", "obsidian_new", "obsidian_tags" },
-- Optional to set kind name., not really neccesary.
-- providers = {
-- obsidian = {
-- kind = "Obsidian",
-- async = true,
-- },
-- obsidian_new = {
-- kind = "Obsidian",
-- async = true,
-- },
-- obsidian_tags = {
-- kind = "Obsidian",
-- async = true,
-- },
-- },
},
},
} To setup marksman lsp in lazyvim, go to your { import = "lazyvim.plugins.extras.lang.markdown" }, I will suggest you read LazyVim docs on how to extend/override plugins opts and importing extras. You might also need to peek the source code to get a better understanding. |
@Muizzyranking Your solution is basically ignoring the Obsidian source and replace it with Makrsman lsp as source. The author of blink.compat said The main branch of blink.compat has already implemented a workaround for obsidian
and put the |
@CaeChao putting |
@CaeChao @Muizzyranking Thanks a lot. Things are getting better (with a behavior a little different from what I used to have in case of completion suggestions).
And I had to set nvim-cmp to true in my obsidian.lua file. I have no error and completion works 😄 I'll enquire to try and understand how to 'modify' the suggestion list, but THANKS a lot for your help. |
@CaeChao what changed? |
to avoid having to have
some time before loading this plugin. Then if using the |
Using the method outlined here has it popup with a |
At the moment using #770 (comment) Thanks @CaeChao ! |
Things basically work after using method suggested by @CaeChao . There is one thing, I want to insert page link/tag link by using -- blink.lua
return {
"saghen/blink.cmp",
version = "*",
dependencies = {
{ "L3MON4D3/LuaSnip", version = "v2.*" },
{ "saghen/blink.compat", lazy = true, verson = false },
},
opts = {
snippets = { preset = "luasnip" },
keymap = { preset = "super-tab" },
appearance = {
use_nvim_cmp_as_default = true,
nerd_font_variant = "normal",
},
sources = {
default = { "lsp", "path", "snippets", "buffer", "obsidian", "obsidian_new", "obsidian_tags" },
providers = {
obsidian = { name = "obsidian", module = "blink.compat.source" },
obsidian_new = { name = "obsidian_new", module = "blink.compat.source" },
obsidian_tags = { name = "obsidian_tags", module = "blink.compat.source" },
},
cmdline = {},
},
signature = { enabled = true },
},
opts_extend = { "sources.default" },
} |
I think it might be due to completion.min_chars of obsidian.nvim |
@ericsunplus i think you need to have a markdown lsp. My config is very similar to yours and it works for me. |
Hi @Muizzyranking , I just install and configure the marksman LSP. Now |
Hi @rbmarliere , I try set |
@ericsunplus I generally don't expect completion from typing |
In the README doc of this obsidian plugin, it indicate that
So Thank you for the help anyway |
🚀 The feature, motivation and pitch
Currently obsidian.nvim does not work with blink.nvim, only with nvim-cmp. However, as blink is gaining popularity and becoming the default for many, compatibility between blink and obsidian would be very welcome.
Alternatives
No response
Additional context
No response
The text was updated successfully, but these errors were encountered: