nvim-neorg / neorg

Modernity meets insane extensibility. The future of organizing your life in Neovim.
GNU General Public License v3.0
6.51k stars 214 forks source link

LSP-like features for `.norg` file editing #513

Open vhyrro opened 2 years ago

vhyrro commented 2 years ago

Discussed in https://github.com/nvim-neorg/neorg/discussions/512

Originally posted by **Aceticia** July 11, 2022 I'm writing my personal notes, journal, GTD, and wiki with neorg. With the telescope integration, things are seamless - I can search for content very effectively and link files. However, there are still some functionalities that are somewhat missing in maintaining a large scale wiki. Functions such as dead link detection, completion-based linking, previewing, links and backlinks, and renaming provided by markdown language servers such as [marksman](https://github.com/artempyanykh/marksman) would be a great compliment to the current, growing functionalities of neorg, for the people who take and maintain a lot of notes.

This issue is mostly a reference point for future me on what to implement should I attempt the task of making a Neorg LSP. By all means if there's someone out there with more experience and they want to help out go ahead!

Aceticia commented 2 years ago

A more formal list of LSP features I can think of (feel free to point out what's missing/unfeasible):

Diagnostics:

Completion:

Hover:

Format:

Code actions:

Others:

danymat commented 2 years ago

GTD:

vhyrro commented 2 years ago

Another interesting idea (proposed on the discord):

Anrock commented 2 years ago

I always wanted something like a potential link detection or proactive link completion. Not sure how to call it, so I'll try to give an example.

Imagine you have a file where you described what Foo is, like

* Foo
  Foo is blah blah
** Foo use cases
   You will use Foo when you want to blah

And then you're brainstorming ideas for something else:

* Bar
  Possibly can be achieved with
  - Something something
  - Maybe can use Foo with blah blah

It will be very nice if Foo on the last line produced a completion/code action/code lense/whatever to turn Foo in the text into a link to that Foo header where you previously described what Foo is.

Could be very useful for wiki, knowledge base and zettelkasten workflows.

vhyrro commented 2 years ago

Ooh a code action along the lines of "xyz can be converted into a link" sonuds like a really cool idea!

Aceticia commented 2 years ago

I'm actually thinking about how to make something like this. I know obsidian.md uses exact word match to suggest links, but I wanted to do some more fuzzy matching either based on word/sentence embeddings or n-gram models.

That said, these are all quite high capacity computation, so likely not fast enough to run with LSP on each text insert. Running a command that detects potential links is a bit more feasible, in my opinion...but I might be wrong. I usually work with python NLP packages, and this is usually the speed I expect. Someone please correct me if you can run this with rust crates at text insert speed, that would be really cool.

vhyrro commented 2 years ago

Something more fuzzy would probably have to be configurable, as it may trigger false positives and users might not like that :sweat_smile:. Neorg already does fuzzy matching for links (using the "fix link" functionality) - that uses the damerau-levenshtein algorithm to determine how similar two strings are. It's very simple but also very effective if you want to do some basic fuzzing. If you wanna go all out with NLP then yeah you might end up getting performance hits unless you run it off-thread with some throttling or something.

Aceticia commented 2 years ago

True. Now that I think about it these might serve two slightly different purposes. The more accurate and faster algorithm for suggesting exact links, while the more fuzzy one is probably more appropriately used as a note exploration tool, like noduslab?

aareman commented 2 years ago

Providing an adapter to null-ls might be the easiest way to leverage existing neorg code and provide LSP/linting/formatting in an async way. (Just throwing this out there, I'm no expert at null-ls)

Thanks @vhyro and crew for this really cool plugin!


From: Xujin Chris Liu @.> Sent: Wednesday, July 20, 2022 10:17:29 AM To: nvim-neorg/neorg @.> Cc: Subscribed @.***> Subject: Re: [nvim-neorg/neorg] LSP-like features for .norg file editing (Issue #513)

True. Now that I think about it these might serve two slightly different purposes. The more accurate and faster algorithm for suggesting exact links, while the more fuzzy one is probably more appropriately used as a note exploration tool, like noduslabhttps://linkprotect.cudasvc.com/url?a=https%3a%2f%2fnoduslabs.com&c=E,1,weZ-HGa88yysjGc-SiQOQMlr_Ntrj4ChE9kzRSEWpFNqFPunjEiQ3HoyMycBSyj6TORTFwm1WzjK7PFTXtcbzo2269HyITihSj96fKrI&typo=1?

— Reply to this email directly, view it on GitHubhttps://github.com/nvim-neorg/neorg/issues/513#issuecomment-1190345452, or unsubscribehttps://github.com/notifications/unsubscribe-auth/ACQDVVYA2U33LYTJP2D3A5TVVAC7TANCNFSM53LU3LJQ. You are receiving this because you are subscribed to this thread.Message ID: @.***>

vhyrro commented 2 years ago

@aareman i don't think using null-ls would be a good idea. Making a generic LSP would nicely help with Neorg adoption outside of Neovim, which is what we want, right? :)

vhyrro commented 2 years ago

Speaking of which, I've started work on an official LSP implementation here: https://github.com/nvim-neorg/neorg-lsp!

I've only been working on it for a day, so don't expect it to do anything useful :p, but I'm letting y'all know about its existence so people can contribute and so that you're aware that work is being done on it :)

AlphabetsAlphabets commented 1 year ago

I know I'm late to the party but something I'd like is to be able to update links when a file changes. In Obsidian, when you make a link to a file and change the file's name. All links get updated to match the file getting renamed. In Neorg that doesn't happen and when stuff breaks, I have to change a lot of things manually.

Having that would be very nice. The issue can be mitigated by just using anchors all over the place, so you can just change the path in one spot in a single file. But, it still has the issue of if the anchors are defined in different files.