-
Notifications
You must be signed in to change notification settings - Fork 197
Use asyncio #2880
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
Open
rwols
wants to merge
148
commits into
main
Choose a base branch
from
feat/asyncio
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Use asyncio #2880
Changes from 15 commits
Commits
Show all changes
148 commits
Select commit
Hold shift + click to select a range
699dad3
Test both TCP modes
rwols 908c849
Use enum for 'Mode' in server.py
rwols b4f0420
Make init_options optional
rwols 76f3c3f
WIP add asyncio to transports
rwols 45d7ea6
Test both TCP modes
rwols e8fae30
Use enum for 'Mode' in server.py
rwols c511cec
Make init_options optional
rwols 7438d4a
Use StrEnum
rwols 6a104b0
Merge branch 'chore/add-tests' into feat/asyncio
rwols d59bb1c
More work on adding asyncio
rwols c0bea09
Merge branch 'main' into feat/asyncio
rwols c1fc59c
More work towards asyncio
rwols e35b611
Remove accidental merge conflict changes
rwols 6cad098
Remove code in server.py, I really screwed up the merge but will reba…
rwols 1597782
refactor Promise.__await__
rwols cc642f4
Add more comments to _SetTimeoutAsyncExecutor
rwols cea0e99
Rename Session._invoke_views -> Session._invoke_views_async
rwols 3d30ad4
More work towards asyncio
rwols 472705b
debugging sublime_aio.ViewEventListener
rwols ea34714
Merge branch 'main' into feat/asyncio
rwols 069ed50
Fix calls
rwols 776749a
More fix calls
rwols 0227877
More work. Some diagnostics show intermittently. Request logic is not…
rwols 2649a6f
Tweaks to pull diagnostics handling
rwols 54af917
Restore method names
rwols 1a4589c
Forgot import
rwols 900f721
Restore more method names
rwols 35621cf
ResponseException is not needed, we already have Error
rwols dbf4d7d
Merge branch 'main' into feat/asyncio
rwols f3b2f84
More rename reverts
rwols a9c1692
Add more tracing for understanding why requests are not resolving
rwols 7004df5
Start fixing up 'goto' functionality
rwols a876949
Fix:
rwols d27aa93
debugging
rwols 341ff99
We have something working
rwols 4ed4e3f
Start fixing diagnostic errors because diagnostics work
rwols 7aba65e
Remove trace() calls
rwols e3ccba2
Remove trace() calls
rwols c2c2a8c
Remove trace() calls
rwols af561a8
Fixups
rwols 7260c90
Remove trace() calls and fixup type hints
rwols a60ddd2
Reintroduce request_code_actions_async for SessionBuffer
rwols 23210e3
Consolidate sublime_aio & asyncio functions/classes in plugin/core/ai…
rwols 73ed644
get_session_buffer_for_uri -> get_session_buffer_for_uri_async
rwols 6d6e772
Session.session_buffers -> Session.session_buffers_async
rwols a84f3dd
_invoke_views_async -> _invoke_views
rwols f7702c2
Fix notifications being logged twice
rwols bb51929
Fix LspCheckApplicableCommand... I think
rwols 7d58862
Fix errors in WindowManager.start, and allow async version of LspPlug…
rwols e2119a1
Print exceptions from coroutines started from `run_coroutine_threadsafe`
rwols ce27231
Ensure plugin_unloaded works as expected
rwols a4aba53
Merge branch 'main' into feat/asyncio
rwols c215234
Fixup incorrect (old) usage of Session.send_request_async
rwols ae081e3
Remove trace() calls from sessions.py
rwols e4d3324
Merge branch 'main' into feat/asyncio
rwols 6e5ca85
Fix type errors in sessions.py
rwols 4866feb
Review all sublime.set_timeout_async call sites
rwols 73a658a
Merge branch 'main' into feat/asyncio
rwols 8a6de63
asyncio.Future, async functions, and Promises are all just Awaitables
rwols fcb8717
Fix process args
rwols 8997d51
Fix most type errors, except for tooling.py
rwols 5943571
Fix: document link was requested before didOpen
rwols 7485b90
Rename Files: open files sequentially, as it as before
rwols edd3ccd
apply_text_edits: wait at least one UI frame
rwols 91af0e0
LspPlugin.prefer_async_on_pre_start -> LspPlugin.use_asyncio
rwols da1fc1d
Invoke LspPlugin.on_initialize after the `initialized` notification
rwols 34697be
Update tooling.py for asyncio
rwols aa37898
Remove unused imports
rwols 9335c7d
Fix 'TCP client' mode
rwols afde9fb
Compatibility with python 3.8
rwols 0795ee4
Fix missing import for type checking
rwols 4659e8d
Add stubs/sublime_aio.pyi
rwols 76aeba1
Fix formatting
rwols 66bd43a
Fix all remaining lint errors
rwols a143bdf
Fix interface method (why isn't this reported as an error by either p…
rwols 69fd44d
Fixup interface method of `Manager` (why isn't this reported by eithe…
rwols c2a9e30
Fixup wm.handle_show_message: it's not async
rwols 8835214
Add @override to all methods in WindowManager that implement an inter…
rwols 668846c
Turn off @deprecation warnings
rwols c6a89b1
Fix lint warnings
rwols 9d8c1b3
The return type of the `Window.handle_show_message` interface method …
rwols d271624
Fix reference to task object
rwols 68b8945
Add function: exceptions_log
rwols a3c88ec
Catch possible exception when draining the stream writer
rwols 3915ca6
Add functions aclosing, gather_and_flatten_exceptions, TaskContainer.…
rwols 82973a5
Fix for python 3.8 runtime regarding opening files lock
rwols 1ae40fe
Fixes for python 3.8 runtime, better CancellableInflightStreamingRequ…
rwols 45bbb05
Fix LSP: Rename
rwols 998ac1c
Comment out the debug print in the tranports.py because I'm feeling c…
rwols 9c761d1
Merge branch 'main' into feat/asyncio
rwols 056359b
LspPlugin.use_asyncio() -> LspPlugin.use_asyncio
rwols aca3b34
Fixup incorrect merge resolution in api.py
rwols 1a6448b
I don't know how this got here.
rwols dd2b791
Odds and ends in sessions.py
rwols ff9cfd7
Odds and ends: make `@requires_session` compatible with coroutine fun…
rwols 5e3af9c
WIP refactor tests
rwols d91eeda
Convert unit/integration tests to asyncio
rwols 8676dc4
Fix bugs revealed by tests
rwols c6efba4
Merge branch 'main' into feat/asyncio
rwols 2c2e7b3
Merge branch 'main' into feat/asyncio
rwols 119fa99
Add runtime check for accidental coroutine continuations
rwols 9e35cc4
In the process of fixing bugs due to tests revealing bugs
rwols 8c83c96
Re-introduce classSetUp and classTearDown
rwols 691d8ea
Fixes for macOS
rwols 0aa553b
Merge branch 'main' into feat/asyncio
rwols e9d65dd
Fixes after merge
rwols a8f6ba1
Merge branch 'main' into feat/asyncio
rwols a5d67f5
Session.open_scratch_buffer always returns a View
rwols 09b3d3d
Fix disabling and then enabling configs
rwols bc70dee
Simplify executors, and encode/decode JSON on the ST async thread
rwols 7005ac0
Maybe fix LSP.tests.test_single_document.SingleDocumentTestCase.test_…
rwols 750b995
Remove debug prints from test code
rwols e3fc6e9
Fix remaining tests... hopefully?
rwols 6817036
Fix lint errors
rwols 3c90ff9
Revert "Maybe fix LSP.tests.test_single_document.SingleDocumentTestCa…
rwols 6e7f252
Fix purge_changes_async in rename.py not being called from the asynci…
rwols a5e3a6d
Rename run_coroutine_threadsafe -> run_coroutine
rwols 135aa60
Fix bug in the rename flow when first making a preview and then click…
rwols 9506bd5
Rename call_soon_threadsafe -> run_in_asyncio_thread
rwols 0e19738
Remove trace() calls from code_actions.py and save_command.py
rwols 45ee4dd
Remove duplicated imports from api.py
rwols ca61cc6
Fix toggling inlay hints
rwols bb41f71
Fix hardcoded value for on-save task timeout
rwols 1529494
Catch the asyncio.CancelledError that's going to be thrown when cance…
rwols 1f14cee
Mark SessionBuffer.request_code_actions_async as deprecated
rwols baec759
There's no need for that opening_files_lock to be used in boot.py
rwols 81e3ab8
Merge branch 'main' into feat/asyncio
rwols 89d8ae9
Simplify types in statement
rwols ff28a4e
Fix running code actions with multiple language servers
rwols 0ab6df7
Prefer apply_workspace_edit over apply_workspace_edit_async
rwols 4801cd6
Merge branch 'main' into feat/asyncio
rwols c7af523
Fix code actions on save
rwols f3d0684
Rename: run_in_asyncio_thread -> run_on_asyncio_thread
rwols 9d2283d
Rename: _run_in_st_thread -> _run_on_st_thread
rwols fbfba1c
Rename: run_in_main_thread -> run_on_main_thread
rwols e39ccf2
Rename: run_in_async_thread -> run_on_async_thread
rwols 4081b04
Rename: wait_until_st_state -> wait_until
rwols 42111fb
Merge branch 'main' into feat/asyncio
rchl f7686b1
debug asyncio.InvalidStateError
rwols 317ff07
Revert "debug asyncio.InvalidStateError"
rwols 54b99af
Allow PostResponseCallback to be a coroutine object
rwols 1dbb546
Tighten exception catching in Session._refresh_text_document_content
rwols ba14429
Add some comments when we invoke loop.run_in_executor
rwols d3a3641
Merge branch 'main' into feat/asyncio
rwols eee901a
Revert "Allow PostResponseCallback to be a coroutine object"
rchl 982079c
simplify
rchl a76cc3e
Fix: don't try to resolve a cancelled future
rwols be9b11f
Make run_tasks a method of LspTextCommandWithTasks
rwols File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,6 +4,7 @@ | |
| "bracex", | ||
| "mdpopups", | ||
| "orjson", | ||
| "sublime_aio", | ||
| "typing_extensions", | ||
| "wcmatch" | ||
| ] | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,46 @@ | ||
| import concurrent.futures | ||
| import threading | ||
| from typing import Any, Callable, TypeVar | ||
|
|
||
| import sublime | ||
|
|
||
|
|
||
| class _SetTimeoutAsyncExecutor(concurrent.futures.Executor): | ||
| """ | ||
| An Executor that wraps sublime.set_timeout_async. | ||
| """ | ||
|
|
||
| def __init__(self) -> None: | ||
| self._running = 0 | ||
| self._shuttingdown = False | ||
| self._lock = threading.Lock() | ||
| self._cv = threading.Condition(self._lock) | ||
|
|
||
| def submit(self, fn: Callable[..., Any], *args: Any, **kwargs: Any) -> concurrent.futures.Future: | ||
| if self._shuttingdown: | ||
| raise RuntimeError("Executor is shutting down") | ||
| future: concurrent.futures.Future = concurrent.futures.Future() | ||
| with self._cv: | ||
| self._running += 1 | ||
|
|
||
| def run() -> None: | ||
| try: | ||
| future.set_result(fn(*args, **kwargs)) | ||
| except BaseException as ex: | ||
| future.set_exception(ex) | ||
| with self._cv: | ||
| self._running -= 1 | ||
| if self._running == 0: | ||
| self._cv.notify() | ||
|
|
||
| sublime.set_timeout_async(run) | ||
| return future | ||
|
|
||
| def shutdown(self, wait: bool = True, *, cancel_futures: bool = False) -> None: | ||
| self._shuttingdown = True | ||
| if wait: | ||
| with self._cv: | ||
| self._cv.wait_for(lambda: self._running == 0) | ||
|
|
||
|
|
||
| executor = _SetTimeoutAsyncExecutor() |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.