|
1 | 1 | import pluralize from 'pluralize'
|
| 2 | +import { lowerCaseFirst } from '@zardoy/utils' |
2 | 3 | import { GetConfig } from '../types'
|
3 | 4 | import { findChildContainingPosition, getLineTextBeforePos } from '../utils'
|
4 | 5 |
|
@@ -29,20 +30,30 @@ export default (entries: ts.CompletionEntry[], position: number, sourceFile: ts.
|
29 | 30 | const nodeBeforeDot = findChildContainingPosition(ts, sourceFile, position - postfixRemoveLength - 1)
|
30 | 31 | if (!nodeBeforeDot) return
|
31 | 32 |
|
32 |
| - const cleanSourceText = getItemNameFromNode(nodeBeforeDot)?.replace(/^(?:all)?(.+?)(?:List)?$/, '$1') |
| 33 | + let inferred = true |
| 34 | + const defaultItemName = { |
| 35 | + get value() { |
| 36 | + inferred = false |
| 37 | + return c('arrayMethodsSnippets.defaultItemName') |
| 38 | + }, |
| 39 | + } |
| 40 | + const cleanSourceText = lowerCaseFirst(getItemNameFromNode(nodeBeforeDot)?.replace(/^(?:all)?(.+?)(?:List)?$/, '$1') ?? '') || defaultItemName.value |
33 | 41 | if (!cleanSourceText) return
|
34 | 42 | let inferredName = pluralize.singular(cleanSourceText)
|
35 |
| - const defaultItemName = c('arrayMethodsSnippets.defaultItemName') |
36 | 43 | // both can be undefined
|
37 | 44 | if (inferredName === cleanSourceText) {
|
38 |
| - if (defaultItemName === false) return |
39 |
| - inferredName = defaultItemName |
| 45 | + if (defaultItemName.value === false) return |
| 46 | + inferredName = defaultItemName.value |
| 47 | + } |
| 48 | + |
| 49 | + if (inferredName && c('arrayMethodsSnippets.inferredFirstLetterOnly')) { |
| 50 | + inferredName = inferredName[0]! |
40 | 51 | }
|
41 | 52 |
|
42 | 53 | // workaround for
|
43 | 54 | // https://github.com/microsoft/vscode/blob/4765b898acb38a44f9dd8fa7ed48e833fff6ecc6/extensions/typescript-language-features/src/languageFeatures/completions.ts#L99
|
44 | 55 | // (overriding default range)
|
45 |
| - // after []. .fill was appearing above .filter becuase .filter is snippet in insertText, not changing insertText of .fill so vscode method completions calls work as expected |
| 56 | + // after []. .fill was appearing above .filter because .filter is snippet in insertText, not changing insertText of .fill so vscode method completions calls work as expected |
46 | 57 | const resetRangeKinds = fullText.slice(position - 1, position) === '.' && [
|
47 | 58 | ts.ScriptElementKind.constElement,
|
48 | 59 | ts.ScriptElementKind.memberFunctionElement,
|
|
0 commit comments