Skip to content

Commit d9a8238

Browse files
authored
Merge pull request #139 from zardoy/develop
2 parents d0b9de8 + d6d1ff4 commit d9a8238

16 files changed

+264
-135
lines changed

.vscode/settings.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,5 +11,8 @@
1111
],
1212
"githubPullRequests.ignoredPullRequestBranches": [
1313
"develop"
14+
],
15+
"cSpell.words": [
16+
"unpatch"
1417
]
1518
}

package.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,13 +55,13 @@
5555
"command": "copyFullType",
5656
"title": "Copy Full Type"
5757
},
58-
{
59-
"command": "pasteCodeWithImports",
60-
"title": "Paste Code with Imports"
61-
},
6258
{
6359
"command": "disableAllOptionalFeatures",
6460
"title": "Disable All Optional Features"
61+
},
62+
{
63+
"command": "replaceGlobalTypescriptWithLocalVersion",
64+
"title": "Replace Global Typescript with Local Version"
6565
}
6666
],
6767
"keybindings": [

pnpm-lock.yaml

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

src/configurationType.ts

Lines changed: 22 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ type ReplaceRule = {
1515
fileNamePattern?: string
1616
languageMode?: keyof typeof ScriptKind
1717
}
18-
/** by default only first entry is proccessed */
18+
/** by default only first entry is processed */
1919
processMany?: boolean
2020
delete?: boolean
2121
/**
@@ -25,7 +25,7 @@ type ReplaceRule = {
2525
patch?: Partial<{
2626
name: string
2727
kind: keyof typeof ScriptElementKind
28-
/** Might be useless when `correntSorting.enable` is true */
28+
/** Might be useless when `correctSorting.enable` is true */
2929
sortText: string
3030
insertText: string | true
3131
/** Wether insertText differs from completion name */
@@ -36,7 +36,7 @@ type ReplaceRule = {
3636
description?: string
3737
}
3838
}>
39-
/** Works only with `correntSorting.enable` set to true (default) */
39+
/** Works only with `correctSorting.enable` set to true (default) */
4040
// movePos?: number
4141
/** When specified, `movePos` is ignored */
4242
// TODO!
@@ -86,7 +86,7 @@ export type Configuration = {
8686
'patchToString.enable': boolean
8787
/**
8888
* Format of this setting is very close to `jsxCompletionsMap` setting:
89-
* `path#symbol` (exact) or `path/*#symbol` (`#symbol` part can be ommited)
89+
* `path#symbol` (exact) or `path/*#symbol` (`#symbol` part can be omitted)
9090
*
9191
* Note: Please use `javascript`/`typescript.preferences.autoImportFileExcludePatterns` when possible, to achieve better performance!
9292
*
@@ -127,7 +127,12 @@ export type Configuration = {
127127
* @default false
128128
*/
129129
'suggestions.localityBonus': boolean
130-
// TODO! corrent watching!
130+
/**
131+
* position = cursor position
132+
* @default prefer-before-position
133+
*/
134+
'suggestions.localityBonusMode': 'prefer-before-position' | 'nearest-to-position'
135+
// TODO! correct watching!
131136
/**
132137
* Wether to enable snippets for array methods like `items.map(item => )`
133138
* @default false
@@ -145,7 +150,7 @@ export type Configuration = {
145150
*/
146151
'arrayMethodsSnippets.addOuterTabStop': boolean
147152
/**
148-
* If set to `false` and singular item name can't be inffered, feature will be disabled
153+
* If set to `false` and singular item name can't be inferred, feature will be disabled
149154
* @default item
150155
*/
151156
'arrayMethodsSnippets.defaultItemName': string | false
@@ -275,12 +280,12 @@ export type Configuration = {
275280
*/
276281
'jsxPseudoEmmet.tags': { [tag: string]: true | string }
277282
/**
278-
* Exclude lowercase / incorrent suggestions
283+
* Exclude lowercase / incorrect suggestions
279284
* @default true
280285
*/
281286
'jsxImproveElementsSuggestions.enabled': boolean
282287
/**
283-
* Recommended to enable to experience less uneeded suggestions unless you are using JSX Elements declared in namespaces
288+
* Recommended to enable to experience less useless suggestions unless you are using JSX Elements declared in namespaces
284289
* @default false
285290
*/
286291
'jsxImproveElementsSuggestions.filterNamespaces': boolean
@@ -338,7 +343,7 @@ export type Configuration = {
338343
miscDefinitionImprovement: boolean
339344
// todo change setting format to: vue.*
340345
/**
341-
* Removes definiion suggestion from vue `components` options.
346+
* Removes definition suggestion from vue `components` options.
342347
* Might be useful with [Vetur-extended goToDefinition](https://github.com/zardoy/vetur-extended/blob/main/src/gotoDefinition.ts) for components as a replacement for (https://github.com/vuejs/language-tools/issues/1245)
343348
* @default false
344349
*/
@@ -431,7 +436,7 @@ export type Configuration = {
431436
*/
432437
'disableMethodSnippets.jsxAttributes': boolean
433438
/**
434-
* Support `@ts-diagnostic-disable` top-level comment for disabling spefici semantic diagnostics
439+
* Support `@ts-diagnostic-disable` top-level comment for disabling specific semantic diagnostics
435440
* Example: `// @ts-diagnostic-disable
436441
* Advanced usage only! Enable in `.vscode/settings.json` for projects that need this
437442
* Since its changes only IDE experience, but not tsc
@@ -465,15 +470,15 @@ export type Configuration = {
465470
*/
466471
switchExcludeCoveredCases: boolean
467472
/**
468-
* Make completions case-sensetive (see https://github.com/microsoft/TypeScript/issues/46622)
473+
* Make completions case-sensitive (see https://github.com/microsoft/TypeScript/issues/46622)
469474
* Might be enabled by default in future. Experimental as for now compares only start of completions.
470475
* Might require completion retrigger if was triggered by not quick suggestions.
471476
* @default false
472477
*/
473478
caseSensitiveCompletions: boolean
474479
/**
475480
* Might be useful to enable for a moment. Note, that you can bind shortcuts within VSCode to quickly toggle settings like this
476-
* Also experimental and wasnt tested in all cases
481+
* Also experimental and wasn't tested in all cases
477482
* Like described in `caseSensitiveCompletions` might require completion retrigger
478483
* @default false
479484
*/
@@ -482,6 +487,7 @@ export type Configuration = {
482487
* Disable useless highlighting,
483488
* @default disable
484489
*/
490+
// todo fix spelling
485491
disableUselessHighlighting: 'disable' | 'inJsxArttributeStrings' | 'inAllStrings'
486492
/**
487493
* Improve JSX attribute completions:
@@ -492,7 +498,7 @@ export type Configuration = {
492498
improveJsxCompletions: boolean
493499
/**
494500
* Replace JSX completions by map with `tagName#attribute` pattern as keys
495-
* `tagName` can be ommited, but not `attribute` for now
501+
* `tagName` can be omitted, but not `attribute` for now
496502
* Example usages:
497503
* - `#className`: `insertText: "={classNames$1}"`
498504
* - `button#type`: `insertText: "='button'"`
@@ -555,7 +561,7 @@ export type Configuration = {
555561
*/
556562
'experiments.excludeNonJsxCompletions': boolean
557563
/**
558-
* Wether to change funcntion completions to function kind
564+
* Wether to change function completions to function kind
559565
* @default false
560566
*/
561567
'experiments.changeKindToFunction': boolean
@@ -600,7 +606,7 @@ export type Configuration = {
600606
*/
601607
useDefaultImport?: boolean
602608
/**
603-
* Set to `false` if module is acessible from global variable
609+
* Set to `false` if the module is accessible from the global variable
604610
* For now not supported in add all missing imports code action
605611
* @default true */
606612
addImport?: boolean
@@ -632,7 +638,7 @@ export type Configuration = {
632638
}
633639
}
634640

635-
// scrapped using search editor. config: caseInsesetive, context lines: 0, regex: const fix\w+ = "[^ ]+"
641+
// scrapped using search editor. config: caseInsensitive, context lines: 0, regex: const fix\w+ = "[^ ]+"
636642
type FixId =
637643
| 'addConvertToUnknownForNonOverlappingTypes'
638644
| 'addMissingAsync'

src/extension.ts

Lines changed: 2 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import vueVolarSupport from './vueVolarSupport'
1717
import moreCompletions from './moreCompletions'
1818
import { mergeSettingsFromScopes } from './mergeSettings'
1919
import codeActionProvider from './codeActionProvider'
20+
import nonTsCommands from './nonTsCommands'
2021

2122
let isActivated = false
2223
// let erroredStatusBarItem: vscode.StatusBarItem | undefined
@@ -91,7 +92,7 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted
9192
}
9293

9394
export const activate = async () => {
94-
registerDisableOptionalFeaturesCommand()
95+
nonTsCommands()
9596
migrateSettings()
9697

9798
const possiblyActivateTsPlugin = async () => {
@@ -140,55 +141,3 @@ export const activate = async () => {
140141
})
141142
}
142143
}
143-
144-
const registerDisableOptionalFeaturesCommand = () => {
145-
registerExtensionCommand('disableAllOptionalFeatures', async () => {
146-
const config = vscode.workspace.getConfiguration(process.env.IDS_PREFIX, null)
147-
const toDisable: Array<[keyof Settings, any]> = []
148-
for (const optionalExperience of optionalExperiences) {
149-
const desiredKey = Array.isArray(optionalExperience) ? optionalExperience[0] : optionalExperience
150-
const desiredValue = Array.isArray(optionalExperience) ? optionalExperience[1] : false
151-
if (config.get(desiredKey) !== desiredValue) toDisable.push([desiredKey, desiredValue])
152-
}
153-
154-
const action = await vscode.window.showInformationMessage(
155-
`${toDisable.length} features are going to be disabled`,
156-
{ detail: '', modal: true },
157-
'Write to settings NOW',
158-
'Copy settings',
159-
)
160-
if (!action) return
161-
switch (action) {
162-
case 'Write to settings NOW': {
163-
for (const [key, value] of toDisable) {
164-
void config.update(key, value, vscode.ConfigurationTarget.Global)
165-
}
166-
167-
break
168-
}
169-
170-
case 'Copy settings': {
171-
await vscode.env.clipboard.writeText(JSON.stringify(Object.fromEntries(toDisable), undefined, 4))
172-
break
173-
}
174-
}
175-
})
176-
}
177-
178-
/** Experiences that are enabled out of the box */
179-
const optionalExperiences: Array<keyof ConditionalPick<Settings, boolean> | [keyof Settings, any]> = [
180-
'enableMethodSnippets',
181-
'removeUselessFunctionProps.enable',
182-
'patchToString.enable',
183-
['suggestions.keywordsInsertText', 'none'],
184-
'highlightNonFunctionMethods.enable',
185-
'markTsCodeActions.enable',
186-
['markTsCodeFixes.character', ''],
187-
'removeCodeFixes.enable',
188-
'removeDefinitionFromReferences',
189-
'removeImportsFromReferences',
190-
'miscDefinitionImprovement',
191-
'improveJsxCompletions',
192-
'objectLiteralCompletions.moreVariants',
193-
'codeActions.extractTypeInferName',
194-
]

src/nonTsCommands.ts

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
import * as vscode from 'vscode'
2+
import { ConditionalPick } from 'type-fest'
3+
import { registerExtensionCommand, Settings } from 'vscode-framework'
4+
import { getCurrentWorkspaceRoot } from '@zardoy/vscode-utils/build/fs'
5+
import { Utils } from 'vscode-uri'
6+
import { showQuickPick } from '@zardoy/vscode-utils/build/quickPick'
7+
8+
// these commands doesn't require TS to be available
9+
10+
export default () => {
11+
registerExtensionCommand('disableAllOptionalFeatures', async () => {
12+
const config = vscode.workspace.getConfiguration(process.env.IDS_PREFIX, null)
13+
const toDisable: Array<[keyof Settings, any]> = []
14+
for (const optionalExperience of optionalExperiences) {
15+
const desiredKey = Array.isArray(optionalExperience) ? optionalExperience[0] : optionalExperience
16+
const desiredValue = Array.isArray(optionalExperience) ? optionalExperience[1] : false
17+
if (config.get(desiredKey) !== desiredValue) toDisable.push([desiredKey, desiredValue])
18+
}
19+
20+
const action = await vscode.window.showInformationMessage(
21+
`${toDisable.length} features are going to be disabled`,
22+
{ detail: '', modal: true },
23+
'Write to settings NOW',
24+
'Copy settings',
25+
)
26+
if (!action) return
27+
switch (action) {
28+
case 'Write to settings NOW': {
29+
for (const [key, value] of toDisable) {
30+
void config.update(key, value, vscode.ConfigurationTarget.Global)
31+
}
32+
33+
break
34+
}
35+
36+
case 'Copy settings': {
37+
await vscode.env.clipboard.writeText(JSON.stringify(Object.fromEntries(toDisable), undefined, 4))
38+
break
39+
}
40+
}
41+
})
42+
43+
registerExtensionCommand('replaceGlobalTypescriptWithLocalVersion', async () => {
44+
const root = getCurrentWorkspaceRoot()
45+
const localTypeScript = Utils.joinPath(root.uri, 'node_modules/typescript')
46+
const globalTypeScript = Utils.joinPath(vscode.Uri.file(vscode.env.appRoot), 'extensions/node_modules/typescript')
47+
const { version: localVersion } = await vscode.workspace.fs
48+
.readFile(Utils.joinPath(localTypeScript, 'package.json'))
49+
.then(result => JSON.parse(result.toString()))
50+
const { version: globalVersion } = await vscode.workspace.fs
51+
.readFile(Utils.joinPath(globalTypeScript, 'package.json'))
52+
.then(result => JSON.parse(result.toString()))
53+
const result = await showQuickPick([`Replace global TS ${globalVersion} with local ${localVersion}`].map(x => ({ value: x, label: x })))
54+
if (!result) return
55+
const paths = ['package.json', 'lib']
56+
for (const path of paths) {
57+
// eslint-disable-next-line no-await-in-loop
58+
await vscode.workspace.fs.copy(Utils.joinPath(localTypeScript, path), Utils.joinPath(globalTypeScript, path), { overwrite: true })
59+
}
60+
})
61+
}
62+
63+
/** Experiences that are enabled out of the box */
64+
const optionalExperiences: Array<keyof ConditionalPick<Settings, boolean> | [keyof Settings, any]> = [
65+
'enableMethodSnippets',
66+
'removeUselessFunctionProps.enable',
67+
'patchToString.enable',
68+
['suggestions.keywordsInsertText', 'none'],
69+
'highlightNonFunctionMethods.enable',
70+
'markTsCodeActions.enable',
71+
['markTsCodeFixes.character', ''],
72+
'removeCodeFixes.enable',
73+
'removeDefinitionFromReferences',
74+
'removeImportsFromReferences',
75+
'miscDefinitionImprovement',
76+
'improveJsxCompletions',
77+
'objectLiteralCompletions.moreVariants',
78+
'codeActions.extractTypeInferName',
79+
]

src/specialCommands.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,9 +289,9 @@ export default () => {
289289
await vscode.env.clipboard.writeText(text)
290290
})
291291

292-
registerExtensionCommand('pasteCodeWithImports', async () => {
293-
const clipboard = await vscode.env.clipboard.readText()
294-
const lines = clipboard.split('\n')
295-
const lastImportLineIndex = lines.findIndex(line => line !== 'import')
296-
})
292+
// registerExtensionCommand('pasteCodeWithImports', async () => {
293+
// const clipboard = await vscode.env.clipboard.readText()
294+
// const lines = clipboard.split('\n')
295+
// const lastImportLineIndex = lines.findIndex(line => line !== 'import')
296+
// })
297297
}

0 commit comments

Comments
 (0)