Skip to content

Commit 687fe0e

Browse files
authored
Merge pull request #4302 from JoeRobich/add-organize-imports
Add option to organize imports during document formatting.
2 parents b04c301 + 151b11d commit 687fe0e

File tree

5 files changed

+15
-2
lines changed

5 files changed

+15
-2
lines changed

package.json

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -820,6 +820,11 @@
820820
"default": false,
821821
"description": "Enables support for showing unimported types and unimported extension methods in completion lists. When committed, the appropriate using directive will be added at the top of the current file. This option can have a negative impact on initial completion responsiveness, particularly for the first few completion sessions after opening a solution."
822822
},
823+
"omnisharp.organizeImportsOnFormat": {
824+
"type": "boolean",
825+
"default": false,
826+
"description": "Specifies whether 'using' directives should be grouped and sorted during document formatting."
827+
},
823828
"razor.plugin.path": {
824829
"type": [
825830
"string",

src/observers/OptionChangeObserver.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@ const omniSharpOptions: ReadonlyArray<OptionsKey> = [
2020
"loggingLevel",
2121
"enableEditorConfigSupport",
2222
"enableDecompilationSupport",
23-
"enableImportCompletion"
23+
"enableImportCompletion",
24+
"organizeImportsOnFormat",
2425
];
2526

2627
function OmniSharpOptionChangeObservable(optionObservable: Observable<Options>): Observable<Options> {

src/omnisharp/options.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ export class Options {
1616
public maxProjectResults: number,
1717
public useEditorFormattingSettings: boolean,
1818
public useFormatting: boolean,
19+
public organizeImportsOnFormat: boolean,
1920
public showReferencesCodeLens: boolean,
2021
public showTestsCodeLens: boolean,
2122
public disableCodeActions: boolean,
@@ -74,6 +75,7 @@ export class Options {
7475
const enableImportCompletion = omnisharpConfig.get<boolean>('enableImportCompletion', false);
7576

7677
const useFormatting = csharpConfig.get<boolean>('format.enable', true);
78+
const organizeImportsOnFormat = omnisharpConfig.get<boolean>('organizeImportsOnFormat', false);
7779

7880
const showReferencesCodeLens = csharpConfig.get<boolean>('referencesCodeLens.enabled', true);
7981
const showTestsCodeLens = csharpConfig.get<boolean>('testsCodeLens.enabled', true);
@@ -107,6 +109,7 @@ export class Options {
107109
maxProjectResults,
108110
useEditorFormattingSettings,
109111
useFormatting,
112+
organizeImportsOnFormat,
110113
showReferencesCodeLens,
111114
showTestsCodeLens,
112115
disableCodeActions,

src/omnisharp/server.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,10 @@ export class OmniSharpServer {
355355
args.push('FormattingOptions:EnableEditorConfigSupport=true');
356356
}
357357

358+
if (options.organizeImportsOnFormat === true) {
359+
args.push('FormattingOptions:OrganizeImports=true');
360+
}
361+
358362
if (this.decompilationAuthorized && options.enableDecompilationSupport === true) {
359363
args.push('RoslynExtensionsOptions:EnableDecompilationSupport=true');
360364
}

test/unitTests/Fakes/FakeOptions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@
66
import { Options } from "../../../src/omnisharp/options";
77

88
export function getEmptyOptions(): Options {
9-
return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, 0, 0, false, false, false, false, false, false, false, undefined, "", "");
9+
return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, false, 0, 0, false, false, false, false, false, false, false, undefined, "", "");
1010
}

0 commit comments

Comments
 (0)