Giter VIP home page Giter VIP logo

Comments (3)

dbaeumer avatar dbaeumer commented on June 21, 2024

I tested this in the testbed and requests send from the server to the client are properly resolved. The code is in the dbaeumer/underground-vole-plum branch in case you want to have a look.

Can you try to test this from the TS server part directly to the client. If that works for you as well (as it does for me) it is more likely with the bridge code.

from vscode-languageserver-node.

0xMemoryGrinder avatar 0xMemoryGrinder commented on June 21, 2024

Hello,

I tested to perform the sendRequest inside an handler defined in typescript. Its works correctly.
The problem however is that my bridge code seems to work too.

The rust part of my codebase calls the typescript callback to send a request. I get the first log but never the resolve of catch.
Here is the callback from the code above :

const sendRequest = async (method: string, params: any) => {
	connection.console.log(`sendRequeest: ${method} ${JSON.stringify(params)}`); // is logged
	try {
		let res = await connection.sendRequest(method, params); // my handler is executed during this call
		connection.console.log(`sendRequest: ${method} ${JSON.stringify(params)} => ${JSON.stringify(res)}`); // never logged
		return res;
	} catch (error) {
		connection.console.error('Error with sendRequest:', error); // never log too
	}	
	
};

I also tried with a "promise" version to see if the async was the problem but I get the same behavior :

const sendRequest = (method: string, params: any): Promise<any> {
	return new Promise((resolve, reject) => {
		connection.console.log(`sendRequeest: ${method} ${JSON.stringify(params)}`); // is logged
		connection.sendRequest(method, params) // my handler is executed during this call
		.then((res: any) => {
			connection.console.log(`sendRequest: ${method} ${JSON.stringify(params)} => ${JSON.stringify(res)}`); // never logged
			resolve(res)
		})
		.catch((err) => {
			connection.console.error('Error with sendRequest:', err); // never logged
			reject(err);
		});
	});
};

Is there any context specific behavior with the Connection class ?

from vscode-languageserver-node.

dbaeumer avatar dbaeumer commented on June 21, 2024

I assume that you compile your Rust code to WASM. If this is the case WASM is fully sync and as soon as you execute WASM code the corresponding worker never falls back to the NodeJS event loop until the WASM code is finished (even not if you call code in the JS host). Hence the promise can never be fullfilled.

To get something like this working you either need to asyncify the WASM code, wait for async support in WASM or use another worker and SharedArrayBuffers with Atomics to do the promise handling in yet another worker. You might want to look at code here to see how this can be done: https://github.com/microsoft/vscode-wasi.git

I will close the issue since there is nothing in the LSP library I can do about this. The above repository contains an example on how to implement a LSP server in Rust, compile it to WASM and then use without any TS clue code. See https://github.com/microsoft/vscode-wasi/blob/dbaeumer/mere-meerkat-green/testbeds/lsp-rust/client/src/extension.ts#L37

from vscode-languageserver-node.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.