-
Notifications
You must be signed in to change notification settings - Fork 414
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
Add organize imports command #341
Conversation
src/commands.ts
Outdated
@@ -67,5 +67,15 @@ export namespace Commands { | |||
/** | |||
* Open Java Language Server Log file | |||
*/ | |||
export const OPEN_SERVER_LOG = 'java.open.serverLog'; | |||
export const OPEN_SERVER_LOG = 'java.open.serverLog'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Something happened with the indentation here and below.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
basically tabs were replaced with spaces. I think we need to set a project preference for indentation. But until then we should try to keep indentation coherent all over the place.
Ultimately we can do a major sweep to format all files at once, but that's the subject of another commit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would like to keep the indentation consistent, and will accept either tab or whitespace.
As I went through the vscode-java codebase, there are mixed with tab and whitespaces. We need make them consistent anyway.
Can you also add the new command to tests at https://github.com/redhat-developer/vscode-java/blob/master/test/extension.test.ts#L25 |
I can't bind a keyboard shortcut to the organize import command from the VSCode UI. It works when editing the keybindings.json manually. However, when calling the shortcut on a file with imports to organize, an error occurs on the server:
|
package.json
Outdated
@@ -150,6 +150,11 @@ | |||
"command": "java.open.serverLog", | |||
"title": "Open Java Language Server log file", | |||
"category": "Java" | |||
}, | |||
{ | |||
"command": "vscode.java.edit.organizeImports", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we skip the vscode prefix? Having all commands under the java
namespace is more consistent
package.json
Outdated
"menus": { | ||
"editor/context": [ | ||
{ | ||
"command": "vscode.java.edit.organizeImports", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
again, skip vscode prefix
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This cannot be skip. There are two commands here actually.
- One is appeared on the VSCode UI side, which is starting with prefix "vscode"
- Another one is just starting with "java...", which used for underlying talking with JDT.LS, which is neutral.
src/commands.ts
Outdated
/** | ||
* VSCode UI for organize imports commands | ||
*/ | ||
export const VSCODE_EDIT_ORGANIZE_IMPORTS = 'vscode.java.edit.organizeImports'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does having the same command id for client and server cause any issue?
src/extension.ts
Outdated
@@ -160,6 +160,22 @@ export function activate(context: ExtensionContext) { | |||
} | |||
}); | |||
|
|||
commands.registerCommand(Commands.VSCODE_EDIT_ORGANIZE_IMPORTS, async (uri: Uri) => { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need to check the uri is actually an Uri
src/extension.ts
Outdated
commands.registerCommand(Commands.VSCODE_EDIT_ORGANIZE_IMPORTS, async (uri: Uri) => { | ||
const edit = await <any>commands.executeCommand(Commands.EXECUTE_WORKSPACE_COMMAND, Commands.EDIT_ORGANIZE_IMPORTS, uri.toString()); | ||
const workspaceEdit = new WorkspaceEdit(); | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
any way to reuse what we have L156?
package.json
Outdated
"editor/context": [ | ||
{ | ||
"command": "vscode.java.edit.organizeImports", | ||
"when": "resourceLangId == java", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we call the command from a folder (not just files) in the explorer?
package.json
Outdated
"explorer/context": [ | ||
{ | ||
"command": "java.edit.organizeImports", | ||
"when": "resourceLangId == java", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can we enable it for folders too?
Any idea why calling a keyboard shortcut doesn't work? With:
the command receives an empty Object, instead of a URI, so nothing happens |
It seems the keybinding doesn't provide any parameters as the context menu do. We need change the behavior of these commands. |
Signed-off-by: Yaohai Zheng <yaozheng@microsoft.com>
For adding commands of "Organize Imports" in folder/workspace in VSCode, there is an issue here. We cannot determine current project(Could we? ). If so, the "Organize Imports" will be appeared in all VSCode instance, which is not desired behavior. |
Ok, we can figure out how to get folders working later on the client side. Though I still think we can have it supported on the server side |
@yaohaizh If you want to limit the command to only show up for certain files, this is how it works: https://github.com/Microsoft/vscode/blob/cabf4b2997fddf7eabff83d4d22ffa72381545b1/extensions/markdown/package.json#L191 |
Merged as 9779734 (with keybinding to |
Fixes #253
Signed-off-by: Yaohai Zheng yaozheng@microsoft.com
@fbricon @aeschli @gorkem