|
1 |
| -import { compact } from '@zardoy/utils' |
| 1 | +import { compact, oneOf } from '@zardoy/utils' |
2 | 2 | import { isTypeNode } from './completions/keywordsSpace'
|
3 | 3 | import { GetConfig } from './types'
|
4 | 4 | import { findChildContainingExactPosition } from './utils'
|
5 | 5 |
|
6 | 6 | export default (languageService: ts.LanguageService, sourceFile: ts.SourceFile, position: number, c: GetConfig) => {
|
7 |
| - const node = findChildContainingExactPosition(sourceFile, position) |
| 7 | + let node = findChildContainingExactPosition(sourceFile, position) |
8 | 8 | if (!node || isTypeNode(node)) return
|
9 | 9 |
|
10 | 10 | const checker = languageService.getProgram()!.getTypeChecker()!
|
11 | 11 | const type = checker.getTypeAtLocation(node)
|
12 |
| - const signatures = checker.getSignaturesOfType(type, ts.SignatureKind.Call) |
| 12 | + |
| 13 | + if (ts.isIdentifier(node)) node = node.parent |
| 14 | + if (ts.isPropertyAccessExpression(node)) node = node.parent |
| 15 | + |
| 16 | + const isNewExpression = ts.isNewExpression(node) |
| 17 | + const signatures = checker.getSignaturesOfType(type, isNewExpression ? ts.SignatureKind.Construct : ts.SignatureKind.Call) |
| 18 | + // ensure node is not used below |
13 | 19 | if (signatures.length === 0) return
|
14 |
| - const signature = signatures[0] |
| 20 | + const signature = signatures[0]! |
| 21 | + // probably need to remove check as class can be instantiated inside another class, and don't really see a reason for this check |
| 22 | + if (isNewExpression && hasPrivateOrProtectedModifier(signature.getDeclaration().modifiers)) return |
15 | 23 | if (signatures.length > 1 && c('methodSnippets.multipleSignatures') === 'empty') {
|
16 | 24 | return ['']
|
17 | 25 | }
|
@@ -121,3 +129,7 @@ function getPromiseLikeTypeArgument(type: ts.Type | undefined, checker: ts.TypeC
|
121 | 129 | if (typeArgs.length !== 1) return
|
122 | 130 | return typeArgs[0]!
|
123 | 131 | }
|
| 132 | + |
| 133 | +function hasPrivateOrProtectedModifier(modifiers: ts.NodeArray<ts.ModifierLike> | ts.NodeArray<ts.Modifier> | undefined) { |
| 134 | + return modifiers?.some(modifier => oneOf(modifier.kind, ts.SyntaxKind.PrivateKeyword, ts.SyntaxKind.ProtectedKeyword)) |
| 135 | +} |
0 commit comments