trypurescript
trypurescript copied to clipboard
Autocomplete
Ace probably provides an API for this, we just need to expose it on the server.
Ace does provide support for autocompletion via the ace/ext/language_tools package. There's a wiki page with some admittedly sparse details:
https://github.com/ajaxorg/ace/wiki/How-to-enable-Autocomplete-in-the-Ace-editor
The wiki includes a link to a demo, however, which is useful for seeing how to implement your own autocompletion. We'd presumably want to do something similar, calling back to some PureScript code to provide the completions: https://plnkr.co/edit/6MVntVmXYUbjR0DI82Cr?p=preview&preview
There is existing PureScript code written around autocompletions in this context, namely in the purescript-language-server package. From a glance through that package, this looks relevant (but I'd like to hear if @nwolverson has any suggestions for doing this in an Ace context):
https://github.com/nwolverson/purescript-language-server/blob/78086f60f2741d5fe52bbad8572c107863091eb8/src/IdePurescript/Completion.purs#L73-L84
Of course, then there's the second concern: once we have the autocomplete suggestion and the user selects it, then we have to actually update the imports properly in the editor; I'm not exactly sure where this is done in the language server.
I know nothing about ace, but if (server side) you want to do completion, the language server is all driven by purs ide server (via purescript-psc-ide), including imports (see https://github.com/nwolverson/purescript-language-server/blob/78086f60f2741d5fe52bbad8572c107863091eb8/src/LanguageServer/IdePurescript/Completion.purs#L119 eventually ending at https://github.com/nwolverson/purescript-language-server/blob/78086f60f2741d5fe52bbad8572c107863091eb8/src/IdePurescript/Modules.purs#L191 ).
For reference look at the psc-ide protocol https://github.com/purescript/purescript/blob/master/psc-ide/PROTOCOL.md - complete and import sections.
I started looking into this here but backend stuff isn't really my strong suit, and I have no idea if I'm going down the right path. Right now I'm starting up purs ide server along with server, and then running purs ide client on every request to a /complete endpoint. Does that sound about like the right approach as far as the backend implementation?
@ptrfrncsmrph it's a little round-about, ultimately you might want to just make the socket connection directly, but it should do to get started. You might want to look at the purescript client bindings https://github.com/kritzcreek/purescript-psc-ide