-
Notifications
You must be signed in to change notification settings - Fork 132
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
Providing a Language Server (LSP) #22
Comments
Tested this out, it's very cool! I am seeing an issue using go to definition with neovim builtin lsp, but i'm not sure if that's a neovim problem or a zk problem. The error is Log2021/04/04 21:00:24.323 DEBUG [zk.rpc] jsonrpc2: <-- result #26: textDocument/definit ion: {"uri":{"start":{"line":7,"character":0},"end":{"line":7,"character":8}},"target Uri":"file:///Users/mitchell/Dropbox/notes/zk/gznd.md","targetRange":{"start":{"line" :0,"character":0},"end":{"line":0,"character":0}},"targetSelectionRage":{"start":{"li ne":0,"character":0},"end":{"line":0,"character":0}}} |
@mhanberg It was actually caused by a bug in a third-party dependency. I opened a PR but forgot to disable the faulty portion in
Btw, I tried the builtin LSP but couldn't make the trigger characters work for the completion. Did you setup anything special for this? |
I updated and go to def works now 👍.
I use nvim-compe for completion. |
@mickael-menu first off, this is so great! I've been using it with A couple items I've noticed.
Other than those two minor items, this has been fantastic to use! |
I set up the links for my own usage and I usually prefer to omit the extension. But I'll let users configure the format of the generated links in the config later on. However, the link href is matched as a prefix of the actual path, so it should work without the extension or if you have a unique ID prefix. For example,
This is expected, because a normal #hashtag can't contain spaces, so I added this ad-hoc escape syntax if an existing tag contains spaces. But if you enable Bear's multi-word tags syntax in the config, instead of using |
Thanks @mickael-menu .. I'm still playing around with this to get a repro case for you. I think I might be using something wrong; meaning, I'm looking to be able to |
Ahh, I'm wondering if certain characters in a filename or title might be breaking completion? Will check the logs to verify this. When searching for a note (using |
Yes right now the completion is on the note title (heading or YAML frontmatter) and not on the file path. I intend to add both in the completion filter later. I'll open a new issue for the special characters. |
Go to definition seems to be working when the current note is in the root of the notebook, but not when the note is in a sub-directory. I noticed this when implementing the "daily journal" example from the docs. |
@mhanberg Thanks for spotting that, should be fixed in |
I merged in a way to specify the completion link format from the user configuration: #32 [format.markdown]
# Format used to generate links between notes.
# Either "wiki", "markdown" or a custom template. Default is "markdown".
link-format = "wiki"
# Indicates whether a link's path will be percent-encoded.
link-encode-path = false
# Indicates whether a link's path file extension will be removed.
link-drop-extension = true Incidentally, internal link completion is triggered only with |
@mickael-menu .. one thing i've noticed recently (not sure if it's a zk lsp implementation or related to neovim's lspconfig and native LS client implementation), is that when trying to "select" a completion item that has spaces it will break the selection and you'll end up with just Thanks! |
Oh man, update; turns out bullets.vim was the culprit :( that's a bummer. Soooo.. please ignore my above question. |
Ha that's interesting because I actually had the same issue with coc.nvim, which was considering spaces as the end of the completion item for some reason. I had to set this in its settings to make it work: {
// Important, otherwise link completion containing spaces and other special characters won't work.
"suggest.invalidInsertCharacters": []
} |
I created a Visual Studio Code client extension for |
In case anyone else gets stuck when using Pandoc in Vim, just add E.g:
|
On a related note, does filtering the tag/note auto-completion work? If I enter the trigger character ( |
@ZachariasLenz Thanks, I'll add this to the documentation!
It depends what you expect but with coc.nvim I can filter though the auto-completion list with fuzzy-matching. It matches the notes' title and their path (which is hidden from the completion items).
I'm not sure what you mean by non-LSP auto-completion? Would you be able to record a screencast? |
@mickael-menu see the screencast for an example of what I mean: scrrencast_lsp_completion.mp4 |
@ZachariasLenz Thanks, this definitely doesn't look right. I'm not sure what could be the problem as I'm not using NeoVim's built-in LSP yet. Do you have any idea @megalithic? (Nice color scheme ;)) Here's how it looks like with coc.nvimzk-autocomplete2.mov |
I just merged some pretty exciting new LSP features. I added two code actions to create a new note using the text selection as title. Either in the current directory, or the root/top directory. It will convert the selection to a link to the newly created note. This feature builds on new custom LSP commands: lsp-actions.movYou will need a bit of configuration to add user commands and shortcuts exposing This is my coc.nvim config: ~/.config/nvim/init.vimcommand! -nargs=0 ZkIndex :call CocAction("runCommand", "zk.index", expand("%:p"))
command! -nargs=? ZkNew :exec "edit ".CocAction("runCommand", "zk.new", expand("%:p"), <args>).path
nnoremap <leader>zi :ZkIndex<CR>
nnoremap <leader>zn :ZkNew {"title": input("Title: ")}<CR>
nnoremap <leader>zl :ZkNew {"dir": "log"}<CR> (Note the cool keybinding which prompts for a title: And here's with built-in Neovim LSP client: ~/.config/nvim/init.vimcommand! -nargs=0 ZkIndex :lua require'lspconfig'.zk.index()
command! -nargs=? ZkNew :lua require'lspconfig'.zk.new(<args>)
lua << EOF
local lspconfig = require'lspconfig'
local configs = require'lspconfig/configs'
configs.zk = {
default_config = {
cmd = {'zk', 'lsp'};
filetypes = {'markdown'};
root_dir = lspconfig.util.root_pattern('.zk');
settings = {};
};
}
configs.zk.index = function()
vim.lsp.buf.execute_command({
command = "zk.index",
arguments = {vim.api.nvim_buf_get_name(0)},
})
end
configs.zk.new = function(...)
vim.lsp.buf_request(0, 'workspace/executeCommand',
{
command = "zk.new",
arguments = {
vim.api.nvim_buf_get_name(0),
...
},
},
function(_, _, result)
if not (result and result.path) then return end
vim.cmd("edit " .. result.path)
end
)
end
lspconfig.zk.setup({
on_attach = function(client, bufnr)
-- Key mappings
local function buf_set_keymap(...) vim.api.nvim_buf_set_keymap(bufnr, ...) end
local opts = { noremap=true, silent=true }
buf_set_keymap("n", "<CR>", "<cmd>lua vim.lsp.buf.definition()<CR>", opts)
buf_set_keymap("n", "K", "<cmd>lua vim.lsp.buf.hover()<CR>", opts)
buf_set_keymap("n", "<leader>zi", ":ZkIndex<CR>", opts)
buf_set_keymap("v", "<leader>zn", ":'<,'>lua vim.lsp.buf.range_code_action()<CR>", opts)
buf_set_keymap("n", "<leader>zn", ":ZkNew {title = vim.fn.input('Title: ')}<CR>", opts)
buf_set_keymap("n", "<leader>zl", ":ZkNew {dir = 'log'}<CR>", opts)
end
})
EOF |
The wiki-link titles are particularly useful with Neovim's 0.5 built-in LSP client, as they are displayed as virtual text. However I disabled this diagnostic by default as it's not so useful for other editors. You need to enable it in your [lsp.diagnostics]
# Report titles of wiki-links as hints.
wiki-title = "hint" Here's a screenshot after customizing the colors: ~/.config/nvim/init.vimhighlight LspDiagnosticsDefaultError ctermfg=red guifg=red
highlight LspDiagnosticsUnderlineError ctermfg=red guifg=red
highlight LspDiagnosticsDefaultHint ctermfg=yellow guifg=yellow
highlight LspDiagnosticsUnderlineHint cterm=none gui=none |
Considering that there are often issues with the Let me know if it works for you @stefanvanburen. Footnotes
|
As regards pandoc integration, I don't know if this solves the same problem that @ZachariasLenz was having, but my markdown files were already subsumed into a
And now the LSP works perfectly with my pandoc files. |
This comment was marked as duplicate.
This comment was marked as duplicate.
From now on let's open a dedicated GitHub issue for LSP bug reports or LSP feature requests. This issue will be used to follow the evolution of the LSP implementation. |
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
This comment was marked as off-topic.
Anyone managed to make the LSP work with Kakoune (kak-lsp)? |
Wow, this project is awesome, nice work! |
Yes, I managed to get it working with kak-lsp. Try adding this config to your [language.markdown]
filetypes = ["markdown"]
roots = [".zk"]
command = "zk"
args = ["lsp"] Note that it's very important to call the config entry as |
The title issue mentions that |
It was a mistake, but I implemented it quickly in #261. However, this uses LSP Personally with NeoVim I've been using |
Ah, I had |
I seem to be experiencing the issue mentioned above where goto definition doesn't work outside of the root directory. I also notice that when running |
@zalegrala I think that "Running in single file mode" is expected, I have the same thing. I can't reproduce the issue though, opening a note from a sub directory or a directory outside the notebook. I have this in my export ZK_NOTEBOOK_DIR=~/Notes |
just wanna stop by and say thanks for the continual work! im a big fan and with the current feature set, i'm able to clean all my markdown notes from 7+ years ago (written in markdown, hoping for zk to come around). very much appreciated, and hoping to contribute soon as i learn more Go |
@mickael-menu Yep, thanks for the note. I've got |
@zalegrala Ha yes, I'm not sure If you use The one you want is: -- Open the link under the caret.
map("n", "<CR>", "<Cmd>lua vim.lsp.buf.definition()<CR>", opts) |
Ah yes,
|
Any thoughts on adding TODO support for autocomplete and code actions for switching TODO to DONE? I'd be happy to put up a pr giving it a shot if you'd be interested! |
@WhiskeyJack96 IMO this is out of scope for This discussion could be relevant: zk-org/zk-nvim#88 |
@mickael-menu yeah I can see that, is there any plan for or existing/method to extend zk? my workflow currently revolves around using logseq for and then editting my journal notes with Helix in the terminal during work (but helix doesnt currently support plugins or multiple lsps per filetype). |
@WhiskeyJack96 I don't think However, if you're willing to put in the work, you could just fork |
Any plans to support |
I'm getting
I installed via EDIT: I think this was due to me using the I'm using |
Neovim has client support for this and it would be pretty useful. |
zk
can provide a basic integration with any LSP-compatible text editor by shipping a Language Server.PR #21 implements a proof of concept server showing promising results, but there's more to come:
Links
[[
[custom title]((
textDocument/documentLink
)window.showDocument
)DocumentLink
for unlinked mentions, usingaliases
metadataTags
#
and:
trigger charactersNotes
refactor.extract
?)zk
templatesExpose
zk
commands as LSP commands, for easy client-side consumptionzk.init
to create a new notebookzk.index
to index a notebook manuallyzk.new
to create a new notezk.list
to search for notes (returning a JSON)zk.tag.list
to return the list of tagszk.info
to provide detailed JSON metadata about a notebook (list of groups, templates, dirs, etc.)Other
Feel free to share more ideas!
The text was updated successfully, but these errors were encountered: