Closed jamesnvc closed 3 years ago
completion would not be that hard with https://www.swi-prolog.org/pldoc/doc/_SWI_/library/console_input.pl
Oh nice, thank you! I will have a look at that.
On Oct 4, 2019, at 08:02, rrooij notifications@github.com wrote:
completion would not be that hard with https://www.swi-prolog.org/pldoc/doc/_SWI_/library/console_input.pl
— You are receiving this because you authored the thread. Reply to this email directly, view it on GitHub, or mute the thread.
Hm, it looks like that might not work directly in this case...I can probably use the $atom_completions
thing that it uses internally, but the issue is that the completion systems there rely on dynamically loading the program to figure out what the available atoms are.
I may eventually change this LSP server to also actually load the code its introspecting, but for now I want to keep it using the xref
family of predicates to just do static analysis.
Agree. But maybe just completing the internal library would be a good start already.
Indeed. I started trying to implement completion based on a combination of the above library & xref_defined
, but ran into another issue that will require some thinking about:
An LSP completion request just gives the server the name of the file and the position in the file. This means then that if the file is unsaved (as it would presumably be if you're in the process of typing), the server can't actually tell what you've just typed & want completed. This seems like kind of a wild deficiency in the API, so maybe there's a way around this. As of now, the only way I can see is to implement the didUpdate
notification and maintain in the server that the current state of the file is, independent of what's actually saved, just for this purpose. That would in turn complicate xref stuff though, so I'm going to just ponder this for a little bit.
Yes, I tried it as well and encountered the same issue. I do think that we need to implement didUpdate
since we need to keep track of the modified unsaved buffer for other LSP-implementations as well.
Maintaining the current state of the file is the best way, I think.
Just pushed out version 1.4.0 that tries implementing simple completion, using xref
to get the loaded predicates in the current file. As discussed here, it uses the didUpdate
notification to keep track of what the current text is, independent of being saved.
Thanks for helping with this; please let me know if it works for you!
Thanks a lot, will definitely look at it!
Works pretty well.
Some built-in predicates are not completed by the way. For instance, memberchk/2
findall(X, current_predicate(X), BuiltInPredicates).
Could be used to list all available default predicates.
Using current_predicate/1
unfortunately doesn't work in this case, because the LSP doesn't actually load the file you're editing -- the completions are from xref_defined/3
. That's probably also why some of the built-in predicates don't show up; I think that xref doesn't know about ones that are autoloaded.
Oh never mind, I see what you're saying about the default predicates! I will give that a try, thanks!
To work with https://github.com/ncm2/ncm2.
Carrying on from #2