Skip to content

Commit 8042cb7

Browse files
committed
Add the option for Roslyn LSP to support organize imports
1 parent 72b0688 commit 8042cb7

File tree

6 files changed

+21
-12
lines changed

6 files changed

+21
-12
lines changed

package.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -739,6 +739,11 @@
739739
"default": true,
740740
"description": "%configuration.dotnet.autoInsert.enableAutoInsert%"
741741
},
742+
"dotnet.formatting.organizeImportsOnFormat": {
743+
"type": "boolean",
744+
"default": false,
745+
"description": "%configuration.dotnet.formatting.organizeImportsOnFormat%"
746+
},
742747
"dotnet.typeMembers.memberInsertionLocation": {
743748
"type": "string",
744749
"enum": [
@@ -1696,11 +1701,6 @@
16961701
"default": false,
16971702
"description": "%configuration.omnisharp.enableLspDriver%"
16981703
},
1699-
"omnisharp.organizeImportsOnFormat": {
1700-
"type": "boolean",
1701-
"default": false,
1702-
"description": "%configuration.omnisharp.organizeImportsOnFormat%"
1703-
},
17041704
"omnisharp.enableAsyncCompletion": {
17051705
"type": "boolean",
17061706
"default": false,

package.nls.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
"command.dotnet.test.debugTestsInContext": "Debug Tests in Context",
2525
"command.dotnet.restartServer": "Restart Language Server",
2626
"configuration.dotnet.autoInsert.enableAutoInsert": "Enable automatic insertion of documentation comments.",
27+
"configuration.dotnet.formatting.organizeImportsOnFormat": "Specifies whether 'using' directives should be grouped and sorted during document formatting. (Previously `omnisharp.organizeImportsOnFormat`)",
2728
"configuration.dotnet.defaultSolution.description": "The path of the default solution to be opened in the workspace, or set to 'disable' to skip it. (Previously `omnisharp.defaultLaunchSolution`)",
2829
"configuration.dotnet.server.path": "Specifies the absolute path to the server (LSP or O#) executable. When left empty the version pinned to the C# Extension is used. (Previously `omnisharp.path`)",
2930
"configuration.dotnet.server.componentPaths": "Allows overriding the folder path for built in components of the language server (for example, override the .roslynDevKit path in the extension directory to use locally built components)",
@@ -116,7 +117,6 @@
116117
"configuration.omnisharp.enableEditorConfigSupport": "Enables support for reading code style, naming convention and analyzer settings from .editorconfig.",
117118
"configuration.omnisharp.enableDecompilationSupport": "Enables support for decompiling external references instead of viewing metadata.",
118119
"configuration.omnisharp.enableLspDriver": "Enables support for the experimental language protocol based engine (requires reload to setup bindings correctly)",
119-
"configuration.omnisharp.organizeImportsOnFormat": "Specifies whether 'using' directives should be grouped and sorted during document formatting.",
120120
"configuration.omnisharp.enableAsyncCompletion": "(EXPERIMENTAL) Enables support for resolving completion edits asynchronously. This can speed up time to show the completion list, particularly override and partial method completion lists, at the cost of slight delays after inserting a completion item. Most completion items will have no noticeable impact with this feature, but typing immediately after inserting an override or partial method completion, before the insert is completed, can have unpredictable results.",
121121
"configuration.omnisharp.dotNetCliPaths": "Paths to a local download of the .NET CLI to use for running any user code.",
122122
"configuration.omnisharp.razor.plugin.path": "Overrides the path to the Razor plugin dll.",

src/omnisharp/server.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,7 @@ export class OmniSharpServer {
458458
args.push('FormattingOptions:EnableEditorConfigSupport=true');
459459
}
460460

461-
if (omnisharpOptions.organizeImportsOnFormat === true) {
461+
if (commonOptions.organizeImportsOnFormat === true) {
462462
args.push('FormattingOptions:OrganizeImports=true');
463463
}
464464

src/shared/migrateOptions.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -100,6 +100,10 @@ export const migrateOptions = [
100100
oldName: 'dotnet.implementType.propertyGenerationBehavior',
101101
newName: 'dotnet.typeMembers.propertyGenerationBehavior',
102102
},
103+
{
104+
oldName: 'omnisharp.organizeImportsOnFormat',
105+
newName: 'dotnet.formatting.organizeImportsOnFormat',
106+
},
103107
];
104108

105109
export async function MigrateOptions(vscode: vscode): Promise<void> {

src/shared/options.ts

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ export interface CommonOptions {
1717
readonly defaultSolution: string;
1818
readonly unitTestDebuggingOptions: object;
1919
readonly runSettingsPath: string;
20+
readonly organizeImportsOnFormat: boolean;
2021
}
2122

2223
export interface OmnisharpServerOptions {
@@ -34,7 +35,6 @@ export interface OmnisharpServerOptions {
3435
readonly enableImportCompletion: boolean;
3536
readonly enableAsyncCompletion: boolean;
3637
readonly analyzeOpenDocumentsOnly: boolean;
37-
readonly organizeImportsOnFormat: boolean;
3838
readonly disableMSBuildDiagnosticWarning: boolean;
3939
readonly showOmnisharpLogOnError: boolean;
4040
readonly minFindSymbolsFilterLength: number;
@@ -157,6 +157,9 @@ class CommonOptionsImpl implements CommonOptions {
157157
public get runSettingsPath() {
158158
return readOption<string>('dotnet.unitTests.runSettingsPath', '', 'omnisharp.testRunSettings');
159159
}
160+
public get organizeImportsOnFormat() {
161+
return readOption<boolean>('dotnet.formatting.organizeImportsOnFormat', false);
162+
}
160163
}
161164

162165
class OmnisharpOptionsImpl implements OmnisharpServerOptions {
@@ -227,9 +230,6 @@ class OmnisharpOptionsImpl implements OmnisharpServerOptions {
227230
const analyzeOpenDocumentsOnlyNewOption = diagnosticAnalysisScope == 'openFiles';
228231
return analyzeOpenDocumentsOnlyLegacyOption || analyzeOpenDocumentsOnlyNewOption;
229232
}
230-
public get organizeImportsOnFormat() {
231-
return readOption<boolean>('omnisharp.organizeImportsOnFormat', false);
232-
}
233233
public get disableMSBuildDiagnosticWarning() {
234234
return readOption<boolean>('omnisharp.disableMSBuildDiagnosticWarning', false);
235235
}
@@ -483,7 +483,6 @@ export const OmnisharpOptionsThatTriggerReload: ReadonlyArray<keyof OmnisharpSer
483483
'enableEditorConfigSupport',
484484
'enableDecompilationSupport',
485485
'enableImportCompletion',
486-
'organizeImportsOnFormat',
487486
'enableAsyncCompletion',
488487
'useModernNet',
489488
'enableLspDriver',

test/lsptoolshost/unitTests/configurationMiddleware.test.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,6 +267,12 @@ const testData = [
267267
declareInPackageJson: true,
268268
section: editorBehaviorSection,
269269
},
270+
{
271+
serverOption: 'csharp|formatting.dotnet_formatting_sort_imports',
272+
vsCodeConfiguration: 'dotnet.formatting.organizeImportsOnFormat',
273+
declareInPackageJson: true,
274+
section: editorBehaviorSection,
275+
},
270276
];
271277

272278
describe('Server option name to vscode configuration name test', () => {

0 commit comments

Comments
 (0)