Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- folders will open a file picker
- see docs at <https://github.com/obsidian-nvim/obsidian.nvim/wiki/Attachment>
- `Note` class can carry a `template` field.
- LSP completion replaces completion plugin based completion.
- Frontmatter tag completion.

### Removed

Expand Down
36 changes: 17 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ The original project has not been actively maintained for quite a while and with

## ⭐ Features

▶️ **Completion:** Ultra-fast, asynchronous autocompletion for note references and tags via [nvim-cmp](https://github.com/hrsh7th/nvim-cmp) or [blink.cmp](https://github.com/Saghen/blink.cmp) (triggered by typing `[[` for wiki and markdown links, `#` for tags)
▶️ **Completion:** Ultra-fast, asynchronous autocompletion for note references and tags via in-process LSP (triggered by typing `[[` for wiki and markdown links, `#` for tags)

🏃 **Navigation:** Navigate throughout your vault via links, backlinks, tags and etc.

Expand Down Expand Up @@ -157,33 +157,31 @@ There's one entry point user command for this plugin: `Obsidian`

There's no required dependency, but there are a number of optional dependencies that enhance the obsidian.nvim experience.

**Completion:**

- [blink.cmp](https://github.com/Saghen/blink.cmp)
- [nvim-cmp](https://github.com/hrsh7th/nvim-cmp)

**Pickers:**

- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
- [fzf-lua](https://github.com/ibhagwan/fzf-lua)
- [mini.pick](https://github.com/echasnovski/mini.pick)
- [snacks.picker](https://github.com/folke/snacks.nvim/blob/main/docs/picker.md)
- **Pickers:**
- [telescope.nvim](https://github.com/nvim-telescope/telescope.nvim)
- [fzf-lua](https://github.com/ibhagwan/fzf-lua)
- [mini.pick](https://github.com/echasnovski/mini.pick)
- [snacks.picker](https://github.com/folke/snacks.nvim/blob/main/docs/picker.md)

To use a specific picker, set `picker.name` in your config, e.g.:

```lua
require"obsidian".setup {
picker = {
name = "snacks.picker", -- use snacks picker
require("obsidian").setup {
picker = {
name = "snacks.picker", -- use snacks picker
-- name = "telescope.nvim", -- or telescope
-- name = "fzf-lua", -- or fzf-lua
-- name = "mini.pick", -- or mini.pick
}}
},
}
```

**Image viewing:**
- **Image viewing:**
- [snacks.image](https://github.com/folke/snacks.nvim/blob/main/docs/image.md)
- See [Images](https://github.com/obsidian-nvim/obsidian.nvim/wiki/Images) for configuration.

- [snacks.image](https://github.com/folke/snacks.nvim/blob/main/docs/image.md)
- See [Images](https://github.com/obsidian-nvim/obsidian.nvim/wiki/Images) for configuration.
- **Completion**
- See [Completion](https://github.com/obsidian-nvim/obsidian.nvim/wiki/Completion)

## 📥 Installation

Expand Down
45 changes: 45 additions & 0 deletions docs/Completion.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
## Plugin Completion

This plugin provides plugin-agnostic completion via in-process LSP, you only need to make sure you are triggering LSP completions in markdown buffers.

For blink.cmp, if you have a dedicated `per_filetype` config for markdown, LSP completion will not attach, use:

```lua

require("blink.cmp").setup {
sources = {
-- NOTE: no need if you don't have custom markdown stuff
per_filetype = {
markdown = {
"lsp", -- NOTE: explicitly enable lsp
-- inherit_defaults = true, -- NOTE: if your defaults include lsp
"dictionary",
},
},
},
}
```

## Neovim Native Completion

To use completions without completion plugin, put this anywhere in your config before an obsidian buffer loads:

```lua
-- HACK: to trigger on every ASCII char, unicode will work when the upstream neovim completion respects isIncomplete field properly
local chars = {}
for i = 32, 126 do
table.insert(chars, string.char(i))
end

vim.api.nvim_create_autocmd("LspAttach", {
callback = function(ev)
local buf = ev.buf
local client = vim.lsp.get_client_by_id(ev.data.client_id)
if client and client.name == "obsidian-ls" then
client.server_capabilities.completionProvider.triggerCharacters = chars -- HACK:
vim.bo[buf].completeopt = "menuone,noselect,fuzzy,nosort" -- noselect to make sure no accidentally accept and create new notes, others are not strictly necessary, adjust to your taste, see `:h completeopt'
vim.lsp.completion.enable(true, client.id, buf, { autotrigger = true })
end
end,
})
```
2 changes: 1 addition & 1 deletion docs/LSP-Progress.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ Tracking implementation status of [LSP 3.17](https://microsoft.github.io/languag
- [x] Rename (`textDocument/rename`) - rename notes and update all references across the vault
- [x] Prepare Rename (`textDocument/prepareRename`)
- [x] Code Action (`textDocument/codeAction`)
- [x] Completion Proposals (`textDocument/completion`)
- [ ] Hover (`textDocument/hover`)
- [ ] Completion Proposals (`textDocument/completion`) - currently handled outside LSP via nvim-cmp/blink.cmp
- [ ] Completion Item Resolve (`completionItem/resolve`)
- [ ] Publish Diagnostics (`textDocument/publishDiagnostics`)
- [ ] Code Action Resolve (`codeAction/resolve`)
Expand Down
19 changes: 18 additions & 1 deletion lua/obsidian/actions.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ local api = require "obsidian.api"
local log = require "obsidian.log"
local util = require "obsidian.util"
local Note = require "obsidian.note"
local Path = require "obsidian.path"
local attachment = require "obsidian.attachment"
local picker = require "obsidian.picker"

Expand Down Expand Up @@ -486,7 +487,10 @@ M.new = function(id, callback)
end
end

local note = Note.create { id = id, template = Obsidian.opts.note.template }
local note = Note.create {
id = id,
template = Obsidian.opts.note.template,
}
note:write()

if callback then
Expand Down Expand Up @@ -836,4 +840,17 @@ M.merge_note = function(dst_note)
end
end

--- write note to disk, for lsp completion create note
---
---@param note obsidian.Note
M.write_note = function(note)
-- Make sure `note` is actually an `obsidian.Note` object.
-- If it gets serialized by server commands, it will lose its metatable.
if not Note.is_note_obj(note) then
note = setmetatable(note, Note)
note.path = setmetatable(note.path, Path)
end
note:write()
end

return M
7 changes: 0 additions & 7 deletions lua/obsidian/autocmds.lua
Original file line number Diff line number Diff line change
Expand Up @@ -59,13 +59,6 @@ local function bufenter_callback(ev)
end, { buffer = true, desc = "Obsidian Previous Link" })
end

-- Inject completion sources, providers to their plugin configurations
if opts.completion.nvim_cmp then
require("obsidian.completion.plugin_initializers.nvim_cmp").inject_sources()
elseif opts.completion.blink then
require("obsidian.completion.plugin_initializers.blink").inject_sources()
end

require("obsidian.lsp").start(ev.buf)

if opts.footer.enabled then
Expand Down
3 changes: 1 addition & 2 deletions lua/obsidian/commands/new.lua
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
---@param data obsidian.CommandArgs
return function(data)
local id = data.args:len() > 0 and data.args
---@diagnostic disable-next-line: param-type-mismatch
local id = data.args:len() > 0 and data.args or nil
require("obsidian.actions").new(id, function(note)
note:open { sync = true }
end)
Expand Down
2 changes: 1 addition & 1 deletion lua/obsidian/commands/new_from_template.lua
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ return function(data)
local id = table.concat(data.fargs, " ", 1, #data.fargs - 1)
local template = data.fargs[#data.fargs]
require("obsidian.actions").new_from_template(id, template, function(note)
note:open()
note:open { sync = true }
end)
end
6 changes: 0 additions & 6 deletions lua/obsidian/completion/init.lua

This file was deleted.

188 changes: 0 additions & 188 deletions lua/obsidian/completion/plugin_initializers/blink.lua

This file was deleted.

Loading
Loading