Skip to content

Commit cf58c6d

Browse files
authored
Revert latest accidential merge (#75)
1 parent e7c5108 commit cf58c6d

24 files changed

+123
-868
lines changed

README.MD

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

33
## Top Features
44

5-
> Here React experience hits different!
5+
### Special Commands
66

7-
### Special Commands & Actions
8-
9-
See [special commands list](#special-commands-list) ans [code actions list](#contributed-code-actions)
7+
See [special commands list](#special-commands-list)
108

119
### JSX Outline
1210

@@ -64,24 +62,12 @@ const usersList = []
6462
usersList.map // -> usersList.map((user) => )
6563
```
6664

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

7567
(*enabled by default*)
7668

7769
<https://github.com/microsoft/vscode/issues/160637>
7870

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-
8571
## Minor Useful Features
8672

8773
### `enablePlugin` setting
@@ -168,59 +154,6 @@ type A<T extends 'foo' | 'bar' = ''> = ...
168154
169155
Use cases: search excluding comments, search & replace only within strings, find interested JSX attribute node
170156
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-
224157
## Even Even More
225158
226159
Please look at extension settings, as this extension has much more features than described here!

buildTsPlugin.mjs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,6 @@ 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-
},
118
banner: {
129
js: 'let ts, tsFull;',
1310
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))',

package.json

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

pnpm-lock.yaml

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

src/configurationType.ts

Lines changed: 4 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -44,23 +44,14 @@ export type Configuration = {
4444
* @default true
4545
* */
4646
'removeUselessFunctionProps.enable': boolean
47-
/**
48-
* @default disable
49-
*/
50-
'removeOrMarkGlobalCompletions.action': 'disable' | 'mark' | 'remove'
5147
/**
5248
* Useful for Number types.
5349
* Patch `toString()`: Removes arg tabstop
5450
* @default true
5551
*/
5652
'patchToString.enable': boolean
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-
*/
53+
// TODO achieve perfomace by patching the host
54+
/** @default [] */
6455
'suggestions.banAutoImportPackages': string[]
6556
/**
6657
* What insert text to use for keywords (e.g. `return`)
@@ -123,19 +114,6 @@ export type Configuration = {
123114
* @default true
124115
* */
125116
// '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
139117
/**
140118
* @default true
141119
* */
@@ -178,11 +156,6 @@ export type Configuration = {
178156
* @default true
179157
*/
180158
'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
186159
/**
187160
* @default false
188161
*/
@@ -220,10 +193,6 @@ export type Configuration = {
220193
* @default true
221194
*/
222195
removeDefinitionFromReferences: boolean
223-
/**
224-
* @default true
225-
*/
226-
removeImportsFromReferences: boolean
227196
/**
228197
* Small definition improvements by cleaning them out:
229198
* - remove node_modules definition on React.FC component click
@@ -245,6 +214,7 @@ export type Configuration = {
245214
* Wether to disable our and builtin method snippets within jsx attributes
246215
* @default true
247216
*/
217+
// TODO add smart setting
248218
'disableMethodSnippets.jsxAttributes': boolean
249219
/**
250220
* Support `@ts-diagnostic-disable` top-level comment for disabling spefici semantic diagnostics
@@ -270,24 +240,10 @@ export type Configuration = {
270240
*/
271241
patchOutline: boolean
272242
/**
273-
* Exclude covered strings/enum cases in switch in completions
243+
* Exclude covered strings/enum cases in switch
274244
* @default true
275245
*/
276246
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
291247
/**
292248
* Disable useless highlighting,
293249
* @default disable
@@ -356,12 +312,5 @@ export type Configuration = {
356312
* Also affects builtin typescript.suggest.objectLiteralMethodSnippets, even when additional completions disabled
357313
* @default below
358314
*/
359-
// TODO its a bug, change to after & before with fixed behavior
360315
'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
367316
}

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<K> = {
6+
type SendCommandData = {
77
position: vscode.Position
88
document: vscode.TextDocument
9-
inputOptions?: K
9+
inputOptions?: any
1010
}
11-
export const sendCommand = async <T, K = any>(command: TriggerCharacterCommand, sendCommandDataArg?: SendCommandData<K>): Promise<T | undefined> => {
11+
export const sendCommand = async <T>(command: TriggerCharacterCommand, sendCommandDataArg?: SendCommandData): 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, K = any>(command: TriggerCharacterCommand,
1919
const {
2020
document: { uri },
2121
position,
22-
} = ((): SendCommandData<any> => {
22+
} = ((): SendCommandData => {
2323
if (sendCommandDataArg) return sendCommandDataArg
2424
const editor = getActiveRegularEditor()!
2525
return {

src/specialCommands.ts

Lines changed: 4 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import * as vscode from 'vscode'
2-
import { getActiveRegularEditor } from '@zardoy/vscode-utils'
3-
import { getExtensionCommandId, getExtensionSetting, registerExtensionCommand, VSCodeQuickPickItem } from 'vscode-framework'
2+
import { getActiveRegularEditor, rangeToSelection } from '@zardoy/vscode-utils'
3+
import { getExtensionCommandId, 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'
97
import { RequestOptionsTypes, RequestResponseTypes } from '../typescript/src/ipcTypes'
108
import { sendCommand } from './sendCommand'
119
import { tsRangeToVscode, tsRangeToVscodeSelection } from './util'
@@ -15,15 +13,12 @@ export default () => {
1513
const editor = getActiveRegularEditor()
1614
if (!editor) return
1715
const { selection, document } = editor
18-
const response = await sendCommand<
19-
RequestResponseTypes['removeFunctionArgumentsTypesInSelection'],
20-
RequestOptionsTypes['removeFunctionArgumentsTypesInSelection']
21-
>('removeFunctionArgumentsTypesInSelection', {
16+
const response = await sendCommand<RequestResponseTypes['removeFunctionArgumentsTypesInSelection']>('removeFunctionArgumentsTypesInSelection', {
2217
document,
2318
position: selection.start,
2419
inputOptions: {
2520
endSelection: document.offsetAt(selection.end),
26-
},
21+
} as RequestOptionsTypes['removeFunctionArgumentsTypesInSelection'],
2722
})
2823
if (!response) return
2924
const { ranges } = response
@@ -220,79 +215,4 @@ export default () => {
220215
registerExtensionCommand('goToNodeBySyntaxKindWithinSelection', async () => {
221216
await vscode.commands.executeCommand(getExtensionCommandId('goToNodeBySyntaxKind'), { filterWithSelection: true })
222217
})
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-
})
298218
}

0 commit comments

Comments
 (0)