@tslite/services 1.16.0 → 1.17.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (123) hide show
  1. package/NOTICE +3 -1
  2. package/dist/_namespaces/edit.d.ts +1 -1
  3. package/dist/_namespaces/edit.js +10759 -11
  4. package/dist/_namespaces/ts.codefix.d.ts +0 -1
  5. package/dist/_namespaces/ts.js +10196 -19
  6. package/dist/classifier.d.ts +3 -1
  7. package/dist/codeFixProvider.d.ts +2 -1
  8. package/dist/codefixes/helpers.d.ts +3 -1
  9. package/dist/codefixes/importFixes.d.ts +3 -1
  10. package/dist/completions.d.ts +5 -2
  11. package/dist/documentHighlights.d.ts +3 -1
  12. package/dist/documentRegistry.d.ts +2 -1
  13. package/dist/findAllReferences.d.ts +3 -1
  14. package/dist/formatting/formatting.d.ts +3 -2
  15. package/dist/formatting/formattingContext.d.ts +2 -1
  16. package/dist/formatting/formattingScanner.d.ts +2 -2
  17. package/dist/formatting/rule.d.ts +1 -1
  18. package/dist/formatting/rulesMap.d.ts +1 -1
  19. package/dist/formatting/smartIndenter.d.ts +2 -1
  20. package/dist/getEditsForFileRename.d.ts +4 -1
  21. package/dist/goToDefinition.d.ts +3 -1
  22. package/dist/importTracker.d.ts +2 -1
  23. package/dist/navigationBar.d.ts +3 -1
  24. package/dist/organizeImports.d.ts +4 -2
  25. package/dist/outliningElementsCollector.d.ts +3 -1
  26. package/dist/refactorProvider.d.ts +1 -1
  27. package/dist/refactors/extractSymbol.d.ts +2 -1
  28. package/dist/rename.d.ts +3 -1
  29. package/dist/services.d.ts +5 -2
  30. package/dist/signatureHelp.d.ts +3 -1
  31. package/dist/smartSelection.d.ts +2 -1
  32. package/dist/stringCompletions.d.ts +3 -1
  33. package/dist/suggestionDiagnostics.d.ts +4 -3
  34. package/dist/symbolDisplay.d.ts +3 -1
  35. package/dist/textChanges.d.ts +4 -2
  36. package/dist/types.d.ts +3 -3
  37. package/dist/utilities.d.ts +7 -2
  38. package/package.json +7 -5
  39. package/dist/_namespaces/ts.Completions.StringCompletions.js +0 -2
  40. package/dist/_namespaces/ts.Completions.js +0 -3
  41. package/dist/_namespaces/ts.FindAllReferences.js +0 -3
  42. package/dist/_namespaces/ts.GoToDefinition.js +0 -2
  43. package/dist/_namespaces/ts.NavigationBar.js +0 -2
  44. package/dist/_namespaces/ts.OrganizeImports.js +0 -2
  45. package/dist/_namespaces/ts.OutliningElementsCollector.js +0 -2
  46. package/dist/_namespaces/ts.Rename.js +0 -2
  47. package/dist/_namespaces/ts.SignatureHelp.js +0 -2
  48. package/dist/_namespaces/ts.SmartSelectionRange.js +0 -2
  49. package/dist/_namespaces/ts.SymbolDisplay.js +0 -2
  50. package/dist/_namespaces/ts.codefix.js +0 -27
  51. package/dist/_namespaces/ts.formatting.js +0 -8
  52. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +0 -2
  53. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +0 -2
  54. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +0 -2
  55. package/dist/_namespaces/ts.refactor.extractSymbol.js +0 -2
  56. package/dist/_namespaces/ts.refactor.js +0 -10
  57. package/dist/_namespaces/ts.textChanges.js +0 -2
  58. package/dist/classifier.js +0 -715
  59. package/dist/codeFixProvider.js +0 -84
  60. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +0 -1
  61. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +0 -21
  62. package/dist/codefixes/addEmptyExportDeclaration.js +0 -17
  63. package/dist/codefixes/addMissingAsync.js +0 -75
  64. package/dist/codefixes/addMissingAwait.js +0 -236
  65. package/dist/codefixes/addMissingConst.js +0 -91
  66. package/dist/codefixes/addNameToNamelessParameter.js +0 -29
  67. package/dist/codefixes/convertConstToLet.js +0 -30
  68. package/dist/codefixes/convertToAsyncFunction.js +0 -495
  69. package/dist/codefixes/convertToMappedObjectType.js +0 -48
  70. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +0 -33
  71. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +0 -27
  72. package/dist/codefixes/fixAwaitInSyncFunction.js +0 -69
  73. package/dist/codefixes/fixExpectedComma.js +0 -35
  74. package/dist/codefixes/fixInvalidJsxCharacters.js +0 -41
  75. package/dist/codefixes/fixMissingCallParentheses.js +0 -42
  76. package/dist/codefixes/fixSpelling.js +0 -94
  77. package/dist/codefixes/fixUnreachableCode.js +0 -65
  78. package/dist/codefixes/fixUnusedIdentifier.js +0 -224
  79. package/dist/codefixes/helpers.js +0 -53
  80. package/dist/codefixes/importFixes.js +0 -441
  81. package/dist/codefixes/inferFromUsage.js +0 -742
  82. package/dist/codefixes/removeUnnecessaryAwait.js +0 -41
  83. package/dist/codefixes/returnValueCorrect.js +0 -132
  84. package/dist/codefixes/splitTypeOnlyImport.js +0 -32
  85. package/dist/codefixes/useBigintLiteral.js +0 -29
  86. package/dist/completions.js +0 -1720
  87. package/dist/documentHighlights.js +0 -367
  88. package/dist/documentRegistry.js +0 -63
  89. package/dist/editingServices.js +0 -4
  90. package/dist/findAllReferences.js +0 -1366
  91. package/dist/formatting/formatting.js +0 -1021
  92. package/dist/formatting/formattingContext.js +0 -78
  93. package/dist/formatting/formattingScanner.js +0 -228
  94. package/dist/formatting/rule.js +0 -22
  95. package/dist/formatting/rules.js +0 -610
  96. package/dist/formatting/rulesMap.js +0 -127
  97. package/dist/formatting/smartIndenter.js +0 -518
  98. package/dist/getEditsForFileRename.js +0 -86
  99. package/dist/goToDefinition.js +0 -246
  100. package/dist/importTracker.js +0 -422
  101. package/dist/index.js +0 -3
  102. package/dist/navigationBar.js +0 -549
  103. package/dist/organizeImports.js +0 -290
  104. package/dist/outliningElementsCollector.js +0 -261
  105. package/dist/refactorProvider.js +0 -16
  106. package/dist/refactors/addOrRemoveBracesToArrowFunction.js +0 -86
  107. package/dist/refactors/convertExport.js +0 -126
  108. package/dist/refactors/convertImport.js +0 -116
  109. package/dist/refactors/convertParamsToDestructuredObject.js +0 -282
  110. package/dist/refactors/convertStringOrTemplateLiteral.js +0 -148
  111. package/dist/refactors/extractSymbol.js +0 -1281
  112. package/dist/refactors/extractType.js +0 -102
  113. package/dist/refactors/moveToNewFile.js +0 -477
  114. package/dist/rename.js +0 -100
  115. package/dist/services.js +0 -1480
  116. package/dist/signatureHelp.js +0 -414
  117. package/dist/smartSelection.js +0 -243
  118. package/dist/stringCompletions.js +0 -220
  119. package/dist/suggestionDiagnostics.js +0 -92
  120. package/dist/symbolDisplay.js +0 -400
  121. package/dist/textChanges.js +0 -1163
  122. package/dist/types.js +0 -263
  123. package/dist/utilities.js +0 -1981
