Skip to content

Commit

Permalink
Merge pull request #176 from zardoy/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
zardoy authored Nov 8, 2023
2 parents d0388d0 + 00d3fee commit 30f31be
Show file tree
Hide file tree
Showing 29 changed files with 1,291 additions and 81 deletions.
3 changes: 0 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ jobs:
# if command with timeout already failed on unix, Windows job will be cancelled
- run: pnpm test-plugin
if: ${{ runner.os == 'Windows' }}
- uses: GabrielBB/[email protected]
with:
run: pnpm integration-test
- run: cd out && npx @vscode/vsce package --out ../extension.vsix
- name: Archive production artifacts
uses: actions/upload-artifact@v3
Expand Down
12 changes: 11 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
"tsEssentialPlugins.autoImport.changeToNamespaceImport": {
"typescript": {
"typescript/lib/tsserverlibrary": {
"namespace": "ts",
"addImport": false
}
},
"typescript.preferences.autoImportFileExcludePatterns": [
"./typescript/src/ts.d.ts"
],
"tsEssentialPlugins.suggestions.ignoreAutoImports": [
"typescript-full",
"@volar/language-service/*"
Expand All @@ -13,6 +16,13 @@
"develop"
],
"cSpell.words": [
"tsserverlibrary",
"unpatch"
],
"vitest.enable": true,
"vitest.commandLine": "pnpm test-plugin",
"vitest.showFailMessages": true,
"vitest.include": [
"typescript/test/**/*.{test,spec}.{js,mjs,cjs,ts,mts,cts,jsx,tsx}"
]
}
2 changes: 2 additions & 0 deletions CONTRIBUTING.MD
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ To start the VS Code plugin extension locally for developing:

#### Unit Tests

> Note: currently project doesn't use integration testing so you can ignore `integration` folder
They are in `typescript/test` and using vitest, so they faster than integration. Feel free to add new tests here. But note that most of tests are completion tests, but I do hope to add more types tests in the future.

To launch them run `pnpm test-plugin`.
Expand Down
14 changes: 7 additions & 7 deletions README.MD
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,17 @@
Feature-complete TypeScript plugin that improves every single builtin feature such as completions, definitions, references and so on, and also adds even new TypeScript killer features, so you can work with large codebases faster!
We make completions more informative. Definitions, references (and sometimes even completions) less noisy. And finally our main goal is to provide most customizable TypeScript experience for IDE features.

TOC:
## TOC

- [Top Features](#top-features)
- [Minor Useful Features](#minor-useful-features)
- [Method Snippets](#method-snippets)
- [Volar (Vue) support](#vue-support)
- [Volar (Vue) Support](#vue-support)
- [Auto Imports](#auto-imports)
- [Type Driven Completions](#type-driven-completions)
- [Rename Features](#rename-features)
- [Special Commands List](#special-commands-list)
- [Contributed Code Actions](#contributed-code-actions)
- [Rename Features](#rename-features)
- [Even Even More](#even-even-more)

> *Note*: You can disable all optional features with `> Disable All Optional Features` command right after install.
Expand Down Expand Up @@ -133,6 +133,8 @@ This also makes plugin work in Volar's takeover mode!
There is web-only feature: fix clicking on relative `import` paths.

Alternative you can try to use [vscode-typescript-web extension](https://github.com/volarjs/vscode-typescript-web/) for better web intellisense.

### `in` Keyword Suggestions

[Demo](https://github.com/zardoy/typescript-vscode-plugins/pull/19)
Expand Down Expand Up @@ -319,7 +321,7 @@ function Foo() {
}
```

`tsEssentialPlugins.methodSnippetsInsertText`:
`tsEssentialPlugins.methodSnippets.previewSignature`:

Optionally resolve insertText of all completion at suggest trigger:

Expand Down Expand Up @@ -448,9 +450,7 @@ You can add this to `keybindings.json` to disable previewing before renaming:
}
```

Another options that is accepted is

> Note: VS Code has builtin setting to disable introducing aliases (e.g. for imports & object properties)
> Note: VS Code has builtin setting to disable introducing aliases (e.g. for imports & object properties): `typescript.preferences.useAliasesForRenames`
## Special Commands List

Expand Down
17 changes: 17 additions & 0 deletions buildTsPlugin.mjs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
//@ts-check
import buildTsPlugin from '@zardoy/vscode-utils/build/buildTypescriptPlugin.js'
import { build, analyzeMetafile } from 'esbuild'
import fs from 'fs'

const enableWatch = process.argv.includes('--watch')
await build({
Expand Down Expand Up @@ -29,6 +30,22 @@ const result = await buildTsPlugin('typescript', undefined, undefined, {
js: 'let ts, tsFull;',
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))',
},
plugins: [
{
name: 'watch-notifier',
setup(build) {
const writeStatus = (/** @type {number} */ signal) => {
fs.writeFileSync('./out/build_plugin_result', signal.toString())
}
build.onStart(() => {
writeStatus(0)
})
build.onEnd(({ errors }) => {
writeStatus(errors.length ? 2 : 1)
})
},
},
],
})

// @ts-ignore
Expand Down
4 changes: 4 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,10 @@
{
"command": "getArgumentReferencesFromCurrentParameter",
"title": "Get Argument References from Current Parameter"
},
{
"command": "printPerformanceMemoryInfo",
"title": "Print Performance & Memory Info"
}
],
"keybindings": [
Expand Down
27 changes: 27 additions & 0 deletions src/autoPluginReload.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
import * as vscode from 'vscode'
import fs from 'fs'
import { extensionCtx } from 'vscode-framework'

export default () => {
const status = vscode.window.createStatusBarItem('plugin-auto-reload', vscode.StatusBarAlignment.Left, 1000)
status.show()
const watcher = vscode.workspace.createFileSystemWatcher(new vscode.RelativePattern(extensionCtx.extensionUri, 'build_plugin_result'))
const updateStatus = uri => {
const newStatus = fs.readFileSync(uri.fsPath, 'utf8')
if (newStatus === '1') {
void vscode.commands.executeCommand('typescript.restartTsServer')
status.text = 'Latest'
}

if (newStatus === '0') {
status.text = 'Rebuilding'
}

if (newStatus === '2') {
status.text = 'Build errored'
}
}

watcher.onDidChange(updateStatus)
watcher.onDidCreate(updateStatus)
}
9 changes: 5 additions & 4 deletions src/configurationType.ts
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,8 @@ export type Configuration = {
* Format of this setting is very close to `jsxCompletionsMap` setting:
* `path#symbol` (exact) or `path/*#symbol` (`#symbol` part can be omitted)
*
* Note: Please use `javascript`/`typescript.preferences.autoImportFileExcludePatterns` when possible, to achieve better performance!
* **Note**: Please use builtin `javascript`/`typescript.preferences.autoImportFileExcludePatterns` when possible, to achieve better performance!
* The builtin function expects relative paths to .d.ts / .ts files that contains declarations.
*
* e.g. instead of declaring `@mui/icons-material` here, declare `node_modules/@mui/icons-material` in aforementioned setting.
*
Expand All @@ -99,7 +100,7 @@ export type Configuration = {
* - `path/*#join` - ignore path, path/posix and path/win32, but only join symbol
* - `path/*#join,resolve` - ignore path, path/posix and path/win32, but only join and resolve symbol
*
* - jquery/* - ignore absolutely all auto imports from jquery, even if it was declared virtually (declare module)
* - jquery/* - ignore absolutely all auto imports from jquery, even if it was declared using ambient declaration (`declare module`)
* @default []
*/
'suggestions.ignoreAutoImports': string[]
Expand Down Expand Up @@ -384,7 +385,7 @@ export type Configuration = {
* Recommended to try!
* @default disable
*/
methodSnippetsInsertText: 'disable' | 'only-local' | 'all'
'methodSnippets.previewSignature': 'disable' | 'only-local' | 'all'
/**
* ```ts
* const example = ({ a }, b?, c = 5, ...d) => { }
Expand Down Expand Up @@ -571,7 +572,7 @@ export type Configuration = {
'experiments.excludeNonJsxCompletions': boolean
/**
* Wether to change function completions to function kind
* @deprecated Use `methodSnippetsInsertText` instead
* @deprecated Use `methodSnippets.previewSignature` instead
* @default false
*/
'experiments.changeKindToFunction': boolean
Expand Down
4 changes: 4 additions & 0 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,10 @@ export const activateTsPlugin = (tsApi: { configurePlugin; onCompletionAccepted

figIntegration()
vueVolarSupport()

if (process.env.PLATFORM === 'node' && process.env.NODE_ENV === 'development') {
require('./autoPluginReload').default()
}
}

export const activate = async () => {
Expand Down
7 changes: 7 additions & 0 deletions src/migrateSettings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ export default () => {
mustBePrimitive: false,
},
},
{
rename: {
old: 'methodSnippetsInsertText',
new: 'methodSnippets.previewSignature',
mustBePrimitive: false,
},
},
{
async detect(configuration) {
return !!(await migrateSettingValues(configuration, true))
Expand Down
9 changes: 6 additions & 3 deletions src/onCompletionAccepted.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,8 +62,8 @@ export default (tsApi: { onCompletionAccepted }) => {
const nextChar = editor.document.getText(new vscode.Range(startPos, startPos.translate(0, 1)))
if (!params || ['(', '.', '`'].includes(nextChar)) return

if (getExtensionSetting('methodSnippetsInsertText') === 'disable') {
// handle insertion only if it wasn't handled by methodSnippetsInsertText already
if (getExtensionSetting('methodSnippets.previewSignature') === 'disable') {
// handle insertion only if it wasn't handled by 'methodSnippets.previewSignature' already
if (isAmbiguous && lastAcceptedAmbiguousMethodSnippetSuggestion !== suggestionName) {
lastAcceptedAmbiguousMethodSnippetSuggestion = suggestionName
return
Expand Down Expand Up @@ -116,7 +116,10 @@ export default (tsApi: { onCompletionAccepted }) => {
resolve(true)
}
})
if (accepted) void vscode.window.showInformationMessage('Completion accepted, see console for details')
if (accepted) {
void vscode.window.showInformationMessage('Completion accepted, see console for details')
console.show(true)
}
},
)
})
Expand Down
7 changes: 7 additions & 0 deletions src/specialCommands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,13 @@ export default () => {
)
})

registerExtensionCommand('printPerformanceMemoryInfo', async () => {
const info = await sendCommand('performanceInfo', {})
if (!info) return
console.dir(info, { depth: 10 })
console.show(true)
})

// registerExtensionCommand('insertImportFlatten', () => {
// // got -> default, got
// type A = ts.Type
Expand Down
Loading

0 comments on commit 30f31be

Please sign in to comment.