Skip to content

Commit 646b4dd

Browse files
wrapper.ts: adds sendReceive() plus some function order changes.
1 parent d4868bd commit 646b4dd

File tree

1 file changed

+32
-12
lines changed

1 file changed

+32
-12
lines changed

wrapper.ts

Lines changed: 32 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,17 +62,6 @@ function setupMethods (soljson) {
6262
soljson.setValue(ptr, buffer, '*');
6363
};
6464

65-
const createWrappedLspSend = function() {
66-
if (!('_solidity_lsp_send' in soljson))
67-
return null;
68-
const wrappedLspSend = soljson.cwrap('solidity_lsp_send', 'number', ['string']);
69-
return function (input: String) {
70-
const args = [];
71-
args.push(JSON.stringify(input));
72-
return wrappedLspSend.apply(undefined, args);
73-
};
74-
};
75-
7665
// Creates a wrapper around `int solidity_lsp_start(callbacks: Callbacks)`.
7766
const createWrappedLspStart = function() {
7867
if (!('_solidity_lsp_start' in soljson))
@@ -118,6 +107,36 @@ function setupMethods (soljson) {
118107
};
119108
};
120109

110+
// C signature : int solidity_lsp_send(char const* jsonRpcInputObject);
111+
// TS signature : int send(object jsonRpcInputObject);
112+
const createWrappedLspSend = function() {
113+
if (!('_solidity_lsp_send' in soljson))
114+
return null;
115+
const wrappedLspSend = soljson.cwrap('solidity_lsp_send', 'number', ['string']);
116+
return function (input: String) {
117+
const args = [];
118+
args.push(JSON.stringify(input));
119+
return wrappedLspSend.apply(undefined, args);
120+
};
121+
};
122+
123+
// C signature : char* solidity_lsp_send_receive(char const* jsonRpcInputObject);
124+
// TS signature : object sendReceive(object jsonRpcInputObject);
125+
//
126+
// sendReceive send one message to the LSP server (notification or method call).
127+
// The method call may reply with zero or one message that is going to be returned.
128+
const createWrappedLspSendReceive = function() {
129+
if (!('_solidity_lsp_send_receive' in soljson))
130+
return null;
131+
const wrappedLspSendReceive = soljson.cwrap('solidity_lsp_send_receive', 'string', ['string']);
132+
return function (input: String) {
133+
const args = [];
134+
args.push(JSON.stringify(input));
135+
const reply = wrappedLspSendReceive.apply(undefined, args);
136+
return JSON.parse(reply);
137+
};
138+
};
139+
121140
// This is to support multiple versions of Emscripten.
122141
// Take a single `ptr` and returns a `str`.
123142
const copyFromCString = soljson.UTF8ToString || soljson.Pointer_stringify;
@@ -384,7 +403,8 @@ function setupMethods (soljson) {
384403
},
385404
lsp: {
386405
start: createWrappedLspStart(),
387-
sendReceive: createWrappedLspSend()
406+
send: createWrappedLspSend(),
407+
sendReceive: createWrappedLspSendReceive()
388408
},
389409
compile: compileStandardWrapper,
390410
// Loads the compiler of the given version from the github repository

0 commit comments

Comments
 (0)