Skip to content
This repository has been archived by the owner on Apr 14, 2022. It is now read-only.

Implement auto indentation when pressing the : or Enter keys #671

Closed
DonJayamanne opened this issue Feb 27, 2019 · 6 comments
Closed

Implement auto indentation when pressing the : or Enter keys #671

DonJayamanne opened this issue Feb 27, 2019 · 6 comments

Comments

@DonJayamanne
Copy link

DonJayamanne commented Feb 27, 2019

  • Today indentation of code is implemented within the extension (and buggy, as we do not have the token/AST information, etc)
  • The C# extension supports similar features (indentation changes) when you type the character }.
    • The C# extension is TS code, that sends requests to a .NET process over a protocol.
    • I.e. .NET is performing the necessary formatting, and sending back the formatted code (asynchronously) back to the TS code.
  • We need the same thing, when users type the character :.
    • I.e. TS can send a custom request to language server, get the response back and send formatted code to VSC.

I.e. if C# extension (using the .NET code, async communication via a protocol) can do this, then how about we do the same thing (using LSP over custom request).

https://github.com/OmniSharp/omnisharp-vscode/blob/f0a0336ced8cb44f78bdee88120bfe9d62a596c0/src/features/formattingEditProvider.ts#L44

export async function formatAfterKeystroke(server: OmniSharpServer, request: protocol.FormatAfterKeystrokeRequest, token: vscode.CancellationToken) {
https://github.com/OmniSharp/omnisharp-vscode/blob/f0a0336ced8cb44f78bdee88120bfe9d62a596c0/src/omnisharp/utils.ts#L42

Related to microsoft/vscode-python#481

@MikhailArkhipov
Copy link

Omni is not using LSP. They have regular TS extension which then runs their process manually and communicates with it via custom protocol. This is not technically a language server at all. Omni was implemented way before LSP was born.

When actual LS/LSP runs the extension TS/editor part is bypassed and requests go directly to the LS process.

Therefore what you are asking is a way to get to LS while actually VS Code did not launch it. This can be done at the extension side - start the process and perform similar connection hookup as VS Code performs internally in regular LS scenarios. Then send and receive requests either via LSP or via custom messages.

This is basically a hybrid solution. There may be other cases such as get syntax errors from the parser without actually switching to LS.

@DonJayamanne
Copy link
Author

DonJayamanne commented Feb 27, 2019

Omni is not using LSP. They have regular TS extension which then runs their process manually and communicates with it via custom protocol. This is not technically a language server at all. Omni was implemented way before LSP was born.

Agreed. I just see it as a separate process that ts extension communicates over some protocol.

When actual LS/LSP runs the extension TS/editor part is bypassed and requests go directly to the LS process.

Yes, but we can still send custom requests via the language client, and that's the plan. No changes.

Therefore what you are asking is a way to get to LS while actually VS Code did not launch it.

No, we'll let VSC launch the language server as done today. No changes there.
All, we'll do is use the language client and send a request (we already do this today), so architecturally, no changes.
The only exception would be we'd probably send a custom request to the LSP.
FYI - we already send requests manually to LS from extension code manually.

This is basically a hybrid solution. There may be other cases such as get syntax errors from the parser without actually switching to LS.

Not really, we'll only do this for language server, and not when using Jedi.
We will not change how LS is loaded.

@MikhailArkhipov
Copy link

No, we'll let VSC launch the language server as done today. No changes there.

Do you still get requests for the editor functionality when LS is running?

@DonJayamanne
Copy link
Author

Do you still get requests for the editor functionality when LS is running?

Not sure what you mean. But we have the ability to manually send requests to the LS, and we do this today.

@MikhailArkhipov
Copy link

I mean that when LS is up you don't get requests for completion, tooltips, etc in the TS part, they bypass the extension and go straight to LS. I.e. TS 'completion provider' is mute. Do you still get requests for the indentation?

@DonJayamanne
Copy link
Author

Do you still get requests for the indentation?

Got it. No that doesn't work.
Also double check with C#, the auto indentation of } is done by VSC and not C#.
I.e. disabling formatOnType doesn't provide what we need.
Back to square one.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants