diff options
Diffstat (limited to 'graphics/asymptote/main.cc')
-rw-r--r-- | graphics/asymptote/main.cc | 47 |
1 files changed, 38 insertions, 9 deletions
diff --git a/graphics/asymptote/main.cc b/graphics/asymptote/main.cc index e4eb1dc590..4359111829 100644 --- a/graphics/asymptote/main.cc +++ b/graphics/asymptote/main.cc @@ -44,6 +44,10 @@ #include "interact.h" #include "fileio.h" +#ifdef HAVE_LSP +#include "lspserv.h" +#endif + #include "stack.h" using namespace settings; @@ -87,7 +91,7 @@ int sigsegv_handler (void *, int emergency) } #endif -void setsignal(RETSIGTYPE (*handler)(int)) +void setsignal(void (*handler)(int)) { #ifdef HAVE_LIBSIGSEGV char mystack[16384]; @@ -126,6 +130,11 @@ struct Args Args(int argc, char **argv) : argc(argc), argv(argv) {} }; +int returnCode() +{ + return em.processStatus() || interact::interactive ? 0 : 1; +} + void *asymain(void *A) { setsignal(signalHandler); @@ -134,11 +143,32 @@ void *asymain(void *A) if(interactive) { Signal(SIGINT,interruptHandler); - processPrompt(); +#ifdef HAVE_LSP + if (getSetting<bool>("lsp")) { + AsymptoteLsp::LspLog log; + auto jsonHandler=std::make_shared<lsp::ProtocolJsonHandler>(); + auto endpoint=std::make_shared<GenericEndpoint>(log); + + unique_ptr<AsymptoteLsp::AsymptoteLspServer> asylsp; + + if(getSetting<string>("lspport") != "") { + asylsp=make_unique<AsymptoteLsp::TCPAsymptoteLSPServer>( + (std::string)getSetting<string>("lsphost").c_str(), + (std::string)getSetting<string>("lspport").c_str(), + jsonHandler, endpoint, log); + } else { + asylsp=make_unique<AsymptoteLsp::AsymptoteLspServer>(jsonHandler, + endpoint, + log); + } + asylsp->start(); + } else +#endif + processPrompt(); } else if (getSetting<bool>("listvariables") && numArgs()==0) { try { doUnrestrictedList(); - } catch(handled_error) { + } catch(handled_error const&) { em.statusError(); } } else { @@ -155,7 +185,7 @@ void *asymain(void *A) processFile("-",true); try { setOptions(args->argc,args->argv); - } catch(handled_error) { + } catch(handled_error const&) { em.statusError(); } if(inpipe < 0) break; @@ -166,7 +196,7 @@ void *asymain(void *A) try { if(ind < n-1) setOptions(args->argc,args->argv); - } catch(handled_error) { + } catch(handled_error const&) { em.statusError(); } } @@ -193,12 +223,12 @@ void *asymain(void *A) } #endif #endif - exit(em.processStatus() || interact::interactive ? 0 : 1); + exit(returnCode()); } void exitHandler(int) { - exit(0); + exit(returnCode()); } int main(int argc, char *argv[]) @@ -211,7 +241,7 @@ int main(int argc, char *argv[]) try { setOptions(argc,argv); - } catch(handled_error) { + } catch(handled_error const&) { em.statusError(); } @@ -256,4 +286,3 @@ GC_API void GC_CALL GC_throw_bad_alloc() { std::bad_alloc(); } #endif - |