neo4j / cypher-language-support

Neo4j's Cypher Language support
https://neo4j.github.io/cypher-language-support/
Apache License 2.0
31 stars 5 forks source link

Prototyping a runtime strategy to allow different runtime behaviours in the language server #247

Open daveajrussell opened 1 month ago

daveajrussell commented 1 month ago

Currently with our vscode extension, we have 2 instances on the schema poller.. 1 in the vscode extension, that is used for connecting to and listing databases and their properties. The other is in the language server itself, and is used by the language server for database aware features.

The vscode extension brokers messages via the language client for language server to update its own schema poller instance when the connection in the extension is modified.

There are a few problems with this approach;

In this prototype I am;

Creating the concept of a 'Runtime' in the language server This does make the language server somewhat less client agnostic, as this approach makes it aware of the client that is consuming it.

However it does allow us to configure the language server to manage its own instance of the schema poller, or allow schema updates to be deferred to the consumer.

In the standalone runtime, we construct a schema poller instance and establish a persistent connection to it.

In the extension runtime, we establish a single listener to a schemaFetched message, that updates an internal dbSchema instance which the database aware features will use. This message will be dispatched from the vscode extension when it receives an event from its schema poller instance.

schema poller:emit('schemaFetched') -> vscode extension:languageServer.sendNotification('schemaFetched', {}) -> language server:onNotification('schemaFetched', (dbSchema) => {})

It would be nice to share the actual schema poller instance that the vscode extension creates between the vscode extension and the language server to avoid the need for having to rebroadcast a message from the extension, but this does not seem possible.. parameters may be passed via the initializationOptions, however these are serialized and deserialized, and the event emitter doesn't pick up messages inside of the language server.

changeset-bot[bot] commented 1 month ago

⚠️ No Changeset found

Latest commit: a5795daf7edd1676ffcef48aa1e8b9c0fd720c5d

Merging this PR will not cause a version bump for any packages. If these changes should not result in a new version, you're good to go. If these changes should result in a version bump, you need to add a changeset.

This PR includes no changesets When changesets are added to this PR, you'll see the packages that this PR includes changesets for and the associated semver types

Click here to learn what changesets are, and how to add one.

Click here if you're a maintainer who wants to add a changeset to this PR

OskarDamkjaer commented 1 month ago

I like this approach/solution to the problem, I feel it makes it simpler to understand how the connection to neo4j works :+1: