Skip to content
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

FormattingOptions should match the LSP's #97343

Closed
giltho opened this issue May 9, 2020 · 7 comments
Closed

FormattingOptions should match the LSP's #97343

giltho opened this issue May 9, 2020 · 7 comments
Assignees
Labels
api feature-request Request for new features or functionality

Comments

@giltho
Copy link

giltho commented May 9, 2020

Hi!

The LSP describes more formatting features than what VSCode can provide. Therefore, the LanguageClient can only handle part of the protocol's available parameters (see the related issue : microsoft/vscode-languageserver-node#617)

In particular, the FormattingOptions interface should contain more fields:

export interface FormattingOptions {
	/**
	 * Size of a tab in spaces.
	 */
	tabSize: number;
	/**
	 * Prefer spaces over tabs.
	 */
	insertSpaces: boolean;
	/**
	 * Trim trailing whitespace on a line.
	 */
	trimTrailingWhitespace?: boolean;
	/**
	 * Insert a newline character at the end of the file if one does not exist.
	 */
	insertFinalNewline?: boolean;
	/**
	 * Trim all newlines after the final newline at the end of the file.
	 */
	trimFinalNewlines?: boolean;
}

If there is also a way to pass more options (the [key: string]: boolean | number | string; part of the protocol) it would be extra nice, but I don't know if that should be done by vscode of handled directly by the language-client lib.

Also, since we're here, maybe this type and the protocol's should be extended with a lineWidth parameter which is common to a lot of formatters and we need in the case of the OCaml LSP (see issues on ocaml-lsp and on the ocaml-vscode plugin)

@alexdima alexdima assigned jrieken and unassigned alexdima May 11, 2020
@jrieken
Copy link
Member

jrieken commented May 11, 2020

I don't think that's needed, all those trimming features are built into VS Code itselves and no formatter is needed for that. We have a "catch-all" signature for various different options:

vscode/src/vs/vscode.d.ts

Lines 3417 to 3420 in af3c79e

/**
* Signature for further properties.
*/
[key: string]: boolean | number | string;

I honestly think that enough, because it kinda matches what vs code offers by default and other options can be defined (and read) by extensions themselves

@jrieken jrieken added this to the Backlog Candidates milestone May 11, 2020
@jrieken jrieken added api feature-request Request for new features or functionality labels May 11, 2020
@giltho
Copy link
Author

giltho commented May 11, 2020

Hi ! Thank you for your answer :)

There is a mismatch between protocol usage and vscode itself.
When writing a language server, one expects to receive formatting options through DocumentFormattingParams.options : FormattingOptions.

And although the interface exposes more, VSCode only passes part of that information to the provider here, because modes.FormattingOptions is a more restricted type than the one exposed in vscode.d.ts.

Not being able to use these parameters creates a discrepancy between vscode and other editors which may pass the information there.

It would be ok for vscode not to implement and pass them, but then the protocol should probably also deprecate these parameters and ask the server implementers to go lookup in the workspace configuration for these options.

@jrieken
Copy link
Member

jrieken commented May 11, 2020

And although the interface exposes more, VSCode only passes part of that information to the provider here, because modes.FormattingOptions is a more restricted type than the one exposed in vscode.d.ts.

This isn't a problem of VS Code but the LSP client library. It is free to add whatever option it wants. fyi @dbaeumer

@dbaeumer
Copy link
Member

dbaeumer commented Jul 1, 2020

In LSP we added theses options for editor which don't have built in support for this and need to depend on a formatter.

@github-actions github-actions bot locked and limited conversation to collaborators Aug 25, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
api feature-request Request for new features or functionality
Projects
None yet
Development

No branches or pull requests

5 participants
@jrieken @dbaeumer @alexdima @giltho and others