Skip to content

Commit d966c74

Browse files
committed
feat: add setting to disable adding imports on paste
Signed-off-by: Fred Bricon <fbricon@gmail.com>
1 parent 4680aa2 commit d966c74

File tree

3 files changed

+15
-2
lines changed

3 files changed

+15
-2
lines changed

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -260,10 +260,11 @@ The following settings are supported:
260260
* `java.completion.engine`: [Experimental] Select code completion engine. Defaults to `ecj`.
261261
* `java.references.includeDeclarations`: Include declarations when finding references. Defaults to `true`
262262
* `java.jdt.ls.appcds.enabled` : [Experimental] Enable Java AppCDS (Application Class Data Sharing) for improvements to extension activation. When set to `auto`, AppCDS will be enabled in Visual Studio Code - Insiders, and for pre-release versions.
263-
264-
New in 1.50.0
265263
* `java.hover.javadoc.enabled` : Enable/disable displaying Javadoc on hover. Defaults to `true`.
266264

265+
New in 1.53.0
266+
* `java.updateImportsOnPaste.enabled` : Enable/disable auto organize imports when pasting code. Defaults to `true`.
267+
267268
Semantic Highlighting
268269
===============
269270
[Semantic Highlighting](https://github.com/redhat-developer/vscode-java/wiki/Semantic-Highlighting) fixes numerous syntax highlighting issues with the default Java Textmate grammar. However, you might experience a few minor issues, particularly a delay when it kicks in, as it needs to be computed by the Java Language server, when opening a new file or when typing. Semantic highlighting can be disabled for all languages using the `editor.semanticHighlighting.enabled` setting, or for Java only using [language-specific editor settings](https://code.visualstudio.com/docs/getstarted/settings#_languagespecific-editor-settings).

package.json

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1387,6 +1387,13 @@
13871387
"scope": "window",
13881388
"order": 20
13891389
},
1390+
"java.updateImportsOnPaste.enabled": {
1391+
"type": "boolean",
1392+
"default": true,
1393+
"description": "Enable/disable auto organize imports when pasting code",
1394+
"scope": "window",
1395+
"order": 25
1396+
},
13901397
"java.sources.organizeImports.starThreshold": {
13911398
"type": "integer",
13921399
"description": "Specifies the number of imports added before a star-import declaration is used.",

src/pasteAction.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ export function registerCommands(languageClient: LanguageClient, context: Extens
1414
}
1515

1616
export async function registerOrganizeImportsOnPasteCommand(): Promise<void> {
17+
1718
const clipboardText: string = await env.clipboard.readText();
1819
const editor: TextEditor = window.activeTextEditor;
1920
const documentText: string = editor.document.getText();
@@ -40,6 +41,10 @@ export async function registerOrganizeImportsOnPasteCommand(): Promise<void> {
4041

4142
action.then((wasApplied) => {
4243
if (wasApplied && editor.document.languageId === "java") {
44+
const updateImportsOnPasteEnabled = workspace.getConfiguration().get<boolean>("java.updateImportsOnPaste.enabled", true);
45+
if (!updateImportsOnPasteEnabled) {
46+
return;
47+
}
4348
const fileURI = editor.document.uri.toString();
4449
const hasText: boolean = documentText !== null && /\S/.test(documentText);
4550
if (hasText) {

0 commit comments

Comments
 (0)