Skip to content

Commit

Permalink
Merge pull request #139 from zardoy/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Jul 4, 2023
2 parents d0b9de8 + d6d1ff4 commit d9a8238
Show file tree
Hide file tree
Showing 16 changed files with 264 additions and 135 deletions.
3 changes: 3 additions & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,8 @@
],
"githubPullRequests.ignoredPullRequestBranches": [
"develop"
],
"cSpell.words": [
"unpatch"
]
}
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@
"command": "copyFullType",
"title": "Copy Full Type"
},
{
"command": "pasteCodeWithImports",
"title": "Paste Code with Imports"
},
{
"command": "disableAllOptionalFeatures",
"title": "Disable All Optional Features"
},
{
"command": "replaceGlobalTypescriptWithLocalVersion",
"title": "Replace Global Typescript with Local Version"
}
],
"keybindings": [
Expand Down
10 changes: 5 additions & 5 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

38 changes: 22 additions & 16 deletions src/configurationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ type ReplaceRule = {
fileNamePattern?: string
languageMode?: keyof typeof ScriptKind
}
/** by default only first entry is proccessed */
/** by default only first entry is processed */
processMany?: boolean
delete?: boolean
/**
Expand All @@ -25,7 +25,7 @@ type ReplaceRule = {
patch?: Partial<{
name: string
kind: keyof typeof ScriptElementKind
/** Might be useless when `correntSorting.enable` is true */
/** Might be useless when `correctSorting.enable` is true */
sortText: string
insertText: string | true
/** Wether insertText differs from completion name */
Expand All @@ -36,7 +36,7 @@ type ReplaceRule = {
description?: string
}
}>
/** Works only with `correntSorting.enable` set to true (default) */
/** Works only with `correctSorting.enable` set to true (default) */
// movePos?: number
/** When specified, `movePos` is ignored */
// TODO!
Expand Down Expand Up @@ -86,7 +86,7 @@ export type Configuration = {
'patchToString.enable': boolean
/**
* Format of this setting is very close to `jsxCompletionsMap` setting:
* `path#symbol` (exact) or `path/*#symbol` (`#symbol` part can be ommited)
* `path#symbol` (exact) or `path/*#symbol` (`#symbol` part can be omitted)
*
* Note: Please use `javascript`/`typescript.preferences.autoImportFileExcludePatterns` when possible, to achieve better performance!
*
Expand Down Expand Up @@ -127,7 +127,12 @@ export type Configuration = {
* @default false
*/
'suggestions.localityBonus': boolean
// TODO! corrent watching!
/**
* position = cursor position
* @default prefer-before-position
*/
'suggestions.localityBonusMode': 'prefer-before-position' | 'nearest-to-position'
// TODO! correct watching!
/**
* Wether to enable snippets for array methods like `items.map(item => )`
* @default false
Expand All @@ -145,7 +150,7 @@ export type Configuration = {
*/
'arrayMethodsSnippets.addOuterTabStop': boolean
/**
* If set to `false` and singular item name can't be inffered, feature will be disabled
* If set to `false` and singular item name can't be inferred, feature will be disabled
* @default item
*/
'arrayMethodsSnippets.defaultItemName': string | false
Expand Down Expand Up @@ -275,12 +280,12 @@ export type Configuration = {
*/
'jsxPseudoEmmet.tags': { [tag: string]: true | string }
/**
* Exclude lowercase / incorrent suggestions
* Exclude lowercase / incorrect suggestions
* @default true
*/
'jsxImproveElementsSuggestions.enabled': boolean
/**
* Recommended to enable to experience less uneeded suggestions unless you are using JSX Elements declared in namespaces
* Recommended to enable to experience less useless suggestions unless you are using JSX Elements declared in namespaces
* @default false
*/
'jsxImproveElementsSuggestions.filterNamespaces': boolean
Expand Down Expand Up @@ -338,7 +343,7 @@ export type Configuration = {
miscDefinitionImprovement: boolean
// todo change setting format to: vue.*
/**
* Removes definiion suggestion from vue `components` options.
* Removes definition suggestion from vue `components` options.
* 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)
* @default false
*/
Expand Down Expand Up @@ -431,7 +436,7 @@ export type Configuration = {
*/
'disableMethodSnippets.jsxAttributes': boolean
/**
* Support `@ts-diagnostic-disable` top-level comment for disabling spefici semantic diagnostics
* Support `@ts-diagnostic-disable` top-level comment for disabling specific semantic diagnostics
* Example: `// @ts-diagnostic-disable
* Advanced usage only! Enable in `.vscode/settings.json` for projects that need this
* Since its changes only IDE experience, but not tsc
Expand Down Expand Up @@ -465,15 +470,15 @@ export type Configuration = {
*/
switchExcludeCoveredCases: boolean
/**
* Make completions case-sensetive (see https://github.com/microsoft/TypeScript/issues/46622)
* Make completions case-sensitive (see https://github.com/microsoft/TypeScript/issues/46622)
* Might be enabled by default in future. Experimental as for now compares only start of completions.
* Might require completion retrigger if was triggered by not quick suggestions.
* @default false
*/
caseSensitiveCompletions: boolean
/**
* Might be useful to enable for a moment. Note, that you can bind shortcuts within VSCode to quickly toggle settings like this
* Also experimental and wasnt tested in all cases
* Also experimental and wasn't tested in all cases
* Like described in `caseSensitiveCompletions` might require completion retrigger
* @default false
*/
Expand All @@ -482,6 +487,7 @@ export type Configuration = {
* Disable useless highlighting,
* @default disable
*/
// todo fix spelling
disableUselessHighlighting: 'disable' | 'inJsxArttributeStrings' | 'inAllStrings'
/**
* Improve JSX attribute completions:
Expand All @@ -492,7 +498,7 @@ export type Configuration = {
improveJsxCompletions: boolean
/**
* Replace JSX completions by map with `tagName#attribute` pattern as keys
* `tagName` can be ommited, but not `attribute` for now
* `tagName` can be omitted, but not `attribute` for now
* Example usages:
* - `#className`: `insertText: "={classNames$1}"`
* - `button#type`: `insertText: "='button'"`
Expand Down Expand Up @@ -555,7 +561,7 @@ export type Configuration = {
*/
'experiments.excludeNonJsxCompletions': boolean
/**
* Wether to change funcntion completions to function kind
* Wether to change function completions to function kind
* @default false
*/
'experiments.changeKindToFunction': boolean
Expand Down Expand Up @@ -600,7 +606,7 @@ export type Configuration = {
*/
useDefaultImport?: boolean
/**
* Set to `false` if module is acessible from global variable
* Set to `false` if the module is accessible from the global variable
* For now not supported in add all missing imports code action
* @default true */
addImport?: boolean
Expand Down Expand Up @@ -632,7 +638,7 @@ export type Configuration = {
}
}

// scrapped using search editor. config: caseInsesetive, context lines: 0, regex: const fix\w+ = "[^ ]+"
// scrapped using search editor. config: caseInsensitive, context lines: 0, regex: const fix\w+ = "[^ ]+"
type FixId =
| 'addConvertToUnknownForNonOverlappingTypes'
| 'addMissingAsync'
Expand Down
55 changes: 2 additions & 53 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import vueVolarSupport from './vueVolarSupport'
import moreCompletions from './moreCompletions'
import { mergeSettingsFromScopes } from './mergeSettings'
import codeActionProvider from './codeActionProvider'
import nonTsCommands from './nonTsCommands'

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

export const activate = async () => {
registerDisableOptionalFeaturesCommand()
nonTsCommands()
migrateSettings()

const possiblyActivateTsPlugin = async () => {
Expand Down Expand Up @@ -140,55 +141,3 @@ export const activate = async () => {
})
}
}

const registerDisableOptionalFeaturesCommand = () => {
registerExtensionCommand('disableAllOptionalFeatures', async () => {
const config = vscode.workspace.getConfiguration(process.env.IDS_PREFIX, null)
const toDisable: Array<[keyof Settings, any]> = []
for (const optionalExperience of optionalExperiences) {
const desiredKey = Array.isArray(optionalExperience) ? optionalExperience[0] : optionalExperience
const desiredValue = Array.isArray(optionalExperience) ? optionalExperience[1] : false
if (config.get(desiredKey) !== desiredValue) toDisable.push([desiredKey, desiredValue])
}

const action = await vscode.window.showInformationMessage(
`${toDisable.length} features are going to be disabled`,
{ detail: '', modal: true },
'Write to settings NOW',
'Copy settings',
)
if (!action) return
switch (action) {
case 'Write to settings NOW': {
for (const [key, value] of toDisable) {
void config.update(key, value, vscode.ConfigurationTarget.Global)
}

break
}

case 'Copy settings': {
await vscode.env.clipboard.writeText(JSON.stringify(Object.fromEntries(toDisable), undefined, 4))
break
}
}
})
}

/** Experiences that are enabled out of the box */
const optionalExperiences: Array<keyof ConditionalPick<Settings, boolean> | [keyof Settings, any]> = [
'enableMethodSnippets',
'removeUselessFunctionProps.enable',
'patchToString.enable',
['suggestions.keywordsInsertText', 'none'],
'highlightNonFunctionMethods.enable',
'markTsCodeActions.enable',
['markTsCodeFixes.character', ''],
'removeCodeFixes.enable',
'removeDefinitionFromReferences',
'removeImportsFromReferences',
'miscDefinitionImprovement',
'improveJsxCompletions',
'objectLiteralCompletions.moreVariants',
'codeActions.extractTypeInferName',
]
79 changes: 79 additions & 0 deletions src/nonTsCommands.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
import * as vscode from 'vscode'
import { ConditionalPick } from 'type-fest'
import { registerExtensionCommand, Settings } from 'vscode-framework'
import { getCurrentWorkspaceRoot } from '@zardoy/vscode-utils/build/fs'
import { Utils } from 'vscode-uri'
import { showQuickPick } from '@zardoy/vscode-utils/build/quickPick'

// these commands doesn't require TS to be available

export default () => {
registerExtensionCommand('disableAllOptionalFeatures', async () => {
const config = vscode.workspace.getConfiguration(process.env.IDS_PREFIX, null)
const toDisable: Array<[keyof Settings, any]> = []
for (const optionalExperience of optionalExperiences) {
const desiredKey = Array.isArray(optionalExperience) ? optionalExperience[0] : optionalExperience
const desiredValue = Array.isArray(optionalExperience) ? optionalExperience[1] : false
if (config.get(desiredKey) !== desiredValue) toDisable.push([desiredKey, desiredValue])
}

const action = await vscode.window.showInformationMessage(
`${toDisable.length} features are going to be disabled`,
{ detail: '', modal: true },
'Write to settings NOW',
'Copy settings',
)
if (!action) return
switch (action) {
case 'Write to settings NOW': {
for (const [key, value] of toDisable) {
void config.update(key, value, vscode.ConfigurationTarget.Global)
}

break
}

case 'Copy settings': {
await vscode.env.clipboard.writeText(JSON.stringify(Object.fromEntries(toDisable), undefined, 4))
break
}
}
})

registerExtensionCommand('replaceGlobalTypescriptWithLocalVersion', async () => {
const root = getCurrentWorkspaceRoot()
const localTypeScript = Utils.joinPath(root.uri, 'node_modules/typescript')
const globalTypeScript = Utils.joinPath(vscode.Uri.file(vscode.env.appRoot), 'extensions/node_modules/typescript')
const { version: localVersion } = await vscode.workspace.fs
.readFile(Utils.joinPath(localTypeScript, 'package.json'))
.then(result => JSON.parse(result.toString()))
const { version: globalVersion } = await vscode.workspace.fs
.readFile(Utils.joinPath(globalTypeScript, 'package.json'))
.then(result => JSON.parse(result.toString()))
const result = await showQuickPick([`Replace global TS ${globalVersion} with local ${localVersion}`].map(x => ({ value: x, label: x })))
if (!result) return
const paths = ['package.json', 'lib']
for (const path of paths) {
// eslint-disable-next-line no-await-in-loop
await vscode.workspace.fs.copy(Utils.joinPath(localTypeScript, path), Utils.joinPath(globalTypeScript, path), { overwrite: true })
}
})
}

/** Experiences that are enabled out of the box */
const optionalExperiences: Array<keyof ConditionalPick<Settings, boolean> | [keyof Settings, any]> = [
'enableMethodSnippets',
'removeUselessFunctionProps.enable',
'patchToString.enable',
['suggestions.keywordsInsertText', 'none'],
'highlightNonFunctionMethods.enable',
'markTsCodeActions.enable',
['markTsCodeFixes.character', ''],
'removeCodeFixes.enable',
'removeDefinitionFromReferences',
'removeImportsFromReferences',
'miscDefinitionImprovement',
'improveJsxCompletions',
'objectLiteralCompletions.moreVariants',
'codeActions.extractTypeInferName',
]
10 changes: 5 additions & 5 deletions src/specialCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -289,9 +289,9 @@ export default () => {
await vscode.env.clipboard.writeText(text)
})

registerExtensionCommand('pasteCodeWithImports', async () => {
const clipboard = await vscode.env.clipboard.readText()
const lines = clipboard.split('\n')
const lastImportLineIndex = lines.findIndex(line => line !== 'import')
})
// registerExtensionCommand('pasteCodeWithImports', async () => {
// const clipboard = await vscode.env.clipboard.readText()
// const lines = clipboard.split('\n')
// const lastImportLineIndex = lines.findIndex(line => line !== 'import')
// })
}
Loading

0 comments on commit d9a8238

Please sign in to comment.