libsolc: guard LSP initialization in try/catch block.

This commit is contained in:
Christian Parpart 2022-03-14 16:18:57 +01:00
parent e1947faa1a
commit ec6f1758c1
2 changed files with 15 additions and 6 deletions

View File

@ -137,13 +137,22 @@ extern char* solidity_compile(char const* _input, CStyleReadFileCallback _readCa
return solidityAllocations.emplace_back(compile(_input, _readCallback, _readContext)).data();
}
extern int solidity_lsp_start(CStyleReadFileCallback /*TODO(pr) _readCallback*/, void* /*_readContext*/) noexcept
extern int solidity_lsp_start(CStyleReadFileCallback _readCallback) noexcept
{
if (languageServer || languageServerTransport)
return -1;
languageServerTransport = make_unique<lsp::MockTransport>();
languageServer = make_unique<lsp::LanguageServer>(*languageServerTransport);
try
{
languageServerTransport = make_unique<lsp::MockTransport>();
languageServer = make_unique<lsp::LanguageServer>(*languageServerTransport);
(void) _readCallback; // TODO(pr) pass to LanguageServer()
}
catch (...)
{
return -2;
}
return 0;
}

View File

@ -98,7 +98,7 @@ char* solidity_compile(char const* _input, CStyleReadFileCallback _readCallback,
///
/// @returns 0 on success and -1 on failure. A failure can only happen due to mis-use of the API,
/// such as, the LSP mode has been already initiated.
int solidity_lsp_start(CStyleReadFileCallback _readCallback, void* _readContext) SOLC_NOEXCEPT;
int solidity_lsp_start(CStyleReadFileCallback _readCallback) SOLC_NOEXCEPT;
/// Sends a single JSON-RPC message to the LSP server.
/// This message must not include any HTTP headers but only hold the payload.
@ -120,8 +120,8 @@ char const* solidity_try_receive() SOLC_NOEXCEPT;
/// @returns JSON-RPC message (inculding HTTP headers), can be empty (or nullptr).
/// If the result is not null, it has to be freed by the caller using solidity_free.
///
/// This can cause the callback provided in solidity_lsp to be invoked.
/// Should only be called after having called solidity_lsp.
/// This can cause the callback provided in solidity_lsp_start to be invoked.
/// Should only be called after having called solidity_lsp_start.
char const *solidity_lsp_send_receive(char const* _input) SOLC_NOEXCEPT;
/// Frees up any allocated memory.