Feel-ix-343 / markdown-oxide

Editor Agnostic PKM: you bring the text editor and we bring the PKM - inspired by and compatible with Obsidian
GNU General Public License v3.0
684 stars 10 forks source link

Coq_nvim as the autocompletion tool #75

Closed SpyrosMourelatos closed 1 month ago

SpyrosMourelatos commented 2 months ago

TY for the amazing job I would like to ask if it is possible to use the auto completion features without hrsh7th/nvim-cmp and with ms-jpq/coq_nvim. I have done everything except adding the source

{
name = 'nvim_lsp',
  option = {
    markdown_oxide = {
      keyword_pattern = [[\(\k\| \|\/\|#\)\+]]
    }
  }
},
Screenshot 2024-04-29 at 11 13 21

In my configs as I don't use nvim-cmp and I am pretty close to a fully working functionality( see the screenshot) So I was wondering if we can communicate to ms-joq and add markdown-oxide as a third party source.

In the next days I will try to manually add it and provide some configs. The next best thing other than supporting it out of the box is to document the required work to support it.

Feel-ix-343 commented 2 months ago

Hey thank you so much!!

I'd love to work with you on this. I have certainly heard of coq but never tried it.

Let me know how you are developing and I will work on this at some point.

You can check what is being worked on in the linked github project

SpyrosMourelatos commented 2 months ago

I looked around the code a bit and I still have some missing parts, but I think I am close to understanding. I will write down my thoughts, though they are still inaccurate. So most IDEs normally trigger completion request automatically whenever an identifier is pressed(see https://hexdocs.pm/gen_lsp/GenLSP.Structures.CompletionRegistrationOptions.html) Your lsp has some extra options to get invoked with this trigger characters:

trigger_characters: Some(vec![
   "[".into(),
    " ".into(),
    "(".into(),
    "#".into(),
    ">".into(),
]),

But we have to notify the LSP client somehow to also trigger when these characters are pressed. Nvm-cmp does it with the keyword_pattern = [[\(\k\| \|\/\|#\)\+]] but coq_nvim doesnt seem to have an option like that. I tried to further investigate coq_nvim and indeed I see that from the three context that can be provided from the client coq is using only the Invoked https://github.com/neovim/neovim/blob/b7e5769132e865122fe4bf8588be9ca1820db802/runtime/lua/vim/lsp/protocol.lua#L90 Note that maybe I am completely wrong, as I am not that familiar with lsp's but maybe this project is my chance to get deeper.

Feel-ix-343 commented 2 months ago

If coq_nvim doesn't stop giving completions when you press space (or another weird character), keyword_pattern should not be necessary.

In my opinion, the concept of keyword_pattern in nvim-cmp is slightly odd. It specifies the pattern that an ongoing completion search text must match - otherwise completions are dropped. This is fine for most LSs because they do not give completion with spaces (which is not in the keyword_pattern by default), but many do. VSCode has nothing like this; there was almost no configuration necessary to get moxide working on it. Keyword pattern is a little odd.

And you are right about the trigger characters.

Feel-ix-343 commented 2 months ago

NOTE that keyword_pattern is nvim-cmp specific and is not tied into the language server protocol

SpyrosMourelatos commented 1 month ago

Let's close the issue, I think I had something misconfigured on my enormous configs. Today I cleaned up my configs and coq_nvim also works. Furthermore, I tested a bit working with vim.bo.omnifunc = "v:lua.vim.lsp.omnifunc" and omnifunc works as well! Here is a screenshot after all :

Screenshot 2024-04-30 at 19 49 59
Feel-ix-343 commented 1 month ago

Awesome!

Feel free to open an issue any time!