Skip to content

Commit d4868bd

Browse files
wrapper.ts: simplify code a bit.
1 parent 0411cb6 commit d4868bd

File tree

1 file changed

+6
-13
lines changed

1 file changed

+6
-13
lines changed

wrapper.ts

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@ function setupMethods (soljson) {
6363
};
6464

6565
const createWrappedLspSend = function() {
66+
if (!('_solidity_lsp_send' in soljson))
67+
return null;
6668
const wrappedLspSend = soljson.cwrap('solidity_lsp_send', 'number', ['string']);
6769
return function (input: String) {
6870
const args = [];
@@ -73,6 +75,8 @@ function setupMethods (soljson) {
7375

7476
// Creates a wrapper around `int solidity_lsp_start(callbacks: Callbacks)`.
7577
const createWrappedLspStart = function() {
78+
if (!('_solidity_lsp_start' in soljson))
79+
return null;
7680
const wrappedLspStart = soljson.cwrap('solidity_lsp_start', 'number', []);
7781
return function (callbacks: Callbacks) {
7882
let readCallback = callbacks.import;
@@ -146,17 +150,6 @@ function setupMethods (soljson) {
146150
};
147151
};
148152

149-
// solc.lspStart(myCallbackHere);
150-
let lspStart = null;
151-
if ('_solidity_lsp_start' in soljson) {
152-
lspStart = createWrappedLspStart();
153-
}
154-
155-
let lspSendReceive = null;
156-
if ('_solidity_lsp_send_receive' in soljson) {
157-
lspSendReceive = createWrappedLspSend();
158-
}
159-
160153
// This calls compile() with args || cb
161154
const runWithCallbacks = function (callbacks, compile, args) {
162155
if (callbacks) {
@@ -390,8 +383,8 @@ function setupMethods (soljson) {
390383
nativeStandardJSON: compileStandard !== null
391384
},
392385
lsp: {
393-
start: lspStart,
394-
sendReceive: lspSendReceive
386+
start: createWrappedLspStart(),
387+
sendReceive: createWrappedLspSend()
395388
},
396389
compile: compileStandardWrapper,
397390
// Loads the compiler of the given version from the github repository

0 commit comments

Comments
 (0)