-
Notifications
You must be signed in to change notification settings - Fork 29.8k
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
API for getting a text document without opening #15723
Comments
Why? I don't see that as a benefit but as additional complexity |
Many language servers need to index all files in the project. The linked protocol extensions are an effort to allow them to do that over LSP, without accessing the file system, because servers often run in an isolated environment like a Docker container. They can, for example, operate solely on the Now, to implement these requests in VS Code the I don't see why there would be added complexity - |
That is incorrect. The document data is transferred only once and inside the extension host references are passed around.
No, the editor can decide at any time to close a document again. This usually happens when the last editor showing a document closes but also in other cases. |
Okay, so maybe I misunderstand the
|
So, @aeschli or @dbaeumer know best but to my knowledge |
Thanks for clearing that up @jrieken! I think I can work with that. |
The language server client filters open events based on a document selector. However if the server expressed interest in lets say *.php files and the @jrieken I assume that openTextDocument does trigger on open event. |
@dbaeumer Yes it does - unless it already is open. @felixfbecker Objects closing this after clarifying things? |
Well then my assumption was correct after all
I need to prevent VS Code from sending a |
Where do you want to access the document content? In the extension host or in a language server? |
In the language client, I want to register a custom handler that uses the vscode API to get the document content, all to allow the server to get the document content. So to the correct answer for your question would be: both. Once I have it in the former, I can enable it in the latter. |
@felixfbecker I can understand that you don't want to read the file from disk on the server side but why can't the client simply load the content of the file. |
@dbaeumer Because there is no guarantee that the URI is a Is there anything that speaks against adding this API? |
Glad to see it on March. Want this for vue LS too. |
@jrieken this is the content provider API we talked about. Right. |
Yes, idea is that we will something like |
fyi @joaomoreno you wanna use this for the git-extension |
@jrieken can we make it return a full |
Which then just means don't fire an event? |
Probably, yeah. In pseudo code: loadTextDocument(uri) {
const doc = getTextDocument(uri);
fireEvents(doc);
return doc;
}
getTextDocument(uri) {
// All the logic
} |
re #15723 (comment) @joaomoreno actually not. So, I am back to may old point of view that this is confusing and unhelpful. @felixfbecker your main motivation seems to come from the concern of transferring/opening a document twice. The sequence-diagram in #15723 (comment) isn't correct, the flow is:
Take a look at the |
@jrieken I'm confused by your diagram, what do these calls represent? Is that the current or proposed state? My diagram were supposed to be LSP calls, I am not too familiar with the VS Code internals. Could you explain how you would solve the use case of a |
That is today and the truth on the extension host which is also the source of truth for the LSP because the LSP-client is implemented as an extension. The existence of documents in the extension host and the LSP server is driven by events, not open request which just trigger those events. |
What do you mean with "open request"? Is it possible with the current or proposed API to achieve something like this for language servers?
|
Yes, we will not keep it in memory for long. The extension host function Documents requested by extensions get closed after a timeout and/or when many document have been requested. Because we recently migrated the underlying infrastructure not everything is there yet but in essence extensions cannot make the main side hold on to arbitrary amounts of documents. |
Ah, gotcha. Of course it needs to be loaded in memory for a short time, but it should just not require an explicit close and not trigger any didOpen events. |
Yes, it will not require an explicit close because the editor owns the lifecycle of all documents. There will onDidOpen and onDidClose events because that's how the world works. What we will add is a new property |
@jrieken will it be possible in any way to prevent the |
I believe @dbaeumer's plan is to use the |
For the LSP protocol and VS Code library implementation the plan is as follows:
|
Closing because the open-editor situation has been clarified and improved. Extensions won't be able to open document that we hold on to for long. Also when an extension holds onto a closed document it won't explode anymore but has a boolean that reflects that state. Today, knowing what document is open (as loaded from disk into memory) and knowing what document is showing is easy because a TextEditor is always bound to a document. What's not possible today is to know what the current 'tab-state' is. We track that issue in #15178. |
As an extension developer, I sometimes want to get the content of a textDocument identified by a URI from VS Code, but without opening it and triggering
onDidOpen
events.My use case is extending the
LanguageClient
to support thetextDocument/xfiles
extension. Language servers in isolated environments need a way to request file contents without accessing the file system directly, and there should be a way to extend theLanguageClient
to support these requests as well. I cannot read from disk because the URI could also be the URI of an in-memory document.There are probably other use cases where an extension needs to inspect file contents without wanting VS Code to open them.
Current API:
Proposal:
The text was updated successfully, but these errors were encountered: