Skip to content

Commit f89250c

Browse files
committed
fix: fix meanings of values for objectLiteralCompletions.keepOriginal (no user action required)
1 parent 9312b04 commit f89250c

File tree

3 files changed

+35
-6
lines changed

3 files changed

+35
-6
lines changed

src/configurationType.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -498,11 +498,11 @@ export type Configuration = {
498498
*/
499499
// 'objectLiteralCompletions.deepVariants': 'disable' | 'displayBelow' | 'replaceNotDeep'
500500
/**
501-
* Also affects builtin typescript.suggest.objectLiteralMethodSnippets, even when additional completions disabled
502-
* @default below
501+
* How to position original suggestion relative to snippet suggestion.
502+
* Also affects builtin typescript.suggest.objectLiteralMethodSnippets, even when additional plugin completions disabled
503+
* @default before
503504
*/
504-
// TODO its a bug, change to after & before with fixed behavior
505-
'objectLiteralCompletions.keepOriginal': 'below' | 'above' | 'remove'
505+
'objectLiteralCompletions.keepOriginal': 'before' | 'after' | 'remove'
506506
/**
507507
* Wether to exclude non-JSX components completions in JSX component locations
508508
* Requires TypeScript 5.0+

src/migrateSettings.ts

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
1+
import * as vscode from 'vscode'
12
import { migrateExtensionSettings } from '@zardoy/vscode-utils/build/migrateSettings'
3+
import { Settings } from 'vscode-framework'
24

35
export default () => {
46
void migrateExtensionSettings(
@@ -31,7 +33,34 @@ export default () => {
3133
mustBePrimitive: false,
3234
},
3335
},
36+
{
37+
async detect(configuration) {
38+
return !!(await migrateSettingValues(configuration, true))
39+
},
40+
async handle(configuration) {
41+
return (await migrateSettingValues(configuration, false))!
42+
},
43+
},
3444
],
3545
process.env.IDS_PREFIX!,
3646
)
3747
}
48+
49+
async function migrateSettingValues(configuration: vscode.WorkspaceConfiguration, detectOnly: boolean) {
50+
const keepOriginalSettingKey: keyof Settings = 'objectLiteralCompletions.keepOriginal'
51+
const keepOriginal = configuration.get<string>(keepOriginalSettingKey)!
52+
const keepOriginalNewValuesMap = {
53+
below: 'before',
54+
above: 'after',
55+
}
56+
const newKeepOriginalValue = keepOriginalNewValuesMap[keepOriginal]
57+
if (newKeepOriginalValue) {
58+
if (!detectOnly) {
59+
await configuration.update(keepOriginalSettingKey, newKeepOriginalValue, vscode.ConfigurationTarget.Global)
60+
}
61+
62+
return keepOriginalSettingKey
63+
}
64+
65+
return undefined
66+
}

typescript/src/completions/objectLiteralCompletions.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ export default (
3232
const methodEntry = entries[methodEntryIndex]
3333
if (methodEntry) {
3434
entries.splice(methodEntryIndex, 1)
35-
entries.splice(entries.indexOf(entry) + (keepOriginal === 'below' ? 1 : 0), keepOriginal === 'remove' ? 1 : 0, {
35+
entries.splice(entries.indexOf(entry) + (keepOriginal === 'before' ? 1 : 0), keepOriginal === 'remove' ? 1 : 0, {
3636
...methodEntry,
3737
// let correctSorting.enable sort it
3838
sortText: entry.sortText,
@@ -59,7 +59,7 @@ export default (
5959
const [insertSnippetText, insertSnippetPreview] = typeof insertSnippetVariant === 'function' ? insertSnippetVariant() : insertSnippetVariant
6060
const insertText = entry.name + insertSnippetText
6161
const index = entries.indexOf(entry)
62-
entries.splice(index + (keepOriginal === 'below' ? 1 : 0), keepOriginal === 'remove' ? 1 : 0, {
62+
entries.splice(index + (keepOriginal === 'before' ? 1 : 0), keepOriginal === 'remove' ? 1 : 0, {
6363
...entry,
6464
// todo setting incompatible!!!
6565
sortText: entry.sortText,

0 commit comments

Comments
 (0)