Skip to content

Commit

Permalink
Add options to organize imports during document formatting.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoeRobich committed Dec 17, 2020
1 parent 942a0cb commit dc91d94
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 2 deletions.
5 changes: 5 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -820,6 +820,11 @@
"default": false,
"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."
},
"omnisharp.organizeImportsOnFormat": {
"type": "boolean",
"default": false,
"description": "Specifies whether 'using' directives should be grouped and sorted during document formatting."
},
"razor.plugin.path": {
"type": [
"string",
Expand Down
3 changes: 2 additions & 1 deletion src/observers/OptionChangeObserver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ const omniSharpOptions: ReadonlyArray<OptionsKey> = [
"loggingLevel",
"enableEditorConfigSupport",
"enableDecompilationSupport",
"enableImportCompletion"
"enableImportCompletion",
"organizeImportsOnFormat",
];

function OmniSharpOptionChangeObservable(optionObservable: Observable<Options>): Observable<Options> {
Expand Down
3 changes: 3 additions & 0 deletions src/omnisharp/options.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ export class Options {
public maxProjectResults: number,
public useEditorFormattingSettings: boolean,
public useFormatting: boolean,
public organizeImportsOnFormat: boolean,
public showReferencesCodeLens: boolean,
public showTestsCodeLens: boolean,
public disableCodeActions: boolean,
Expand Down Expand Up @@ -74,6 +75,7 @@ export class Options {
const enableImportCompletion = omnisharpConfig.get<boolean>('enableImportCompletion', false);

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

const showReferencesCodeLens = csharpConfig.get<boolean>('referencesCodeLens.enabled', true);
const showTestsCodeLens = csharpConfig.get<boolean>('testsCodeLens.enabled', true);
Expand Down Expand Up @@ -107,6 +109,7 @@ export class Options {
maxProjectResults,
useEditorFormattingSettings,
useFormatting,
organizeImportsOnFormat,
showReferencesCodeLens,
showTestsCodeLens,
disableCodeActions,
Expand Down
4 changes: 4 additions & 0 deletions src/omnisharp/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,10 @@ export class OmniSharpServer {
args.push('FormattingOptions:EnableEditorConfigSupport=true');
}

if (options.organizeImportsOnFormat === true) {
args.push('FormattingOptions:OrganizeImports=true');
}

if (this.decompilationAuthorized && options.enableDecompilationSupport === true) {
args.push('RoslynExtensionsOptions:EnableDecompilationSupport=true');
}
Expand Down
2 changes: 1 addition & 1 deletion test/unitTests/Fakes/FakeOptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,5 @@
import { Options } from "../../../src/omnisharp/options";

export function getEmptyOptions(): Options {
return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, 0, 0, false, false, false, false, false, false, false, undefined, "", "");
return new Options("", "", false, "", false, 0, 0, false, false, false, false, false, false, false, 0, 0, false, false, false, false, false, false, false, undefined, "", "");
}

0 comments on commit dc91d94

Please sign in to comment.