Skip to content

Commit 9a44410

Browse files
committed
type-driven completions docs
a few minor fixes for new method completions add todo tests
1 parent 0ef516a commit 9a44410

File tree

3 files changed

+66
-5
lines changed

3 files changed

+66
-5
lines changed

README.MD

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -163,8 +163,6 @@ Try to restore [original](https://github.com/microsoft/TypeScript/issues/49012)
163163
We extend completion list with extensions from module augmentation (e.g. `.css` files if you have `declare module '*.css'`).
164164
But for unchecked contexts list of extensions can be extended with `tsEssentialPlugins.additionalIncludeExtensions` setting.
165165

166-
<!-- ## Type-Driven Completions -->
167-
168166
### Mark Code Actions
169167

170168
(*enabled by default* with two settings)
@@ -193,7 +191,38 @@ const a = 5
193191
a = 6
194192
```
195193

196-
### Method Snippets
194+
### Format Ignore Directives
195+
196+
We support [format ignore directives](https://github.com/microsoft/TypeScript/issues/18261)
197+
198+
## Type-Driven Completions
199+
200+
All in this section requires TypeScript nightly extension.
201+
202+
### JSX Elements
203+
204+
To Enable: `"tsEssentialPlugins.experiments.excludeNonJsxCompletions": true`
205+
206+
We can filter out completions so only Function Components stay in your list:
207+
208+
```tsx
209+
class Foo {}
210+
const Bar = () => <div />
211+
212+
const elem = </* Bar is suggested, Foo not
213+
```
214+
215+
Super handy in MUI + Electron projects.
216+
217+
Class components are not supported (no need).
218+
219+
### Change kind to function
220+
221+
Enable with `tsEssentialPlugins.experiments.changeKindToFunction`
222+
223+
![change-icon-kind](media/change-kind.png)
224+
225+
## Method Snippets
197226
198227
(*enabled by default*)
199228

src/onCompletionAccepted.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ export default (tsApi: { onCompletionAccepted }) => {
3636

3737
const enableMethodSnippets = vscode.workspace.getConfiguration(process.env.IDS_PREFIX, item.document).get('enableMethodSnippets')
3838

39-
if (enableMethodSnippets && (typeof insertText !== 'object' || !insertText.value.endsWith(')$0'))) {
39+
if (enableMethodSnippets && /* either snippet by vscode or by us to ignore pos */ typeof insertText !== 'object') {
4040
const editor = getActiveRegularEditor()!
4141
const startPos = editor.selection.start
4242
const nextSymbol = editor.document.getText(new vscode.Range(startPos, startPos.translate(0, 1)))
@@ -80,6 +80,9 @@ export default (tsApi: { onCompletionAccepted }) => {
8080
if (i !== parameters.length - 1) snippet.appendText(', ')
8181
}
8282

83+
const allFiltered = data.parameters.length > parameters.length
84+
if (allFiltered) snippet.appendTabstop()
85+
8386
snippet.appendText(')')
8487
void editor.insertSnippet(snippet, undefined, {
8588
undoStopAfter: false,

typescript/test/completions.spec.ts

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,9 @@ const fourslashLikeTester = (contents: string, fileName = entrypoint) => {
9797
if (includes) {
9898
const { names, all } = includes
9999
if (names) {
100-
expect(result?.entryNames, message).toContain(names)
100+
for (const name of names) {
101+
expect(result?.entryNames, message).toContain(name)
102+
}
101103
}
102104
if (all) {
103105
for (const entry of result.entries.filter(e => names?.includes(e.name))) {
@@ -334,6 +336,33 @@ test('Case-sensetive completions', () => {
334336
}
335337
})
336338

339+
// ts 5
340+
test.todo('Change to function kind', () => {
341+
settingsOverride['experiments.changeKindToFunction'] = true
342+
const tester = fourslashLikeTester(/* ts */ `
343+
// declare const foo: boolean
344+
const foo = () => {}
345+
foo/*1*/
346+
`)
347+
tester.completion(1, {
348+
includes: {
349+
names: ['foo'],
350+
all: {
351+
kind: ts.ScriptElementKind.functionElement,
352+
},
353+
},
354+
})
355+
settingsOverride['experiments.changeKindToFunction'] = false
356+
})
357+
358+
// ts 5
359+
test.todo('Filter JSX Components', () => {
360+
const tester = fourslashLikeTester(/* ts */ `
361+
const a = () => {}
362+
a/*1*/
363+
`)
364+
})
365+
337366
test('Omit<..., ""> suggestions', () => {
338367
const tester = fourslashLikeTester(/* ts */ `
339368
interface A {

0 commit comments

Comments
 (0)