Skip to content

Commit 14fe64d

Browse files
authored
files structure refactor, add special commands! (#39)
feat: add experimental postfixes that disabled by default
1 parent 877692d commit 14fe64d

36 files changed

+1204
-545
lines changed

.eslintrc.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
{
22
"extends": "zardoy",
3-
"rules": {}
3+
"rules": {
4+
"curly": "off"
5+
}
46
}

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
run_install: |
2828
args: [--frozen-lockfile, --strict-peer-dependencies]
2929
- run: pnpm lint
30-
# - run: pnpm unit-test
30+
- run: pnpm test-plugin
3131
- run: pnpm vscode-utils prepareFrameworkBuild
3232
- run: pnpm build
3333
# - uses: GabrielBB/[email protected]

README.MD

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,17 @@ By default removes `Fix Missing Function Declaration` codefix. Possibly to remov
6363

6464
Removes `Symbol`, `caller`, `prototype` completions on function / classes.
6565

66-
### Patch `toString()`
66+
### Keywords Insert Text
6767

6868
(*enabled by default*)
6969

70-
Patches `toString()` insert function snippet on number types to remove tabStop.
70+
Appends *space* to almost all keywords e.g. `extends `, like WebStorm does.
7171

72-
### Keywords Insert Text
72+
### Patch `toString()`
7373

7474
(*enabled by default*)
7575

76-
Almost all keywords would insert space after the name of keyword e.g. `extends` -> `extends `
76+
Patches `toString()` insert function snippet on number types to remove tabStop.
7777

7878
### Correct Sorting
7979

buildTsPlugin.mjs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ await buildTsPlugin('typescript', undefined, undefined, {
66
watch,
77
logLevel: 'info',
88
sourcemap: watch,
9-
// banner: {
10-
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))',
11-
// },
9+
banner: {
10+
js: 'let ts',
11+
// js: 'const log = (...args) => console.log(...args.map(a => JSON.stringify(a)))',
12+
},
1213
})

integration/fixtures/test-project/jsconfig.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
{
2+
"compilerOptions": {
3+
"jsx": "react-jsx"
4+
},
25
"include": [
36
"src"
47
]
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
type A = {
2+
(): void
3+
sync: (arg1?: string) => {}
4+
}
5+
6+
let a: A
7+
a.s

integration/runTests.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ async function main() {
77
version: 'stable',
88
extensionDevelopmentPath: join(__dirname, '../out'),
99
extensionTestsPath: join(__dirname, './index'),
10-
launchArgs: ['--disable-extensions'],
10+
launchArgs: [join(__dirname, '../integration/fixtures'), '--disable-extensions'],
1111
})
1212
} catch (error) {
1313
console.error(error)

integration/suite/completions.test.ts

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import * as vscode from 'vscode'
2+
import delay from 'delay'
3+
4+
import { expect } from 'chai'
5+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
6+
import { fromFixtures, prepareTsStart } from './utils'
7+
8+
describe('Completions', () => {
9+
const editor = () => vscode.window.activeTextEditor!
10+
11+
before(async function () {
12+
this.timeout(6000)
13+
// await vscode.workspace.getConfiguration('typescript').update('tsserver.log', 'verbose', vscode.ConfigurationTarget.Global)
14+
await vscode.commands.executeCommand('vscode.open', vscode.Uri.file(fromFixtures('test-project/src/completions.ts')))
15+
await prepareTsStart()
16+
// await vscode.commands.executeCommand('typescript.openTsServerLog')
17+
})
18+
19+
it('Modifier & method snippets', async () => {
20+
const endPos = () => editor().document.lineAt(editor().document.lineCount - 1).range.end
21+
const pos = endPos()
22+
editor().selection = new vscode.Selection(endPos(), endPos())
23+
await delay(1000)
24+
await vscode.commands.executeCommand('editor.action.triggerSuggest')
25+
const { items }: vscode.CompletionList = (await vscode.commands.executeCommand(
26+
'vscode.executeCompletionItemProvider',
27+
editor().document.uri,
28+
pos,
29+
)) as any
30+
expect(items.some(({ label }) => label === '☆sync')).to.equal(true)
31+
await delay(200)
32+
await vscode.commands.executeCommand('acceptSelectedSuggestion')
33+
await delay(300)
34+
expect(editor().document.lineAt(endPos()).text).to.equal('a.sync(arg1)')
35+
}).timeout(5000)
36+
37+
after(async () => {
38+
await vscode.commands.executeCommand('workbench.action.files.revert')
39+
await vscode.commands.executeCommand('workbench.action.closeActiveEditor')
40+
})
41+
})

integration/suite/jsx.test.ts

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import * as vscode from 'vscode'
2+
import delay from 'delay'
3+
4+
import { expect } from 'chai'
5+
// eslint-disable-next-line @typescript-eslint/ban-ts-comment, @typescript-eslint/prefer-ts-expect-error
6+
import { fromFixtures, prepareTsStart, replaceEditorText } from './utils'
7+
//@ts-ignore
8+
import { Configuration } from '../../src/configurationType'
9+
10+
describe('JSX Attributes', () => {
11+
const editor = () => vscode.window.activeTextEditor!
12+
13+
const startPos = new vscode.Position(0, 0)
14+
before(async function () {
15+
this.timeout(5000)
16+
// await vscode.workspace.getConfiguration('typescript').update('tsserver.log', 'verbose', vscode.ConfigurationTarget.Global)
17+
const configKey: keyof Configuration = 'jsxCompletionsMap'
18+
const configValue: Configuration['jsxCompletionsMap'] = {
19+
'div#classNam*': { insertText: '={test$1}' },
20+
}
21+
await vscode.workspace.getConfiguration('tsEssentialPlugins').update(configKey, configValue, vscode.ConfigurationTarget.Global)
22+
await vscode.commands.executeCommand('vscode.open', vscode.Uri.file(fromFixtures('test-project/src/index.tsx')))
23+
await prepareTsStart()
24+
})
25+
26+
it('JSX attribute patch', async () => {
27+
const searchText = /* className */ '="main__wrap"'
28+
const pos = editor().document.positionAt(editor().document.getText().indexOf(searchText))
29+
const endPos = pos.translate(0, searchText.length)
30+
await replaceEditorText(editor(), new vscode.Range(pos, endPos), '')
31+
editor().selection = new vscode.Selection(pos, pos)
32+
// vscode has slow startup in react langs
33+
await delay(1300)
34+
await vscode.commands.executeCommand('editor.action.triggerSuggest')
35+
await delay(500)
36+
await vscode.commands.executeCommand('acceptSelectedSuggestion')
37+
await delay(300)
38+
expect(editor().document.lineAt(pos).text.slice(pos.character)).to.equal('={test}>')
39+
}).timeout(5000)
40+
41+
after(async () => {
42+
await vscode.commands.executeCommand('workbench.action.files.revert')
43+
await vscode.commands.executeCommand('workbench.action.closeActiveEditor')
44+
})
45+
})

integration/suite/outline.test.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,6 @@ describe('Outline', () => {
8181

8282
describe('Outline in js project', () => {
8383
it('Initial', async () => {
84-
await vscode.commands.executeCommand('vscode.openFolder', vscode.Uri.file(fromFixtures('test-project')))
8584
await delay(500)
8685
await vscode.commands.executeCommand('vscode.open', vscode.Uri.file(fromFixtures('test-project/src/index.tsx')))
8786
await delay(600)

0 commit comments

Comments
 (0)