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

WorkspaceEdit should have an option to adjust whitespaces (like snippets) #52272

Closed
yaohaizh opened this issue Jun 19, 2018 · 11 comments
Closed
Assignees
Labels
feature-request Request for new features or functionality workspace-edit

Comments

@yaohaizh
Copy link

CodeAction and CompletionItems result doesn't format according to current selected opened file.
Code snippets (like ctor) are indented with tabs, but vscode fixes the indentation on-the-fly, according to its preferences. And the codeaction doesn't pass the current editor's indentation setting when invoke codeaction/completions.

Snippet/CodeAction/Completion should have similar behavior.

@vscodebot vscodebot bot added editor editor-autoindent Editor auto indentation issues labels Jun 19, 2018
@chrmarti chrmarti removed editor editor-autoindent Editor auto indentation issues labels Jun 19, 2018
@jrieken jrieken added the editor-code-actions Editor inplace actions (Ctrl + .) label Jun 19, 2018
@jrieken
Copy link
Member

jrieken commented Jun 19, 2018

We could do this but only when the code action use an edit, not a command. @yaohaizh Can you provide a concrete sample please.

@jrieken jrieken added the feature-request Request for new features or functionality label Jun 19, 2018
@MeikTranel
Copy link

@jrieken Given a workspace with everything set to indent using 2 spaces:

{
    "editor.insertSpaces": true,
    "editor.tabSize": 2
}

When applying a code action like ctor in a well-formatted (as in formatted according to the given settings) document, the inserted code block is not automatically formatted to the standards of the document. In my particular example, vscode-java was producing tab-indented snippets.

I assume what @yaohaizh meant was that as an API consumer he wants to read the language agnostic formatting settings like editor.tabSize to produce compliant strings beforehand instead of relying on forced formatting to happen after the fact. Is that a correct assessment, @yaohaizh ?

@yaohaizh
Copy link
Author

Yes, we use the Command for codeaction, but not edit.

I have uploaded a java sample project for this.
Repro:

  1. Install VSCode Java extension
  2. Open the project, waiting for the language server to be ready with installation of maven dependencies.
  3. Open the Inherit.java file
  4. Choose the Inherit class name, trigger the codeaction for "Add unimplemented method" and invoke it, the generated is tab based.
    vscode-java-demo.zip

@jrieken
Copy link
Member

jrieken commented Jun 20, 2018

Yes, we use the Command for codeaction, but not edit.

What command? Is your extension implementing that? Does it use the WorkspaceEdit-api?

@yaohaizh
Copy link
Author

The Command object of LSP for CodeAction result.

Command

Represents a reference to a command. Provides a title which will be used to represent a command in the UI. Commands are identified by a string identifier. The protocol currently doesn’t specify a set of well-known commands. So executing a command requires some tool extension code.

interface Command {
	/**
	 * Title of the command, like `save`.
	 */
	title: string;
	/**
	 * The identifier of the actual command handler.
	 */
	command: string;
	/**
	 * Arguments that the command handler should be
	 * invoked with.
	 */
	arguments?: any[];
}

And this is the java implementation:
https://github.com/eclipse/lsp4j/blob/83ae40a1d4b2b7076a8bb8ea28a953cf1fb1ca84/org.eclipse.lsp4j/src/main/xtend-gen/org/eclipse/lsp4j/Command.java#L44

We put the WorkspaceEdit object in the arguments array.

@jrieken
Copy link
Member

jrieken commented Jun 20, 2018

We put the WorkspaceEdit object in the arguments array.

Ok, so the WorkspaceEdit describes the textual changes you are making. I will update the title accordingly.

@jrieken jrieken changed the title CodeAction doesn't format the generated code WorkspaceEdit should have an option to adjust whitespaces (like snippets) Jun 20, 2018
@jrieken jrieken added workspace-edit and removed editor-code-actions Editor inplace actions (Ctrl + .) labels Jun 20, 2018
@jdneo
Copy link
Member

jdneo commented Aug 23, 2018

Hi @jrieken,

May I ask is there any further plan about this issue?

@vscodebot
Copy link

vscodebot bot commented Jan 15, 2020

This feature request is now a candidate for our backlog. The community has 60 days to upvote the issue. If it receives 20 upvotes we will move it to our backlog. If not, we will close it. To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@vscodebot
Copy link

vscodebot bot commented Mar 6, 2020

This feature request has not yet received the 20 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

Happy Coding

1 similar comment
@vscodebot
Copy link

vscodebot bot commented Mar 6, 2020

This feature request has not yet received the 20 community upvotes it takes to make to our backlog. 10 days to go. To learn more about how we handle feature requests, please see our documentation.

Happy Coding

@vscodebot
Copy link

vscodebot bot commented Mar 16, 2020

🙁 In the last 60 days, this feature request has received less than 20 community upvotes and we closed it. Still a big Thank You to you for taking the time to create this issue! To learn more about how we handle feature requests, please see our documentation.

Happy Coding!

@vscodebot vscodebot bot closed this as completed Mar 16, 2020
@github-actions github-actions bot locked and limited conversation to collaborators Apr 30, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
feature-request Request for new features or functionality workspace-edit
Projects
None yet
Development

No branches or pull requests

5 participants