Language-server-protocol: Feature request: Server initiated "window/showTextDocument" notification

Created on 23 Nov 2018  路  18Comments  路  Source: microsoft/language-server-protocol

I would like to request a feature which is a server-initiated notification window/showTextDocument to open and/or show text document with a given Location.

Propose Change

  • a new method: 'window/showTextDocument'
  • params: Location defined as follows:
interface Location {
    uri: DocumentUri;
    range: Range;
}

Why?
This is beneficial when text files are generated by the Server and wants clients to open / show the text document(optionally to focus specific position) in cases such as test files generation, stubs generation.

I am already aware of the CreateFile and CreateFileOptions still it won't allow to focus on specific position for a Server initiated notification(please correct me if I am wrong here).

WDYT?

feature-request good first issue help wanted

All 18 comments

Makes sense to me. @rasika would you be will on working on a PR for this. I can assist and there is a guideline on how to do this: https://github.com/Microsoft/language-server-protocol/blob/master/contributing.md

I would make it a request to be able to return an indication if the opening was successful or failed.

@dbaeumer Thanks for the info. Sure, I'll proceed with the PR.

@rasika just to clarify. We need a PR here and in https://github.com/Microsoft/vscode-languageserver-node since at least one implementation is necessary as well.

Would it make sense to send an array so that you can open multiple files or just send multiple requests?

I am fine sending an array.

@rcjsuen +1 for the array. Will implement accordingly.

I am personally not a huge fan of serve-initiated requests to change the state of the client, because they break the causality: you can't reliably infer what was the cause of the request.

I'd rather we add an ability to focus specific document when applying edits. @rasika would it work for your if WorkspaceEdit had a focus array which described documents and locations editor should reveal after applying the edit?

@dbaeumer I would also appreciate an ability to focus a specific position after a document edit, and a specific document after workspace edit. In my rust-server, I use a bespoke implementation of edits to have this feature. I need it in two cases:

  • I have "create module" quick fix, which creates a new file, which better be focused
  • SIngle-file code actions would like to move cursor to a specific position in the newly generated code.

@matklad I would suggest to track this in another issue.

@rasika Could we make this a request instead of a notification. The open for example could fail for some reason.

@dbaeumer sorry couldn't track this thread after the vacation. Apparently can implement as a Request. Will start working on it today.

@rasika could you clarify if you need a completely separate request to show arbitrary text document, or if you have a more specific requirement of "open a text document after creating it using CreateFile resource operation"?

Replied to https://github.com/Microsoft/language-server-protocol/issues/663; adding a comment here for the future reference.

@rasika any news on the PR?
I'm adding resolvers finding capabilities to the GraphQL for VSCode extension (https://youtu.be/qBh6-Pd5Otw) and I definitely need this.
As you can see, in the video I'm still using the Go To Definition capabilities so everything's fine, but I've recently moved to CodeLens and I've found no way to initiate a showTextDocument from the server.
0
Basically I have a Location object for each resolver and when the user clicks on Go to Resolver I want VSCode to open it and focus on it.

Since @rasika didn't answer I decided to give it a try: https://github.com/Microsoft/vscode-languageserver-node/pull/490

You're gonna use it this way:

await connection
  .sendRequest(ShowTextDocumentRequest.type.method, {
    fileName,
    options: {
      selection,
  })

I just implemented it for the node server without making any protocol proposal, because I'd like to discuss it little bit to see if there is anything that you would like to change before.

Apology for the late reply. Please go ahead. Won't be able to actively contribute due to recent workload spike in my day job.

I just signed the CLA, let me know if there is anything else I can do to get such feature merged. We rely on it to release the next version of the graphql-for-vscode extension.

The actual client capability does not appear to have been added.

It happened again, so I've just opened a PR #1138 instead of posting another comment in another closed issue.

@KamasamaK thanks. Merged the PR.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ljw1004 picture ljw1004  路  3Comments

lanza picture lanza  路  6Comments

andfoy picture andfoy  路  6Comments

felixfbecker picture felixfbecker  路  3Comments

angelozerr picture angelozerr  路  6Comments