Skip to content

Commit 9987a2b

Browse files
authored
fix: fix changelog of previous release :sad: (#76)
2 parents cf58c6d + 8465f45 commit 9987a2b

24 files changed

+868
-123
lines changed

README.MD

Lines changed: 69 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,11 @@
22

33
## Top Features
44

5-
### Special Commands
5+
> Here React experience hits different!
66
7-
See [special commands list](#special-commands-list)
7+
### Special Commands & Actions
8+
9+
See [special commands list](#special-commands-list) ans [code actions list](#contributed-code-actions)
810

911
### JSX Outline
1012

@@ -62,12 +64,24 @@ const usersList = []
6264
usersList.map // -> usersList.map((user) => )
6365
```
6466

67+
### Case-sensitive Completions
68+
69+
(*disabled by default*)
70+
71+
Filter out completions that start with different casing.
72+
6573
### Remove Definition From References
6674

6775
(*enabled by default*)
6876

6977
<https://github.com/microsoft/vscode/issues/160637>
7078

79+
### Remove Imports From References
80+
81+
(*enabled by default*)
82+
83+
Removes import statements from references when symbol has usages in the same file. Why? Because if export thing is used in another file, it might be obvious that it is imported, and most probably you are not interested in import statements.
84+
7185
## Minor Useful Features
7286

7387
### `enablePlugin` setting
@@ -154,6 +168,59 @@ type A<T extends 'foo' | 'bar' = ''> = ...
154168
155169
Use cases: search excluding comments, search & replace only within strings, find interested JSX attribute node
156170
171+
## Contributed Code Actions
172+
173+
### Swap Keys and Values in Object
174+
175+
> *Note*: Code action displayed **only** when object is fully explicitly selected
176+
177+
Example:
178+
179+
```ts
180+
const obj = {
181+
key1: 'someValue',
182+
key2: getSuperUniqueKey()
183+
}
184+
// turns into
185+
const obj = {
186+
'someValue': 'key1',
187+
[getSuperUniqueKey()]: 'key2'
188+
}
189+
```
190+
191+
### Turn Array Into Object
192+
193+
```ts
194+
const data = [
195+
{
196+
// test
197+
key: 'bar',
198+
a: 0
199+
},
200+
{
201+
key: 'baz',
202+
// yes
203+
b: 1
204+
}
205+
]
206+
```
207+
208+
After selecting code action, you'll get asked for key to used (here you can use only `key`) and after applying:
209+
210+
```ts
211+
const a = {
212+
'bar': {
213+
a: 0
214+
},
215+
'baz': {
216+
// yes
217+
b: 1
218+
}
219+
}
220+
```
221+
222+
(note that for now refactoring removes properties with comments!)
223+
157224
## Even Even More
158225

159226
Please look at extension settings, as this extension has much more features than described here!

buildTsPlugin.mjs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ import { analyzeMetafile } from 'esbuild'
55
const result = await buildTsPlugin('typescript', undefined, undefined, {
66
minify: !process.argv.includes('--watch'),
77
metafile: true,
8+
define: {
9+
'import.meta': '{}',
10+
},
811
banner: {
912
js: 'let ts, tsFull;',
1013
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))',

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@
135135
"lodash.throttle": "^4.1.1",
136136
"mocha": "^10.0.0",
137137
"modify-json-file": "^1.2.2",
138+
"path-browserify": "^1.0.1",
138139
"pluralize": "github:plurals/pluralize#36f03cd2d573fa6d23e12e1529fa4627e2af74b4",
139140
"rambda": "^7.2.1",
140141
"require-from-string": "^2.0.2",

pnpm-lock.yaml

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/configurationType.ts

Lines changed: 55 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,23 @@ export type Configuration = {
4444
* @default true
4545
* */
4646
'removeUselessFunctionProps.enable': boolean
47+
/**
48+
* @default disable
49+
*/
50+
'removeOrMarkGlobalCompletions.action': 'disable' | 'mark' | 'remove'
4751
/**
4852
* Useful for Number types.
4953
* Patch `toString()`: Removes arg tabstop
5054
* @default true
5155
*/
5256
'patchToString.enable': boolean
53-
// TODO achieve perfomace by patching the host
54-
/** @default [] */
57+
/**
58+
* Note: Please use `javascript`/`typescript.preferences.autoImportFileExcludePatterns` when possible, to achieve better performance!
59+
* e.g. instead of declaring `@mui/icons-material` here, declare `node_modules/@mui/icons-material` in aforementioned setting.
60+
*
61+
* And only use this, if auto-imports coming not from physical files (e.g. some modules node imports)
62+
* @default []
63+
*/
5564
'suggestions.banAutoImportPackages': string[]
5665
/**
5766
* What insert text to use for keywords (e.g. `return`)
@@ -114,6 +123,19 @@ export type Configuration = {
114123
* @default true
115124
* */
116125
// 'importUpDefinition.enable': boolean
126+
/**
127+
* Remove definitions for TS module declarations e.g. *.css
128+
* Enable it if your first definition that receives focus is TS module declaration instead of target file itself
129+
* Might be really really useful in some cases
130+
* @default false
131+
*/
132+
removeModuleFileDefinitions: boolean
133+
/**
134+
* Enable definitions for strings that appears to be paths (relatively to file)
135+
* Also must have and should be enabled if you work with path.join a lot
136+
* @default false
137+
*/
138+
enableFileDefinitions: boolean
117139
/**
118140
* @default true
119141
* */
@@ -156,6 +178,11 @@ export type Configuration = {
156178
* @default true
157179
*/
158180
'jsxImproveElementsSuggestions.enabled': boolean
181+
/**
182+
* Recommended to enable to experience less uneeded suggestions unless you are using JSX Elements declared in namespaces
183+
* @default false
184+
*/
185+
'jsxImproveElementsSuggestions.filterNamespaces': boolean
159186
/**
160187
* @default false
161188
*/
@@ -193,6 +220,10 @@ export type Configuration = {
193220
* @default true
194221
*/
195222
removeDefinitionFromReferences: boolean
223+
/**
224+
* @default true
225+
*/
226+
removeImportsFromReferences: boolean
196227
/**
197228
* Small definition improvements by cleaning them out:
198229
* - remove node_modules definition on React.FC component click
@@ -214,7 +245,6 @@ export type Configuration = {
214245
* Wether to disable our and builtin method snippets within jsx attributes
215246
* @default true
216247
*/
217-
// TODO add smart setting
218248
'disableMethodSnippets.jsxAttributes': boolean
219249
/**
220250
* Support `@ts-diagnostic-disable` top-level comment for disabling spefici semantic diagnostics
@@ -240,10 +270,24 @@ export type Configuration = {
240270
*/
241271
patchOutline: boolean
242272
/**
243-
* Exclude covered strings/enum cases in switch
273+
* Exclude covered strings/enum cases in switch in completions
244274
* @default true
245275
*/
246276
switchExcludeCoveredCases: boolean
277+
/**
278+
* Make completions case-sensetive (see https://github.com/microsoft/TypeScript/issues/46622)
279+
* Might be enabled by default in future. Experimental as for now compares only start of completions.
280+
* Might require completion retrigger if was triggered by not quick suggestions.
281+
* @default false
282+
*/
283+
caseSensitiveCompletions: boolean
284+
/**
285+
* Might be useful to enable for a moment. Note, that you can bind shortcuts within VSCode to quickly toggle settings like this
286+
* Also experimental and wasnt tested in all cases
287+
* Like described in `caseSensitiveCompletions` might require completion retrigger
288+
* @default false
289+
*/
290+
disableFuzzyCompletions: boolean
247291
/**
248292
* Disable useless highlighting,
249293
* @default disable
@@ -312,5 +356,12 @@ export type Configuration = {
312356
* Also affects builtin typescript.suggest.objectLiteralMethodSnippets, even when additional completions disabled
313357
* @default below
314358
*/
359+
// TODO its a bug, change to after & before with fixed behavior
315360
'objectLiteralCompletions.keepOriginal': 'below' | 'above' | 'remove'
361+
/**
362+
* Wether to exclude non-JSX components completions in JSX component locations
363+
* Requires `completion-symbol` patch
364+
* @default false
365+
*/
366+
'experiments.excludeNonJsxCompletions': boolean
316367
}

src/sendCommand.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@ import { getActiveRegularEditor } from '@zardoy/vscode-utils'
33
import { getExtensionSetting } from 'vscode-framework'
44
import { TriggerCharacterCommand } from '../typescript/src/ipcTypes'
55

6-
type SendCommandData = {
6+
type SendCommandData<K> = {
77
position: vscode.Position
88
document: vscode.TextDocument
9-
inputOptions?: any
9+
inputOptions?: K
1010
}
11-
export const sendCommand = async <T>(command: TriggerCharacterCommand, sendCommandDataArg?: SendCommandData): Promise<T | undefined> => {
11+
export const sendCommand = async <T, K = any>(command: TriggerCharacterCommand, sendCommandDataArg?: SendCommandData<K>): Promise<T | undefined> => {
1212
// plugin id disabled, languageService would not understand the special trigger character
1313
if (!getExtensionSetting('enablePlugin')) return
1414

@@ -19,7 +19,7 @@ export const sendCommand = async <T>(command: TriggerCharacterCommand, sendComma
1919
const {
2020
document: { uri },
2121
position,
22-
} = ((): SendCommandData => {
22+
} = ((): SendCommandData<any> => {
2323
if (sendCommandDataArg) return sendCommandDataArg
2424
const editor = getActiveRegularEditor()!
2525
return {

src/specialCommands.ts

Lines changed: 84 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
import * as vscode from 'vscode'
2-
import { getActiveRegularEditor, rangeToSelection } from '@zardoy/vscode-utils'
3-
import { getExtensionCommandId, registerExtensionCommand, VSCodeQuickPickItem } from 'vscode-framework'
2+
import { getActiveRegularEditor } from '@zardoy/vscode-utils'
3+
import { getExtensionCommandId, getExtensionSetting, registerExtensionCommand, VSCodeQuickPickItem } from 'vscode-framework'
44
import { showQuickPick } from '@zardoy/vscode-utils/build/quickPick'
55
import _ from 'lodash'
66
import { compact } from '@zardoy/utils'
7+
import { defaultJsSupersetLangsWithVue } from '@zardoy/vscode-utils/build/langs'
8+
import { offsetPosition } from '@zardoy/vscode-utils/build/position'
79
import { RequestOptionsTypes, RequestResponseTypes } from '../typescript/src/ipcTypes'
810
import { sendCommand } from './sendCommand'
911
import { tsRangeToVscode, tsRangeToVscodeSelection } from './util'
@@ -13,12 +15,15 @@ export default () => {
1315
const editor = getActiveRegularEditor()
1416
if (!editor) return
1517
const { selection, document } = editor
16-
const response = await sendCommand<RequestResponseTypes['removeFunctionArgumentsTypesInSelection']>('removeFunctionArgumentsTypesInSelection', {
18+
const response = await sendCommand<
19+
RequestResponseTypes['removeFunctionArgumentsTypesInSelection'],
20+
RequestOptionsTypes['removeFunctionArgumentsTypesInSelection']
21+
>('removeFunctionArgumentsTypesInSelection', {
1722
document,
1823
position: selection.start,
1924
inputOptions: {
2025
endSelection: document.offsetAt(selection.end),
21-
} as RequestOptionsTypes['removeFunctionArgumentsTypesInSelection'],
26+
},
2227
})
2328
if (!response) return
2429
const { ranges } = response
@@ -215,4 +220,79 @@ export default () => {
215220
registerExtensionCommand('goToNodeBySyntaxKindWithinSelection', async () => {
216221
await vscode.commands.executeCommand(getExtensionCommandId('goToNodeBySyntaxKind'), { filterWithSelection: true })
217222
})
223+
224+
async function sendTurnIntoArrayRequest<T = RequestResponseTypes['turnArrayIntoObject']>(
225+
range: vscode.Range,
226+
selectedKeyName?: string,
227+
document = vscode.window.activeTextEditor!.document,
228+
) {
229+
return sendCommand<T, RequestOptionsTypes['turnArrayIntoObject']>('turnArrayIntoObject', {
230+
document,
231+
position: range.start,
232+
inputOptions: {
233+
range: [document.offsetAt(range.start), document.offsetAt(range.end)] as [number, number],
234+
selectedKeyName,
235+
},
236+
})
237+
}
238+
239+
registerExtensionCommand('turnArrayIntoObjectRefactoring' as any, async (_, arg?: RequestResponseTypes['turnArrayIntoObject']) => {
240+
if (!arg) return
241+
const { keysCount, totalCount, totalObjectCount } = arg
242+
const selectedKey: string | false | undefined =
243+
// eslint-disable-next-line @typescript-eslint/dot-notation
244+
arg['key'] ||
245+
(await showQuickPick(
246+
Object.entries(keysCount).map(([key, count]) => {
247+
const isAllowed = count === totalObjectCount
248+
return { label: `${isAllowed ? '$(check)' : '$(close)'}${key}`, value: isAllowed ? key : false, description: `${count} hits` }
249+
}),
250+
{
251+
title: `Selected available key from ${totalObjectCount} objects (${totalCount} elements)`,
252+
},
253+
))
254+
if (selectedKey === undefined || selectedKey === '') return
255+
if (selectedKey === false) {
256+
void vscode.window.showWarningMessage("Can't use selected key as its not used in every object")
257+
return
258+
}
259+
260+
const editor = vscode.window.activeTextEditor!
261+
const edits = await sendTurnIntoArrayRequest<RequestResponseTypes['turnArrayIntoObjectEdit']>(editor.selection, selectedKey)
262+
if (!edits) throw new Error('Unknown error. Try debug.')
263+
await editor.edit(builder => {
264+
for (const { span, newText } of edits) {
265+
const start = editor.document.positionAt(span.start)
266+
builder.replace(new vscode.Range(start, offsetPosition(editor.document, start, span.length)), newText)
267+
}
268+
})
269+
})
270+
271+
// its actually a code action, but will be removed from there soon
272+
vscode.languages.registerCodeActionsProvider(defaultJsSupersetLangsWithVue, {
273+
async provideCodeActions(document, range, context, token) {
274+
if (
275+
context.triggerKind !== vscode.CodeActionTriggerKind.Invoke ||
276+
document !== vscode.window.activeTextEditor?.document ||
277+
!getExtensionSetting('enablePlugin')
278+
)
279+
return
280+
const result = await sendTurnIntoArrayRequest(range)
281+
if (!result) return
282+
const { keysCount, totalCount, totalObjectCount } = result
283+
return [
284+
{
285+
title: `Turn Array Into Object (${totalCount} elements)`,
286+
command: getExtensionCommandId('turnArrayIntoObjectRefactoring' as any),
287+
arguments: [
288+
{
289+
keysCount,
290+
totalCount,
291+
totalObjectCount,
292+
} satisfies RequestResponseTypes['turnArrayIntoObject'],
293+
],
294+
},
295+
]
296+
},
297+
})
218298
}

0 commit comments

Comments
 (0)