need advice for a long blocking task #378
Replies: 3 comments 2 replies
-
In the scenario that you describe, when the events queue up and the error highlighting lags, if you enable logging in your server code, do you also observe this log ? Line 303 in de7a33e We discussed a bit in the past ( #240 (comment) ) and we said that it might be a possible missing feature (or bug maybe) of pygls that it does not process the cancel notifications. |
Beta Was this translation helpful? Give feedback.
-
I also tried to do something with multiprocessing, but there is some state that I need to maintain and I got really weird behaviour. I assume the thread you start are all done via multiprocessing, so any state that needs maintaining needs to also be done with multiprocessing shared memory? Or are the threads you launch for that Is there a non-trivial example somewhere that makes use of the pygls thread() decorator? |
Beta Was this translation helpful? Give feedback.
-
I'm not sure if this is exactly what you want, but here is a pattern that I've been experimenting with recently class SphinxManager(LanguageFeature):
"""Responsible for managing Sphinx application instances."""
def __init__(self, client_factory: SphinxClientFactory, *args, **kwargs):
self._pending_builds: Dict[str, asyncio.Task] = {}
"""Holds tasks that will trigger a build after a given delay if not cancelled."""
async def document_change(self, params: lsp.DidChangeTextDocumentParams):
# Cancel any existing pending builds
if (task := self._pending_builds.pop(client.id, None)) is not None:
task.cancel()
self._pending_builds[client.id] = asyncio.create_task(
self.trigger_build_after(uri, client.id, delay=2)
)
async def trigger_build_after(self, uri: Uri, app_id: str, delay: float):
"""Trigger a build for the given uri after the given delay."""
await asyncio.sleep(delay)
self._pending_builds.pop(app_id)
await self.trigger_build(uri) I've omitted a lot from the code above to try and focus on the main idea, the full code can be found here if you are interested.
It seems to work well for my use case, where a user can make modifications to a document with the server only refreshing after a short pause in activity. |
Beta Was this translation helpful? Give feedback.
-
Hi,
We're implementing a new vscode extension for a DSL. In some cases the parsing and checking can take quite a while.
Right now we're doing a parse on each TEXT_DOCUMENT_DID_CHANGE, but if the parse and validation take ~10 seconds then events queue up and the error highlighting lags.
How should we deal with this? Is there any way to inspect the queue? I'd like to look at the queue and simply skip all events except the last one (so that we always eventually get a correctly highlighted source).
Beta Was this translation helpful? Give feedback.
All reactions