-
Notifications
You must be signed in to change notification settings - Fork 184
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
Provide Transport
as parameter when invoking plugin.on_post_start
#2491
Comments
Thanks for the request and the detailed description. I haven't worked a lot on the code of the subprocess creation and stdio transports, so perhaps there are others who have more insight on that, but essentially I don't see any reason against exposing the Lines 29 to 30 in 7554363
However, from the technical side I don't think we can simply add it in form of a keyword argument to diff --git a/plugin/core/windows.py b/plugin/core/windows.py
index 29abdea9..136453f4 100644
--- a/plugin/core/windows.py
+++ b/plugin/core/windows.py
@@ -37,6 +37,7 @@ from .workspace import sorted_workspace_folders
from collections import deque
from collections import OrderedDict
from datetime import datetime
+from inspect import signature
from subprocess import CalledProcessError
from time import perf_counter
from typing import Any, Generator, TYPE_CHECKING
@@ -279,7 +280,10 @@ class WindowManager(Manager, WindowConfigChangeListener):
transport_config = config.resolve_transport_config(variables)
transport = create_transport(transport_config, transport_cwd, session)
if plugin_class:
- plugin_class.on_post_start(self._window, initiating_view, workspace_folders, config)
+ if len(signature(plugin_class.on_post_start).parameters) == 5:
+ plugin_class.on_post_start(self._window, initiating_view, workspace_folders, config, transport)
+ else:
+ plugin_class.on_post_start(self._window, initiating_view, workspace_folders, config)
config.set_view_status(initiating_view, "initialize")
session.initialize_async(
variables=variables, ... which is a bit awkward and results in a linter error (unless we define the signature of the abstract implementation as Of course we could suppress the linter error on this line if there is no other way, but perhaps you have another idea for an implementation? Or perhaps it would be better (i.e. more high level) to instead pass the
PRs are always welcome! |
I would be happy to align on a new "hook" API for I find your proposal to use I'm also sympathetic to passing the Line 1517 in cd7cb68
As such, we would either need to 1) invoke Line 1521 in cd7cb68
I'm seeing that Line 834 in fc5a7c7
As such, it doesn't seem to matter whether |
We can keep this There are some changes needed in plugin/core/transports.py to send these raw optional |
I don't feel like we need to be shoe-horning this to an existing method if it doesn't feel right. It would just make the API more confusing. A new method like |
And note that stdio is only one of the ways the servers can use to communicate with so we might want to create a higher level method to abstract that. We should think if something like that fits with other methods (tcp, node-ipc in the future). If it doesn't then the method name should probably be very specific like |
But you can't really send anything else after the |
I don't understand this comment... Isn't the Transport abstraction the point of not having to care about the transport details (tcp, tls, node-ipc, websocket, ...)? |
But why would that be an argument against what I've suggested? Maybe I'm missing something since I haven't re-read the thread recently?
My point is that we should think whether such functionality would also apply to other transport methods. Like, is it even possible to do something equivalent with those? Because if not then what should happen in those cases? Should the method throw or do nothing or...? |
Hi folks, Some technical blockers for releasing this plugin have been mitigated, so this is something I'm looking to release more actively now.
This would be possible to do, and it would support the specific requirement(s) I've proposed thus far. I will say that if interactive messaging is required between client/server before the Providing |
Is your feature request related to a problem? Please describe.
When launching the LSP server for AWS Q Developer, this LSP server expects an AES encryption key to be written on
stdin
- before any other messages - in order to encrypt AWS credentials that would later be sent by the LSP client. This ensures plaintext AWS credentials are not persisted in logs by LSP clients. One can observe the need to receive an AES encryption key before any other messages by reading the following code in the LSP server for AWS Q Developer:Describe the solution you'd like
Within an
LSP
plugin, the only opportunity for the plugin to access the process for the underlyingTransport
of an LSP server - before any messages are sent to it - is within theon_post_start
hook for anAbstractPlugin
:LSP/plugin/core/windows.py
Line 282 in fc5a7c7
LSP/plugin/core/sessions.py
Line 943 in cd7cb68
However, in order for the
AbstractPlugin
to access the underlying process inon_post_start
, it needs to receive theTransport
instance created for theSession
. Since theinitialize_async
method onSession
will send theinitialize
message to the LSP server, there is no other opportunity for the LSP plugin to provide an AES key to the LSP server before other messages are sent:LSP/plugin/core/windows.py
Line 284 in fc5a7c7
LSP/plugin/core/sessions.py
Line 1510 in cd7cb68
Given these constraints, it seems the best way to support the LSP server for AWS Q Developer is to provide the
Transport
instance that the plugin will use as an additional (keyword?) parameter to theon_post_start
hook.Describe alternatives you've considered
In order to get around this issue, I found that
transports.py
stores a singletonWeakset
of processes launched by eachTransport
instance in a variable called_subprocesses
:LSP/plugin/core/transports.py
Line 285 in cd7cb68
Currently, I am importing this
_subprocesses
fromtransports.py
and finding the "most recent" subprocess that the LSP plugin has not seen before. However, this is very brittle and relies on internal implementation details. It would be better for theon_post_start
hook to explicitly provide theTransport
instance, so there's no possible ambiguity in resolving the correct process to write the AWS encryption key to.Additional context
I am authoring an LSP plugin for AWS Q Developer at this time, and Amazon will be unwilling to compromise the security profile of this LSP plugin by sending unencrypted AWS credentials over LSP messages to the LSP server for AWS Q Developer. I kindly ask that we consider this concern critical to the success of new LSP plugins that will be meaningful to Sublime Text users.
I would be happy to author a PR for this issue as well, but I'd like to get alignment with the community first before doing so, in order to address any material concerns they may have.
The text was updated successfully, but these errors were encountered: