Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Initial bits for integrating the LSP API. #609

Draft
wants to merge 9 commits into
base: master
Choose a base branch
from
12 changes: 7 additions & 5 deletions wrapper.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ function setupMethods (soljson) {
};
}

const wrappedLspStart = soljson.cwrap('solidity_lsp_start', 'number', []);
const wrappedLspStart = soljson.cwrap('solidity_lsp_start', 'number', ['number']);

return function (callbacks: Callbacks) {
const readCallback = callbacks.import;
Expand All @@ -79,6 +79,8 @@ function setupMethods (soljson) {
const copyFromCString = soljson.UTF8ToString || soljson.Pointer_stringify;

const wrappedReadCallback = function (path: string, contents: string, error: string) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

just run npm run lint:fix or the related package.json command to resolve these before committing.

console.log("wrappedReadCallback: \"" + path + "\"");

// Calls the user-supplied file read callback and passes the return values
// accordingly to either @p contents or into @p error on failure.
const result = readCallback(copyFromCString(path));
Expand All @@ -94,15 +96,15 @@ function setupMethods (soljson) {

const addFunction = soljson.addFunction || soljson.Runtime.addFunction;
const removeFunction = soljson.removeFunction || soljson.Runtime.removeFunction;
const wrappedFunctionId = addFunction(wrappedReadCallback, 'ii');
const wrappedReadCallbackId = addFunction(wrappedReadCallback, 'ii');

try {
// call solidity_lsp_start(callbacks)
const output = wrappedLspStart(wrappedFunctionId);
removeFunction(wrappedFunctionId);
const output = wrappedLspStart(wrappedReadCallbackId);
removeFunction(wrappedReadCallbackId);
return output;
} catch (e) {
removeFunction(wrappedFunctionId);
removeFunction(wrappedReadCallbackId);
throw e;
}

Expand Down