Skip to content

Commit dca2c64

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

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

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)