@@ -1,414 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/signatureHelp.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Debug, EmitHint, InternalSymbolName, ListFormat, NodeBuilderFlags, SyntaxKind, contains, countWhere, createNodeArray, createPrinter, createTextSpan, createTextSpanFromBounds, emptyArray, findContainingList, findPrecedingToken, findTokenOnLeftOfPosition, first, firstDefined, getInvokedExpression, getPossibleGenericSignatures, getPossibleTypeArgumentsInfo, isBlock, isCallExpression, isFunctionTypeNode, isIdentifier, isInComment, isInString, isJsxOpeningLikeElement, isSourceFile, last, mapToDisplayParts, punctuationPart, rangeContainsRange, skipTrivia, spacePart, symbolToDisplayParts, } from "./_namespaces/ts.js";
3
- var InvocationKind;
4
- (function (InvocationKind) {
5
- InvocationKind[InvocationKind["Call"] = 0] = "Call";
6
- InvocationKind[InvocationKind["TypeArgs"] = 1] = "TypeArgs";
7
- InvocationKind[InvocationKind["Contextual"] = 2] = "Contextual";
8
- })(InvocationKind || (InvocationKind = {}));
9
- export function getSignatureHelpItems(program, sourceFile, position, triggerReason, cancellationToken) {
10
- const typeChecker = program.getTypeChecker();
11
- // Decide whether to show signature help
12
- const startingToken = findTokenOnLeftOfPosition(sourceFile, position);
13
- if (!startingToken) {
14
- // We are at the beginning of the file
15
- return undefined;
16
- }
17
- // Only need to be careful if the user typed a character and signature help wasn't showing.
18
- const onlyUseSyntacticOwners = !!triggerReason && triggerReason.kind === "characterTyped";
19
- // Bail out quickly in the middle of a string or comment, don't provide signature help unless the user explicitly requested it.
20
- if (onlyUseSyntacticOwners && (isInString(sourceFile, position, startingToken) || isInComment(sourceFile, position))) {
21
- return undefined;
22
- }
23
- const isManuallyInvoked = !!triggerReason && triggerReason.kind === "invoked";
24
- const argumentInfo = getContainingArgumentInfo(startingToken, position, sourceFile, typeChecker, isManuallyInvoked);
25
- if (!argumentInfo)
26
- return undefined;
27
- cancellationToken.throwIfCancellationRequested();
28
- // Extra syntactic and semantic filtering of signature help
29
- const candidateInfo = getCandidateOrTypeInfo(argumentInfo, typeChecker, sourceFile, startingToken, onlyUseSyntacticOwners);
30
- cancellationToken.throwIfCancellationRequested();
31
- // Na tag, num arquivo JavaScript sem resposta do checker, a assinatura de uma declaração de mesmo nome em qualquer
32
- // arquivo (o `createJSSignatureHelpItems`, CK-03).
33
- if (!candidateInfo) {
34
- return undefined;
35
- }
36
- return typeChecker.runWithCancellationToken(cancellationToken, typeChecker => candidateInfo.kind === 0 /* CandidateOrTypeKind.Candidate */
37
- ? createSignatureHelpItems(candidateInfo.candidates, candidateInfo.resolvedSignature, argumentInfo, sourceFile, typeChecker)
38
- : createTypeHelpItems(candidateInfo.symbol, argumentInfo, sourceFile, typeChecker));
39
- }
40
- var CandidateOrTypeKind;
41
- (function (CandidateOrTypeKind) {
42
- CandidateOrTypeKind[CandidateOrTypeKind["Candidate"] = 0] = "Candidate";
43
- CandidateOrTypeKind[CandidateOrTypeKind["Type"] = 1] = "Type";
44
- })(CandidateOrTypeKind || (CandidateOrTypeKind = {}));
45
- function getCandidateOrTypeInfo({ invocation, argumentCount }, checker, sourceFile, startingToken, onlyUseSyntacticOwners) {
46
- switch (invocation.kind) {
47
- case 0 /* InvocationKind.Call */: {
48
- if (onlyUseSyntacticOwners && !isSyntacticOwner(startingToken, invocation.node, sourceFile)) {
49
- return undefined;
50
- }
51
- const candidates = [];
52
- const resolvedSignature = checker.getResolvedSignatureForSignatureHelp(invocation.node, candidates, argumentCount);
53
- return candidates.length === 0 ? undefined : { kind: 0 /* CandidateOrTypeKind.Candidate */, candidates, resolvedSignature };
54
- }
55
- case 1 /* InvocationKind.TypeArgs */: {
56
- const { called } = invocation;
57
- if (onlyUseSyntacticOwners && !containsPrecedingToken(startingToken, sourceFile, isIdentifier(called) ? called.parent : called)) {
58
- return undefined;
59
- }
60
- const candidates = getPossibleGenericSignatures(called, argumentCount, checker);
61
- if (candidates.length !== 0)
62
- return { kind: 0 /* CandidateOrTypeKind.Candidate */, candidates, resolvedSignature: first(candidates) };
63
- const symbol = checker.getSymbolAtLocation(called);
64
- return symbol && { kind: 1 /* CandidateOrTypeKind.Type */, symbol };
65
- }
66
- case 2 /* InvocationKind.Contextual */:
67
- return { kind: 0 /* CandidateOrTypeKind.Candidate */, candidates: [invocation.signature], resolvedSignature: invocation.signature };
68
- default:
69
- return Debug.assertNever(invocation);
70
- }
71
- }
72
- /** Na tag, também o `new` (CK-02). */
73
- function isSyntacticOwner(startingToken, node, sourceFile) {
74
- if (!isCallExpression(node))
75
- return false;
76
- const invocationChildren = node.getChildren(sourceFile);
77
- switch (startingToken.kind) {
78
- case SyntaxKind.OpenParenToken:
79
- return contains(invocationChildren, startingToken);
80
- case SyntaxKind.CommaToken: {
81
- const containingList = findContainingList(startingToken);
82
- return !!containingList && contains(invocationChildren, containingList);
83
- }
84
- case SyntaxKind.LessThanToken:
85
- return containsPrecedingToken(startingToken, sourceFile, node.expression);
86
- default:
87
- return false;
88
- }
89
- }
90
- function containsPrecedingToken(startingToken, sourceFile, container) {
91
- const pos = startingToken.getFullStart();
92
- // There’s a possibility that `startingToken.parent` contains only `startingToken` and
93
- // missing nodes, none of which are valid to be returned by `findPrecedingToken`. In that
94
- // case, the preceding token we want is actually higher up the tree—almost definitely the
95
- // next parent, but theoretically the situation with missing nodes might be happening on
96
- // multiple nested levels.
97
- let currentParent = startingToken.parent;
98
- while (currentParent) {
99
- // Na tag, sem o token de um JSDoc (o `excludeJsdoc`, CK-03).
100
- const precedingToken = findPrecedingToken(pos, sourceFile, currentParent);
101
- if (precedingToken) {
102
- return rangeContainsRange(container, precedingToken);
103
- }
104
- currentParent = currentParent.parent;
105
- }
106
- return Debug.fail("Could not find preceding token");
107
- }
108
- export function getArgumentInfoForCompletions(node, position, sourceFile) {
109
- const info = getImmediatelyContainingArgumentInfo(node, position, sourceFile);
110
- return !info || info.isTypeParameterList || info.invocation.kind !== 0 /* InvocationKind.Call */ ? undefined
111
- : { invocation: info.invocation.node, argumentCount: info.argumentCount, argumentIndex: info.argumentIndex };
112
- }
113
- function getArgumentOrParameterListInfo(node, sourceFile) {
114
- const info = getArgumentOrParameterListAndIndex(node, sourceFile);
115
- if (!info)
116
- return undefined;
117
- const { list, argumentIndex } = info;
118
- const argumentCount = getArgumentCount(list);
119
- if (argumentIndex !== 0) {
120
- Debug.assertLessThan(argumentIndex, argumentCount);
121
- }
122
- const argumentsSpan = getApplicableSpanForArguments(list, sourceFile);
123
- return { list, argumentIndex, argumentCount, argumentsSpan };
124
- }
125
- function getArgumentOrParameterListAndIndex(node, sourceFile) {
126
- if (node.kind === SyntaxKind.LessThanToken || node.kind === SyntaxKind.OpenParenToken) {
127
- // Find the list that starts right *after* the < or ( token.
128
- // If the user has just opened a list, consider this item 0.
129
- return { list: getChildListThatStartsWithOpenerToken(node.parent, node, sourceFile), argumentIndex: 0 };
130
- }
131
- else {
132
- // findListItemInfo can return undefined if we are not in parent's argument list
133
- // or type argument list. This includes cases where the cursor is:
134
- // - To the right of the closing parenthesis, non-substitution template, or template tail.
135
- // - Between the type arguments and the arguments (greater than token)
136
- // - On the target of the call (parent.func)
137
- // - On the 'new' keyword in a 'new' expression
138
- const list = findContainingList(node);
139
- return list && { list, argumentIndex: getArgumentIndex(list, node) };
140
- }
141
- }
142
- /**
143
- * A lista de argumentos e o argumento corrente, quando o nó está nos argumentos de uma chamada. A posição só servia, na
144
- * tag, ao template marcado (CK-02).
145
- */
146
- function getImmediatelyContainingArgumentInfo(node, _position, sourceFile) {
147
- const { parent } = node;
148
- // Na tag, também o `new` (CK-02).
149
- if (isCallExpression(parent)) {
150
- const invocation = parent;
151
- // There are 3 cases to handle:
152
- // 1. The token introduces a list, and should begin a signature help session
153
- // 2. The token is either not associated with a list, or ends a list, so the session should end
154
- // 3. The token is buried inside a list, and should give signature help
155
- //
156
- // The following are examples of each:
157
- //
158
- // Case 1:
159
- // foo<#T, U>(#a, b) -> The token introduces a list, and should begin a signature help session
160
- // Case 2:
161
- // fo#o<T, U>#(a, b)# -> The token is either not associated with a list, or ends a list, so the session should end
162
- // Case 3:
163
- // foo<T#, U#>(a#, #b#) -> The token is buried inside a list, and should give signature help
164
- // Find out if 'node' is an argument, a type argument, or neither
165
- const info = getArgumentOrParameterListInfo(node, sourceFile);
166
- if (!info)
167
- return undefined;
168
- const { list, argumentIndex, argumentCount, argumentsSpan } = info;
169
- const isTypeParameterList = !!parent.typeArguments && parent.typeArguments.pos === list.pos;
170
- return { isTypeParameterList, invocation: { kind: 0 /* InvocationKind.Call */, node: invocation }, argumentsSpan, argumentIndex, argumentCount };
171
- }
172
- // Na tag, os três ramos seguintes eram o do tagged template, que a Linguagem não tem (CK-02).
173
- else if (isJsxOpeningLikeElement(parent)) {
174
- // Provide a signature help for JSX opening element or JSX self-closing element.
175
- // This is not guarantee that JSX tag-name is resolved into stateless function component. (that is done in "getSignatureHelpItems")
176
- // i.e
177
- // export function MainButton(props: ButtonProps, context: any): JSX.Element { ... }
178
- // <MainButton /*signatureHelp*/
179
- const attributeSpanStart = parent.attributes.pos;
180
- const attributeSpanEnd = skipTrivia(sourceFile.text, parent.attributes.end, /*stopAfterLineBreak*/ false);
181
- return {
182
- isTypeParameterList: false,
183
- invocation: { kind: 0 /* InvocationKind.Call */, node: parent },
184
- argumentsSpan: createTextSpan(attributeSpanStart, attributeSpanEnd - attributeSpanStart),
185
- argumentIndex: 0,
186
- argumentCount: 1
187
- };
188
- }
189
- else {
190
- const typeArgInfo = getPossibleTypeArgumentsInfo(node, sourceFile);
191
- if (typeArgInfo) {
192
- const { called, nTypeArguments } = typeArgInfo;
193
- const invocation = { kind: 1 /* InvocationKind.TypeArgs */, called };
194
- const argumentsSpan = createTextSpanFromBounds(called.getStart(sourceFile), node.end);
195
- return { isTypeParameterList: true, invocation, argumentsSpan, argumentIndex: nTypeArguments, argumentCount: nTypeArguments + 1 };
196
- }
197
- return undefined;
198
- }
199
- }
200
- function getImmediatelyContainingArgumentOrContextualParameterInfo(node, position, sourceFile, checker) {
201
- return tryGetParameterInfo(node, position, sourceFile, checker) || getImmediatelyContainingArgumentInfo(node, position, sourceFile);
202
- }
203
- function tryGetParameterInfo(startingToken, _position, sourceFile, checker) {
204
- const info = getContextualSignatureLocationInfo(startingToken, sourceFile, checker);
205
- if (!info)
206
- return undefined;
207
- const { contextualType, argumentIndex, argumentCount, argumentsSpan } = info;
208
- const signatures = contextualType.getCallSignatures();
209
- if (signatures.length !== 1)
210
- return undefined;
211
- const invocation = { kind: 2 /* InvocationKind.Contextual */, signature: first(signatures), node: startingToken, symbol: chooseBetterSymbol(contextualType.symbol) };
212
- return { isTypeParameterList: false, invocation, argumentsSpan, argumentIndex, argumentCount };
213
- }
214
- /**
215
- * Os parâmetros de uma arrow que se escreve onde o tipo dela já é esperado. Na tag, também os do método de um object literal
216
- * e os de uma function expression (CK-02), e a expressão de vírgula que a arrow ainda sem o `=>` era (`(a, b`): o parser da
217
- * cópia não a produz, porque o operador vírgula saiu (CK-02).
218
- */
219
- function getContextualSignatureLocationInfo(startingToken, sourceFile, checker) {
220
- if (startingToken.kind !== SyntaxKind.OpenParenToken && startingToken.kind !== SyntaxKind.CommaToken)
221
- return undefined;
222
- const { parent } = startingToken;
223
- switch (parent.kind) {
224
- case SyntaxKind.ParenthesizedExpression:
225
- case SyntaxKind.ArrowFunction:
226
- const info = getArgumentOrParameterListInfo(startingToken, sourceFile);
227
- if (!info)
228
- return undefined;
229
- const { argumentIndex, argumentCount, argumentsSpan } = info;
230
- const contextualType = checker.getContextualType(parent);
231
- return contextualType && { contextualType, argumentIndex, argumentCount, argumentsSpan };
232
- default:
233
- return undefined;
234
- }
235
- }
236
- // The type of a function type node has a symbol at that node, but it's better to use the symbol for a parameter or type alias.
237
- function chooseBetterSymbol(s) {
238
- return s.name === InternalSymbolName.Type
239
- ? firstDefined(s.declarations, d => isFunctionTypeNode(d) ? d.parent.symbol : undefined) || s
240
- : s;
241
- }
242
- function getArgumentIndex(argumentsList, node) {
243
- // The list we got back can include commas. In the presence of errors it may
244
- // also just have nodes without commas. For example "Foo(a b c)" will have 3
245
- // args without commas. We want to find what index we're at. So we count
246
- // forward until we hit ourselves, only incrementing the index if it isn't a
247
- // comma.
248
- //
249
- // Note: the subtlety around trailing commas (in getArgumentCount) does not apply
250
- // here. That's because we're only walking forward until we hit the node we're
251
- // on. In that case, even if we're after the trailing comma, we'll still see
252
- // that trailing comma in the list, and we'll have generated the appropriate
253
- // arg index.
254
- let argumentIndex = 0;
255
- for (const child of argumentsList.getChildren()) {
256
- if (child === node) {
257
- break;
258
- }
259
- if (child.kind !== SyntaxKind.CommaToken) {
260
- argumentIndex++;
261
- }
262
- }
263
- return argumentIndex;
264
- }
265
- function getArgumentCount(argumentsList) {
266
- // The argument count for a list is normally the number of non-comma children it has.
267
- // For example, if you have "Foo(a,b)" then there will be three children of the arg
268
- // list 'a' '<comma>' 'b'. So, in this case the arg count will be 2. However, there
269
- // is a small subtlety. If you have "Foo(a,)", then the child list will just have
270
- // 'a' '<comma>'. So, in the case where the last child is a comma, we increase the
271
- // arg count by one to compensate.
272
- //
273
- // Note: this subtlety only applies to the last comma. If you had "Foo(a,," then
274
- // we'll have: 'a' '<comma>' '<missing>'
275
- // That will give us 2 non-commas. We then add one for the last comma, giving us an
276
- // arg count of 3.
277
- const listChildren = argumentsList.getChildren();
278
- let argumentCount = countWhere(listChildren, arg => arg.kind !== SyntaxKind.CommaToken);
279
- if (listChildren.length > 0 && last(listChildren).kind === SyntaxKind.CommaToken) {
280
- argumentCount++;
281
- }
282
- return argumentCount;
283
- }
284
- function getApplicableSpanForArguments(argumentsList, sourceFile) {
285
- // We use full start and skip trivia on the end because we want to include trivia on
286
- // both sides. For example,
287
- //
288
- // foo( /*comment */ a, b, c /*comment*/ )
289
- // | |
290
- //
291
- // The applicable span is from the first bar to the second bar (inclusive,
292
- // but not including parentheses)
293
- const applicableSpanStart = argumentsList.getFullStart();
294
- const applicableSpanEnd = skipTrivia(sourceFile.text, argumentsList.getEnd(), /*stopAfterLineBreak*/ false);
295
- return createTextSpan(applicableSpanStart, applicableSpanEnd - applicableSpanStart);
296
- }
297
- function getContainingArgumentInfo(node, position, sourceFile, checker, isManuallyInvoked) {
298
- for (let n = node; !isSourceFile(n) && (isManuallyInvoked || !isBlock(n)); n = n.parent) {
299
- // If the node is not a subspan of its parent, this is a big problem.
300
- // There have been crashes that might be caused by this violation.
301
- Debug.assert(rangeContainsRange(n.parent, n), "Not a subspan", () => `Child: ${Debug.formatSyntaxKind(n.kind)}, parent: ${Debug.formatSyntaxKind(n.parent.kind)}`);
302
- const argumentInfo = getImmediatelyContainingArgumentOrContextualParameterInfo(n, position, sourceFile, checker);
303
- if (argumentInfo) {
304
- return argumentInfo;
305
- }
306
- }
307
- return undefined;
308
- }
309
- function getChildListThatStartsWithOpenerToken(parent, openerToken, sourceFile) {
310
- const children = parent.getChildren(sourceFile);
311
- const indexOfOpenerToken = children.indexOf(openerToken);
312
- Debug.assert(indexOfOpenerToken >= 0 && children.length > indexOfOpenerToken + 1);
313
- return children[indexOfOpenerToken + 1];
314
- }
315
- function getExpressionFromInvocation(invocation) {
316
- return invocation.kind === 0 /* InvocationKind.Call */ ? getInvokedExpression(invocation.node) : invocation.called;
317
- }
318
- function getEnclosingDeclarationFromInvocation(invocation) {
319
- return invocation.kind === 0 /* InvocationKind.Call */ ? invocation.node : invocation.kind === 1 /* InvocationKind.TypeArgs */ ? invocation.called : invocation.node;
320
- }
321
- const signatureHelpNodeBuilderFlags = NodeBuilderFlags.OmitParameterModifiers | NodeBuilderFlags.IgnoreErrors | NodeBuilderFlags.UseAliasDefinedOutsideCurrentScope;
322
- function createSignatureHelpItems(candidates, resolvedSignature, { isTypeParameterList, argumentCount, argumentsSpan: applicableSpan, invocation, argumentIndex }, sourceFile, typeChecker) {
323
- const enclosingDeclaration = getEnclosingDeclarationFromInvocation(invocation);
324
- const callTargetSymbol = invocation.kind === 2 /* InvocationKind.Contextual */ ? invocation.symbol : typeChecker.getSymbolAtLocation(getExpressionFromInvocation(invocation));
325
- const callTargetDisplayParts = callTargetSymbol ? symbolToDisplayParts(typeChecker, callTargetSymbol, /*enclosingDeclaration*/ undefined, /*meaning*/ undefined) : emptyArray;
326
- const items = candidates.map(candidateSignature => getSignatureHelpItem(candidateSignature, callTargetDisplayParts, isTypeParameterList, typeChecker, enclosingDeclaration, sourceFile));
327
- if (argumentIndex !== 0) {
328
- Debug.assertLessThan(argumentIndex, argumentCount);
329
- }
330
- const selectedItemIndex = candidates.indexOf(resolvedSignature);
331
- Debug.assert(selectedItemIndex !== -1); // If candidates is non-empty it should always include bestSignature. We check for an empty candidates before calling this function.
332
- return { items, applicableSpan, selectedItemIndex, argumentIndex, argumentCount };
333
- }
334
- function createTypeHelpItems(symbol, { argumentCount, argumentsSpan: applicableSpan, invocation, argumentIndex }, sourceFile, checker) {
335
- const typeParameters = checker.getLocalTypeParametersOfClassOrInterfaceOrTypeAlias(symbol);
336
- if (!typeParameters)
337
- return undefined;
338
- const items = [getTypeHelpItem(symbol, typeParameters, checker, getEnclosingDeclarationFromInvocation(invocation), sourceFile)];
339
- return { items, applicableSpan, selectedItemIndex: 0, argumentIndex, argumentCount };
340
- }
341
- function getTypeHelpItem(symbol, typeParameters, checker, enclosingDeclaration, sourceFile) {
342
- const typeSymbolDisplay = symbolToDisplayParts(checker, symbol);
343
- const printer = createPrinter({ removeComments: true });
344
- const parameters = typeParameters.map(t => createSignatureHelpParameterForTypeParameter(t, checker, enclosingDeclaration, sourceFile, printer));
345
- // Na tag, a documentação e as tags do JSDoc do símbolo. Sem o JSDoc (CK-03), as duas saem vazias, como as de um símbolo
346
- // sem comentário na tag.
347
- const documentation = [];
348
- const tags = [];
349
- const prefixDisplayParts = [...typeSymbolDisplay, punctuationPart(SyntaxKind.LessThanToken)];
350
- return { isVariadic: false, prefixDisplayParts, suffixDisplayParts: [punctuationPart(SyntaxKind.GreaterThanToken)], separatorDisplayParts, parameters, documentation, tags };
351
- }
352
- const separatorDisplayParts = [punctuationPart(SyntaxKind.CommaToken), spacePart()];
353
- function getSignatureHelpItem(candidateSignature, callTargetDisplayParts, isTypeParameterList, checker, enclosingDeclaration, sourceFile) {
354
- const { isVariadic, parameters, prefix, suffix } = (isTypeParameterList ? itemInfoForTypeParameters : itemInfoForParameters)(candidateSignature, checker, enclosingDeclaration, sourceFile);
355
- const prefixDisplayParts = [...callTargetDisplayParts, ...prefix];
356
- const suffixDisplayParts = [...suffix, ...returnTypeToDisplayParts(candidateSignature, enclosingDeclaration, checker)];
357
- // Na tag, a documentação e as tags do JSDoc da assinatura; sem o JSDoc (CK-03), vazias.
358
- const documentation = [];
359
- const tags = [];
360
- return { isVariadic, prefixDisplayParts, suffixDisplayParts, separatorDisplayParts, parameters, documentation, tags };
361
- }
362
- function returnTypeToDisplayParts(candidateSignature, enclosingDeclaration, checker) {
363
- return mapToDisplayParts(writer => {
364
- writer.writePunctuation(":");
365
- writer.writeSpace(" ");
366
- const predicate = checker.getTypePredicateOfSignature(candidateSignature);
367
- if (predicate) {
368
- checker.writeTypePredicate(predicate, enclosingDeclaration, /*flags*/ undefined, writer);
369
- }
370
- else {
371
- checker.writeType(checker.getReturnTypeOfSignature(candidateSignature), enclosingDeclaration, /*flags*/ undefined, writer);
372
- }
373
- });
374
- }
375
- function itemInfoForTypeParameters(candidateSignature, checker, enclosingDeclaration, sourceFile) {
376
- const typeParameters = (candidateSignature.target || candidateSignature).typeParameters;
377
- const printer = createPrinter({ removeComments: true });
378
- const parameters = (typeParameters || emptyArray).map(t => createSignatureHelpParameterForTypeParameter(t, checker, enclosingDeclaration, sourceFile, printer));
379
- const parameterParts = mapToDisplayParts(writer => {
380
- // Na tag, também o parâmetro `this`, antes dos outros (CK-02).
381
- const params = createNodeArray(checker.getExpandedParameters(candidateSignature).map(param => checker.symbolToParameterDeclaration(param, enclosingDeclaration, signatureHelpNodeBuilderFlags)));
382
- printer.writeList(ListFormat.CallExpressionArguments, params, sourceFile, writer);
383
- });
384
- return { isVariadic: false, parameters, prefix: [punctuationPart(SyntaxKind.LessThanToken)], suffix: [punctuationPart(SyntaxKind.GreaterThanToken), ...parameterParts] };
385
- }
386
- function itemInfoForParameters(candidateSignature, checker, enclosingDeclaration, sourceFile) {
387
- const isVariadic = checker.hasEffectiveRestParameter(candidateSignature);
388
- const printer = createPrinter({ removeComments: true });
389
- const typeParameterParts = mapToDisplayParts(writer => {
390
- if (candidateSignature.typeParameters && candidateSignature.typeParameters.length) {
391
- const args = createNodeArray(candidateSignature.typeParameters.map(p => checker.typeParameterToDeclaration(p, enclosingDeclaration, signatureHelpNodeBuilderFlags)));
392
- printer.writeList(ListFormat.TypeParameters, args, sourceFile, writer);
393
- }
394
- });
395
- const parameters = checker.getExpandedParameters(candidateSignature).map(p => createSignatureHelpParameterForParameter(p, checker, enclosingDeclaration, sourceFile, printer));
396
- return { isVariadic, parameters, prefix: [...typeParameterParts, punctuationPart(SyntaxKind.OpenParenToken)], suffix: [punctuationPart(SyntaxKind.CloseParenToken)] };
397
- }
398
- function createSignatureHelpParameterForParameter(parameter, checker, enclosingDeclaration, sourceFile, printer) {
399
- const displayParts = mapToDisplayParts(writer => {
400
- const param = checker.symbolToParameterDeclaration(parameter, enclosingDeclaration, signatureHelpNodeBuilderFlags);
401
- printer.writeNode(EmitHint.Unspecified, param, sourceFile, writer);
402
- });
403
- const isOptional = checker.isOptionalParameter(parameter.valueDeclaration);
404
- // Na tag, a documentação do JSDoc do parâmetro; sem o JSDoc (CK-03), vazia.
405
- return { name: parameter.name, documentation: [], displayParts, isOptional };
406
- }
407
- function createSignatureHelpParameterForTypeParameter(typeParameter, checker, enclosingDeclaration, sourceFile, printer) {
408
- const displayParts = mapToDisplayParts(writer => {
409
- const param = checker.typeParameterToDeclaration(typeParameter, enclosingDeclaration, signatureHelpNodeBuilderFlags);
410
- printer.writeNode(EmitHint.Unspecified, param, sourceFile, writer);
411
- });
412
- // Na tag, a documentação do JSDoc do parâmetro de tipo; sem o JSDoc (CK-03), vazia.
413
- return { name: typeParameter.symbol.name, documentation: [], displayParts, isOptional: false };
414
- }
@@ -1,243 +0,0 @@
1
- // Modificado de microsoft/TypeScript v3.9.10, src/services/smartSelection.ts: o namespace virou módulo ES, com os imports explícitos.
2
- import { Debug, SyntaxKind, compact, contains, createNode, createTextSpanFromBounds, findIndex, getTouchingPropertyName, isBindingElement, isBlock, isImportDeclaration, isMappedTypeNode, isParameter, isPropertySignature, isSourceFile, isStringLiteral, isSyntaxList, isTemplateHead, isTemplateLiteral, isTemplateMiddleOrTemplateTail, isTemplateSpan, isTemplateTail, isVariableDeclaration, isVariableDeclarationList, isVariableStatement, last, positionsAreOnSameLine, textSpanIntersectsWithPosition, textSpansEqual, } from "./_namespaces/ts.js";
3
- export function getSmartSelectionRange(pos, sourceFile) {
4
- let selectionRange = {
5
- textSpan: createTextSpanFromBounds(sourceFile.getFullStart(), sourceFile.getEnd())
6
- };
7
- let parentNode = sourceFile;
8
- outer: while (true) {
9
- const children = getSelectionChildren(parentNode);
10
- if (!children.length)
11
- break;
12
- for (let i = 0; i < children.length; i++) {
13
- const prevNode = children[i - 1];
14
- const node = children[i];
15
- const nextNode = children[i + 1];
16
- if (node.getStart(sourceFile) > pos) {
17
- break outer;
18
- }
19
- if (positionShouldSnapToNode(sourceFile, pos, node)) {
20
- // 1. Blocks are effectively redundant with SyntaxLists.
21
- // 2. TemplateSpans, along with the SyntaxLists containing them, are a somewhat unintuitive grouping
22
- // of things that should be considered independently.
23
- // 3. A VariableStatement’s children are just a VaraiableDeclarationList and a semicolon.
24
- // 4. A lone VariableDeclaration in a VaraibleDeclaration feels redundant with the VariableStatement.
25
- //
26
- // Dive in without pushing a selection range.
27
- if (isBlock(node)
28
- || isTemplateSpan(node) || isTemplateHead(node) || isTemplateTail(node)
29
- || prevNode && isTemplateHead(prevNode)
30
- || isVariableDeclarationList(node) && isVariableStatement(parentNode)
31
- || isSyntaxList(node) && isVariableDeclarationList(parentNode)
32
- || isVariableDeclaration(node) && isSyntaxList(parentNode) && children.length === 1) {
33
- parentNode = node;
34
- break;
35
- }
36
- // Synthesize a stop for '${ ... }' since '${' and '}' actually belong to siblings.
37
- if (isTemplateSpan(parentNode) && nextNode && isTemplateMiddleOrTemplateTail(nextNode)) {
38
- const start = node.getFullStart() - "${".length;
39
- const end = nextNode.getStart() + "}".length;
40
- pushSelectionRange(start, end);
41
- }
42
- // Blocks with braces, brackets, parens, or JSX tags on separate lines should be
43
- // selected from open to close, including whitespace but not including the braces/etc. themselves.
44
- const isBetweenMultiLineBookends = isSyntaxList(node)
45
- && isListOpener(prevNode)
46
- && isListCloser(nextNode)
47
- && !positionsAreOnSameLine(prevNode.getStart(), nextNode.getStart(), sourceFile);
48
- const start = isBetweenMultiLineBookends ? prevNode.getEnd() : node.getStart();
49
- const end = isBetweenMultiLineBookends ? nextNode.getStart() : node.getEnd();
50
- // Na tag, também o trecho do nó com o comentário JSDoc dele (CK-03).
51
- pushSelectionRange(start, end);
52
- // String literals should have a stop both inside and outside their quotes.
53
- if (isStringLiteral(node) || isTemplateLiteral(node)) {
54
- pushSelectionRange(start + 1, end - 1);
55
- }
56
- parentNode = node;
57
- break;
58
- }
59
- // If we made it to the end of the for loop, we’re done.
60
- // In practice, I’ve only seen this happen at the very end
61
- // of a SourceFile.
62
- if (i === children.length - 1) {
63
- break outer;
64
- }
65
- }
66
- }
67
- return selectionRange;
68
- function pushSelectionRange(start, end) {
69
- // Skip empty ranges
70
- if (start !== end) {
71
- const textSpan = createTextSpanFromBounds(start, end);
72
- if (!selectionRange || (
73
- // Skip ranges that are identical to the parent
74
- !textSpansEqual(textSpan, selectionRange.textSpan) &&
75
- // Skip ranges that don’t contain the original position
76
- textSpanIntersectsWithPosition(textSpan, pos))) {
77
- selectionRange = { textSpan, ...selectionRange && { parent: selectionRange } };
78
- }
79
- }
80
- }
81
- }
82
- /**
83
- * Like `ts.positionBelongsToNode`, except positions immediately after nodes
84
- * count too, unless that position belongs to the next node. In effect, makes
85
- * selections able to snap to preceding tokens when the cursor is on the tail
86
- * end of them with only whitespace ahead.
87
- * @param sourceFile The source file containing the nodes.
88
- * @param pos The position to check.
89
- * @param node The candidate node to snap to.
90
- */
91
- function positionShouldSnapToNode(sourceFile, pos, node) {
92
- // Can’t use 'ts.positionBelongsToNode()' here because it cleverly accounts
93
- // for missing nodes, which can’t really be considered when deciding what
94
- // to select.
95
- Debug.assert(node.pos <= pos);
96
- if (pos < node.end) {
97
- return true;
98
- }
99
- const nodeEnd = node.getEnd();
100
- if (nodeEnd === pos) {
101
- return getTouchingPropertyName(sourceFile, pos).pos < node.end;
102
- }
103
- return false;
104
- }
105
- // Na tag, também o `import =` (CK-03).
106
- const isImport = isImportDeclaration;
107
- /**
108
- * Gets the children of a node to be considered for selection ranging,
109
- * transforming them into an artificial tree according to their intuitive
110
- * grouping where no grouping actually exists in the parse tree. For example,
111
- * top-level imports are grouped into their own SyntaxList so they can be
112
- * selected all together, even though in the AST they’re just siblings of each
113
- * other as well as of other top-level statements and declarations.
114
- */
115
- function getSelectionChildren(node) {
116
- // Group top-level imports
117
- if (isSourceFile(node)) {
118
- return groupChildren(node.getChildAt(0).getChildren(), isImport);
119
- }
120
- // Mapped types _look_ like ObjectTypes with a single member,
121
- // but in fact don’t contain a SyntaxList or a node containing
122
- // the “key/value” pair like ObjectTypes do, but it seems intuitive
123
- // that the selection would snap to those points. The philosophy
124
- // of choosing a selection range is not so much about what the
125
- // syntax currently _is_ as what the syntax might easily become
126
- // if the user is making a selection; e.g., we synthesize a selection
127
- // around the “key/value” pair not because there’s a node there, but
128
- // because it allows the mapped type to become an object type with a
129
- // few keystrokes.
130
- if (isMappedTypeNode(node)) {
131
- const [openBraceToken, ...children] = node.getChildren();
132
- const closeBraceToken = Debug.checkDefined(children.pop());
133
- Debug.assertEqual(openBraceToken.kind, SyntaxKind.OpenBraceToken);
134
- Debug.assertEqual(closeBraceToken.kind, SyntaxKind.CloseBraceToken);
135
- // Group `-/+readonly` and `-/+?`
136
- const groupedWithPlusMinusTokens = groupChildren(children, child => child === node.readonlyToken || child.kind === SyntaxKind.ReadonlyKeyword ||
137
- child === node.questionToken || child.kind === SyntaxKind.QuestionToken);
138
- // Group type parameter with surrounding brackets
139
- const groupedWithBrackets = groupChildren(groupedWithPlusMinusTokens, ({ kind }) => kind === SyntaxKind.OpenBracketToken ||
140
- kind === SyntaxKind.TypeParameter ||
141
- kind === SyntaxKind.CloseBracketToken);
142
- return [
143
- openBraceToken,
144
- // Pivot on `:`
145
- createSyntaxList(splitChildren(groupedWithBrackets, ({ kind }) => kind === SyntaxKind.ColonToken)),
146
- closeBraceToken,
147
- ];
148
- }
149
- // Group modifiers and property name, then pivot on `:`.
150
- if (isPropertySignature(node)) {
151
- const children = groupChildren(node.getChildren(), child => child === node.name || contains(node.modifiers, child));
152
- return splitChildren(children, ({ kind }) => kind === SyntaxKind.ColonToken);
153
- }
154
- // Group the parameter name with its `...`, then that group with its `?`, then pivot on `=`.
155
- if (isParameter(node)) {
156
- const groupedDotDotDotAndName = groupChildren(node.getChildren(), child => child === node.dotDotDotToken || child === node.name);
157
- const groupedWithQuestionToken = groupChildren(groupedDotDotDotAndName, child => child === groupedDotDotDotAndName[0] || child === node.questionToken);
158
- return splitChildren(groupedWithQuestionToken, ({ kind }) => kind === SyntaxKind.EqualsToken);
159
- }
160
- // Pivot on '='
161
- if (isBindingElement(node)) {
162
- return splitChildren(node.getChildren(), ({ kind }) => kind === SyntaxKind.EqualsToken);
163
- }
164
- return node.getChildren();
165
- }
166
- /**
167
- * Groups sibling nodes together into their own SyntaxList if they
168
- * a) are adjacent, AND b) match a predicate function.
169
- */
170
- function groupChildren(children, groupOn) {
171
- const result = [];
172
- let group;
173
- for (const child of children) {
174
- if (groupOn(child)) {
175
- group = group || [];
176
- group.push(child);
177
- }
178
- else {
179
- if (group) {
180
- result.push(createSyntaxList(group));
181
- group = undefined;
182
- }
183
- result.push(child);
184
- }
185
- }
186
- if (group) {
187
- result.push(createSyntaxList(group));
188
- }
189
- return result;
190
- }
191
- /**
192
- * Splits sibling nodes into up to four partitions:
193
- * 1) everything left of the first node matched by `pivotOn`,
194
- * 2) the first node matched by `pivotOn`,
195
- * 3) everything right of the first node matched by `pivotOn`,
196
- * 4) a trailing semicolon, if `separateTrailingSemicolon` is enabled.
197
- * The left and right groups, if not empty, will each be grouped into their own containing SyntaxList.
198
- * @param children The sibling nodes to split.
199
- * @param pivotOn The predicate function to match the node to be the pivot. The first node that matches
200
- * the predicate will be used; any others that may match will be included into the right-hand group.
201
- * @param separateTrailingSemicolon If the last token is a semicolon, it will be returned as a separate
202
- * child rather than be included in the right-hand group.
203
- */
204
- function splitChildren(children, pivotOn, separateTrailingSemicolon = true) {
205
- if (children.length < 2) {
206
- return children;
207
- }
208
- const splitTokenIndex = findIndex(children, pivotOn);
209
- if (splitTokenIndex === -1) {
210
- return children;
211
- }
212
- const leftChildren = children.slice(0, splitTokenIndex);
213
- const splitToken = children[splitTokenIndex];
214
- const lastToken = last(children);
215
- const separateLastToken = separateTrailingSemicolon && lastToken.kind === SyntaxKind.SemicolonToken;
216
- const rightChildren = children.slice(splitTokenIndex + 1, separateLastToken ? children.length - 1 : undefined);
217
- const result = compact([
218
- leftChildren.length ? createSyntaxList(leftChildren) : undefined,
219
- splitToken,
220
- rightChildren.length ? createSyntaxList(rightChildren) : undefined,
221
- ]);
222
- return separateLastToken ? result.concat(lastToken) : result;
223
- }
224
- function createSyntaxList(children) {
225
- Debug.assertGreaterThanOrEqual(children.length, 1);
226
- const syntaxList = createNode(SyntaxKind.SyntaxList, children[0].pos, last(children).end);
227
- syntaxList._children = children;
228
- return syntaxList;
229
- }
230
- function isListOpener(token) {
231
- const kind = token && token.kind;
232
- return kind === SyntaxKind.OpenBraceToken
233
- || kind === SyntaxKind.OpenBracketToken
234
- || kind === SyntaxKind.OpenParenToken
235
- || kind === SyntaxKind.JsxOpeningElement;
236
- }
237
- function isListCloser(token) {
238
- const kind = token && token.kind;
239
- return kind === SyntaxKind.CloseBraceToken
240
- || kind === SyntaxKind.CloseBracketToken
241
- || kind === SyntaxKind.CloseParenToken
242
- || kind === SyntaxKind.JsxClosingElement;
243
- }