From 5234816430df09ea89e33fb2f9edff957fd16091 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 5 Oct 2023 12:19:16 -0700 Subject: [PATCH 1/7] allows arrays to be used in code actions on save --- .../test/browser/stickyScroll.test.ts | 34 +++++++++++-------- .../browser/codeActionsContribution.ts | 6 +--- .../codeEditor/browser/saveParticipants.ts | 28 +++++++-------- 3 files changed, 34 insertions(+), 34 deletions(-) diff --git a/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts b/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts index 9f15b6ad6815f..c1fcdd40e67b0 100644 --- a/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts +++ b/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts @@ -3,26 +3,30 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { withAsyncTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor'; -import { StickyScrollController } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollController'; -import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; -import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; -import { createTextModel } from 'vs/editor/test/common/testTextModel'; -import { LanguageFeaturesService } from 'vs/editor/common/services/languageFeaturesService'; -import { DocumentSymbol, SymbolKind } from 'vs/editor/common/languages'; -import { StickyLineCandidate, StickyLineCandidateProvider } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollProvider'; -import { EditorOption } from 'vs/editor/common/config/editorOptions'; -import { ILogService, NullLogService } from 'vs/platform/log/common/log'; -import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; +import { DisposableStore } from 'vs/base/common/lifecycle'; import { mock } from 'vs/base/test/common/mock'; +import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler'; +import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; +import { DocumentSymbol, SymbolKind } from 'vs/editor/common/languages'; import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry'; import { ILanguageFeatureDebounceService, LanguageFeatureDebounceService } from 'vs/editor/common/services/languageFeatureDebounce'; +import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; +import { LanguageFeaturesService } from 'vs/editor/common/services/languageFeaturesService'; +import { StickyScrollController } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollController'; +import { StickyLineCandidate, StickyLineCandidateProvider } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollProvider'; +import { withAsyncTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor'; import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService'; -import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; -import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler'; +import { createTextModel } from 'vs/editor/test/common/testTextModel'; +import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; import { IEnvironmentService } from 'vs/platform/environment/common/environment'; -import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils'; -import { DisposableStore } from 'vs/base/common/lifecycle'; +import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; +import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; +import { ILogService, NullLogService } from 'vs/platform/log/common/log'; + + + + suite('Sticky Scroll Tests', () => { diff --git a/src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts b/src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts index 3d0bc4148f386..a773171df8ec0 100644 --- a/src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts +++ b/src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts @@ -52,11 +52,7 @@ const codeActionsOnSaveSchema: IConfigurationPropertySchema = { } ], markdownDescription: nls.localize('editor.codeActionsOnSave', 'Run CodeActions for the editor on save. CodeActions must be specified and the editor must not be shutting down. Example: `"source.organizeImports": "explicit" `'), - type: 'object', - additionalProperties: { - type: ['string', 'boolean'], - enum: ['always', 'explicit', 'never', true, false], - }, + type: ['object', 'array'], default: {}, scope: ConfigurationScope.LANGUAGE_OVERRIDABLE, }; diff --git a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts index d29cbedb13940..d684afb7a095d 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts @@ -281,7 +281,7 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant { const settingsOverrides = { overrideIdentifier: textEditorModel.getLanguageId(), resource: textEditorModel.uri }; // Convert boolean values to strings - const setting = this.configurationService.getValue<{ [kind: string]: string | boolean }>('editor.codeActionsOnSave', settingsOverrides); + const setting = this.configurationService.getValue<{ [kind: string]: string | boolean } | string[]>('editor.codeActionsOnSave', settingsOverrides); if (!setting) { return undefined; } @@ -290,16 +290,15 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant { return undefined; } - const convertedSetting: { [kind: string]: string } = {}; - for (const key in setting) { - if (typeof setting[key] === 'boolean') { - convertedSetting[key] = setting[key] ? 'explicit' : 'never'; - } else if (typeof setting[key] === 'string') { - convertedSetting[key] = setting[key] as string; - } + if (env.reason !== SaveReason.EXPLICIT && Array.isArray(setting)) { + return undefined; } - const codeActionsOnSave = this.createCodeActionsOnSave(Object.keys(convertedSetting)); + const settingItems: string[] = Array.isArray(setting) + ? setting + : Object.keys(setting).filter(x => setting[x]); + + const codeActionsOnSave = this.createCodeActionsOnSave(settingItems); if (!Array.isArray(setting)) { codeActionsOnSave.sort((a, b) => { @@ -319,14 +318,15 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant { if (!codeActionsOnSave.length) { return undefined; } - - const excludedActions = Object.keys(setting) - .filter(x => convertedSetting[x] === 'never' || false) - .map(x => new CodeActionKind(x)); + const excludedActions = Array.isArray(setting) + ? [] + : Object.keys(setting) + .filter(x => setting[x] === 'never' || false) + .map(x => new CodeActionKind(x)); progress.report({ message: localize('codeaction', "Quick Fixes") }); - const filteredSaveList = codeActionsOnSave.filter(x => convertedSetting[x.value] === 'always' || (convertedSetting[x.value] === 'explicit') && env.reason === SaveReason.EXPLICIT); + const filteredSaveList = Array.isArray(setting) ? codeActionsOnSave : codeActionsOnSave.filter(x => setting[x.value] === 'always' || ((setting[x.value] === 'explicit' || true) && env.reason === SaveReason.EXPLICIT)); await this.applyOnSaveActions(textEditorModel, filteredSaveList, excludedActions, progress, token); } From cc9f583b127bd19e83e01e06d33ff7a3d4a12bb5 Mon Sep 17 00:00:00 2001 From: Justin Chen <54879025+justschen@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:28:43 -0700 Subject: [PATCH 2/7] revert changes in non-important files --- .../test/browser/stickyScroll.test.ts | 31 +++++++++---------- 1 file changed, 15 insertions(+), 16 deletions(-) diff --git a/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts b/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts index c1fcdd40e67b0..722d72a7a416d 100644 --- a/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts +++ b/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts @@ -3,27 +3,26 @@ * Licensed under the MIT License. See License.txt in the project root for license information. *--------------------------------------------------------------------------------------------*/ import * as assert from 'assert'; -import { DisposableStore } from 'vs/base/common/lifecycle'; -import { mock } from 'vs/base/test/common/mock'; -import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler'; -import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils'; -import { EditorOption } from 'vs/editor/common/config/editorOptions'; -import { DocumentSymbol, SymbolKind } from 'vs/editor/common/languages'; -import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry'; -import { ILanguageFeatureDebounceService, LanguageFeatureDebounceService } from 'vs/editor/common/services/languageFeatureDebounce'; +import { withAsyncTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor'; +import { StickyScrollController } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollController'; +import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; import { ILanguageFeaturesService } from 'vs/editor/common/services/languageFeatures'; +import { createTextModel } from 'vs/editor/test/common/testTextModel'; import { LanguageFeaturesService } from 'vs/editor/common/services/languageFeaturesService'; -import { StickyScrollController } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollController'; +import { DocumentSymbol, SymbolKind } from 'vs/editor/common/languages'; import { StickyLineCandidate, StickyLineCandidateProvider } from 'vs/editor/contrib/stickyScroll/browser/stickyScrollProvider'; -import { withAsyncTestCodeEditor } from 'vs/editor/test/browser/testCodeEditor'; -import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService'; -import { createTextModel } from 'vs/editor/test/common/testTextModel'; +import { EditorOption } from 'vs/editor/common/config/editorOptions'; +import { ILogService, NullLogService } from 'vs/platform/log/common/log'; import { IContextMenuService } from 'vs/platform/contextview/browser/contextView'; -import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { mock } from 'vs/base/test/common/mock'; +import { ILanguageConfigurationService } from 'vs/editor/common/languages/languageConfigurationRegistry'; +import { ILanguageFeatureDebounceService, LanguageFeatureDebounceService } from 'vs/editor/common/services/languageFeatureDebounce'; +import { TestLanguageConfigurationService } from 'vs/editor/test/common/modes/testLanguageConfigurationService'; import { SyncDescriptor } from 'vs/platform/instantiation/common/descriptors'; -import { ServiceCollection } from 'vs/platform/instantiation/common/serviceCollection'; -import { ILogService, NullLogService } from 'vs/platform/log/common/log'; - +import { runWithFakedTimers } from 'vs/base/test/common/timeTravelScheduler'; +import { IEnvironmentService } from 'vs/platform/environment/common/environment'; +import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils'; +import { DisposableStore } from 'vs/base/common/lifecycle'; From 3b74fe5830b2f5d1602f97039167335c72464d44 Mon Sep 17 00:00:00 2001 From: Justin Chen <54879025+justschen@users.noreply.github.com> Date: Thu, 5 Oct 2023 12:29:08 -0700 Subject: [PATCH 3/7] code cleanup --- .../contrib/stickyScroll/test/browser/stickyScroll.test.ts | 3 --- 1 file changed, 3 deletions(-) diff --git a/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts b/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts index 722d72a7a416d..9f15b6ad6815f 100644 --- a/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts +++ b/src/vs/editor/contrib/stickyScroll/test/browser/stickyScroll.test.ts @@ -24,9 +24,6 @@ import { IEnvironmentService } from 'vs/platform/environment/common/environment' import { ensureNoDisposablesAreLeakedInTestSuite } from 'vs/base/test/common/utils'; import { DisposableStore } from 'vs/base/common/lifecycle'; - - - suite('Sticky Scroll Tests', () => { const disposables = new DisposableStore(); From 38f84bce20d235df72d9dac8c8599dc75fb06b6b Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 5 Oct 2023 13:17:35 -0700 Subject: [PATCH 4/7] adding back in for proper intellisense --- .../contrib/codeActions/browser/codeActionsContribution.ts | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts b/src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts index a773171df8ec0..46589b09e5edb 100644 --- a/src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts +++ b/src/vs/workbench/contrib/codeActions/browser/codeActionsContribution.ts @@ -53,6 +53,10 @@ const codeActionsOnSaveSchema: IConfigurationPropertySchema = { ], markdownDescription: nls.localize('editor.codeActionsOnSave', 'Run CodeActions for the editor on save. CodeActions must be specified and the editor must not be shutting down. Example: `"source.organizeImports": "explicit" `'), type: ['object', 'array'], + additionalProperties: { + type: ['string', 'boolean'], + enum: ['always', 'explicit', 'never', true, false], + }, default: {}, scope: ConfigurationScope.LANGUAGE_OVERRIDABLE, }; From ff53d8dfefd3021b7023e7520a91cb18b5fe5cb0 Mon Sep 17 00:00:00 2001 From: Your Name Date: Thu, 5 Oct 2023 14:43:12 -0700 Subject: [PATCH 5/7] added more specific logic check --- src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts index d684afb7a095d..6fda76096007c 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts @@ -326,7 +326,7 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant { progress.report({ message: localize('codeaction', "Quick Fixes") }); - const filteredSaveList = Array.isArray(setting) ? codeActionsOnSave : codeActionsOnSave.filter(x => setting[x.value] === 'always' || ((setting[x.value] === 'explicit' || true) && env.reason === SaveReason.EXPLICIT)); + const filteredSaveList = Array.isArray(setting) ? codeActionsOnSave : codeActionsOnSave.filter(x => setting[x.value] === 'always' || ((setting[x.value] === 'explicit' || setting[x.value] === true) && env.reason === SaveReason.EXPLICIT)); await this.applyOnSaveActions(textEditorModel, filteredSaveList, excludedActions, progress, token); } From d502fcbcee15027e6128c56ccc7f5e2537e3dd7a Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 6 Oct 2023 00:51:17 -0700 Subject: [PATCH 6/7] fixes contains issue: --- .../contrib/codeEditor/browser/saveParticipants.ts | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts index 6fda76096007c..e9fe95d5d44cc 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts @@ -294,9 +294,18 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant { return undefined; } + const convertedSetting: { [kind: string]: string | boolean } = {}; + if (!Array.isArray(setting)) { + for (const key in setting) { + if (setting[key] && setting[key] !== 'never') { + convertedSetting[key] = setting[key]; + } + } + } + const settingItems: string[] = Array.isArray(setting) ? setting - : Object.keys(setting).filter(x => setting[x]); + : Object.keys(convertedSetting); const codeActionsOnSave = this.createCodeActionsOnSave(settingItems); From 0701b3ed228e32a629b4042d633e20c24e1e09fd Mon Sep 17 00:00:00 2001 From: Your Name Date: Fri, 6 Oct 2023 01:16:17 -0700 Subject: [PATCH 7/7] added additional fix for overwritten duplicate subsets. reverting larger, less necessary code --- .../contrib/codeEditor/browser/saveParticipants.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts index e9fe95d5d44cc..eb6a5525362ee 100644 --- a/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts +++ b/src/vs/workbench/contrib/codeEditor/browser/saveParticipants.ts @@ -294,18 +294,9 @@ class CodeActionOnSaveParticipant implements ITextFileSaveParticipant { return undefined; } - const convertedSetting: { [kind: string]: string | boolean } = {}; - if (!Array.isArray(setting)) { - for (const key in setting) { - if (setting[key] && setting[key] !== 'never') { - convertedSetting[key] = setting[key]; - } - } - } - const settingItems: string[] = Array.isArray(setting) ? setting - : Object.keys(convertedSetting); + : Object.keys(setting).filter(x => setting[x] && setting[x] !== 'never'); const codeActionsOnSave = this.createCodeActionsOnSave(settingItems);