@tslite/services 0.0.0-stage → 1.12.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 (176) hide show
  1. package/LICENSE +55 -0
  2. package/NOTICE +13 -0
  3. package/dist/_namespaces/edit.d.ts +8 -0
  4. package/dist/_namespaces/edit.js +11 -0
  5. package/dist/_namespaces/ts.Completions.StringCompletions.d.ts +1 -0
  6. package/dist/_namespaces/ts.Completions.StringCompletions.js +2 -0
  7. package/dist/_namespaces/ts.Completions.d.ts +2 -0
  8. package/dist/_namespaces/ts.Completions.js +3 -0
  9. package/dist/_namespaces/ts.FindAllReferences.d.ts +2 -0
  10. package/dist/_namespaces/ts.FindAllReferences.js +3 -0
  11. package/dist/_namespaces/ts.GoToDefinition.d.ts +1 -0
  12. package/dist/_namespaces/ts.GoToDefinition.js +2 -0
  13. package/dist/_namespaces/ts.NavigationBar.d.ts +1 -0
  14. package/dist/_namespaces/ts.NavigationBar.js +2 -0
  15. package/dist/_namespaces/ts.OrganizeImports.d.ts +1 -0
  16. package/dist/_namespaces/ts.OrganizeImports.js +2 -0
  17. package/dist/_namespaces/ts.OutliningElementsCollector.d.ts +1 -0
  18. package/dist/_namespaces/ts.OutliningElementsCollector.js +2 -0
  19. package/dist/_namespaces/ts.Rename.d.ts +1 -0
  20. package/dist/_namespaces/ts.Rename.js +2 -0
  21. package/dist/_namespaces/ts.SignatureHelp.d.ts +1 -0
  22. package/dist/_namespaces/ts.SignatureHelp.js +2 -0
  23. package/dist/_namespaces/ts.SmartSelectionRange.d.ts +1 -0
  24. package/dist/_namespaces/ts.SmartSelectionRange.js +2 -0
  25. package/dist/_namespaces/ts.SymbolDisplay.d.ts +1 -0
  26. package/dist/_namespaces/ts.SymbolDisplay.js +2 -0
  27. package/dist/_namespaces/ts.codefix.d.ts +26 -0
  28. package/dist/_namespaces/ts.codefix.js +27 -0
  29. package/dist/_namespaces/ts.d.ts +17 -0
  30. package/dist/_namespaces/ts.formatting.d.ts +7 -0
  31. package/dist/_namespaces/ts.formatting.js +8 -0
  32. package/dist/_namespaces/ts.js +20 -0
  33. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.d.ts +1 -0
  34. package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +2 -0
  35. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.d.ts +1 -0
  36. package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +2 -0
  37. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.d.ts +1 -0
  38. package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +2 -0
  39. package/dist/_namespaces/ts.refactor.d.ts +9 -0
  40. package/dist/_namespaces/ts.refactor.extractSymbol.d.ts +1 -0
  41. package/dist/_namespaces/ts.refactor.extractSymbol.js +2 -0
  42. package/dist/_namespaces/ts.refactor.js +10 -0
  43. package/dist/_namespaces/ts.textChanges.d.ts +1 -0
  44. package/dist/_namespaces/ts.textChanges.js +2 -0
  45. package/dist/classifier.d.ts +5 -0
  46. package/dist/classifier.js +439 -0
  47. package/dist/codeFixProvider.d.ts +13 -0
  48. package/dist/codeFixProvider.js +84 -0
  49. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +1 -0
  50. package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +21 -0
  51. package/dist/codefixes/addEmptyExportDeclaration.d.ts +1 -0
  52. package/dist/codefixes/addEmptyExportDeclaration.js +17 -0
  53. package/dist/codefixes/addMissingAsync.d.ts +1 -0
  54. package/dist/codefixes/addMissingAsync.js +75 -0
  55. package/dist/codefixes/addMissingAwait.d.ts +1 -0
  56. package/dist/codefixes/addMissingAwait.js +236 -0
  57. package/dist/codefixes/addMissingConst.d.ts +1 -0
  58. package/dist/codefixes/addMissingConst.js +91 -0
  59. package/dist/codefixes/addNameToNamelessParameter.d.ts +1 -0
  60. package/dist/codefixes/addNameToNamelessParameter.js +29 -0
  61. package/dist/codefixes/convertConstToLet.d.ts +1 -0
  62. package/dist/codefixes/convertConstToLet.js +30 -0
  63. package/dist/codefixes/convertToAsyncFunction.d.ts +1 -0
  64. package/dist/codefixes/convertToAsyncFunction.js +495 -0
  65. package/dist/codefixes/convertToMappedObjectType.d.ts +1 -0
  66. package/dist/codefixes/convertToMappedObjectType.js +48 -0
  67. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.d.ts +1 -0
  68. package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +33 -0
  69. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.d.ts +1 -0
  70. package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +27 -0
  71. package/dist/codefixes/fixAwaitInSyncFunction.d.ts +1 -0
  72. package/dist/codefixes/fixAwaitInSyncFunction.js +69 -0
  73. package/dist/codefixes/fixExpectedComma.d.ts +1 -0
  74. package/dist/codefixes/fixExpectedComma.js +35 -0
  75. package/dist/codefixes/fixInvalidJsxCharacters.d.ts +1 -0
  76. package/dist/codefixes/fixInvalidJsxCharacters.js +41 -0
  77. package/dist/codefixes/fixMissingCallParentheses.d.ts +1 -0
  78. package/dist/codefixes/fixMissingCallParentheses.js +42 -0
  79. package/dist/codefixes/fixSpelling.d.ts +1 -0
  80. package/dist/codefixes/fixSpelling.js +94 -0
  81. package/dist/codefixes/fixUnreachableCode.d.ts +1 -0
  82. package/dist/codefixes/fixUnreachableCode.js +65 -0
  83. package/dist/codefixes/fixUnusedIdentifier.d.ts +1 -0
  84. package/dist/codefixes/fixUnusedIdentifier.js +224 -0
  85. package/dist/codefixes/helpers.d.ts +8 -0
  86. package/dist/codefixes/helpers.js +53 -0
  87. package/dist/codefixes/importFixes.d.ts +14 -0
  88. package/dist/codefixes/importFixes.js +441 -0
  89. package/dist/codefixes/inferFromUsage.d.ts +1 -0
  90. package/dist/codefixes/inferFromUsage.js +742 -0
  91. package/dist/codefixes/removeUnnecessaryAwait.d.ts +1 -0
  92. package/dist/codefixes/removeUnnecessaryAwait.js +41 -0
  93. package/dist/codefixes/returnValueCorrect.d.ts +1 -0
  94. package/dist/codefixes/returnValueCorrect.js +132 -0
  95. package/dist/codefixes/splitTypeOnlyImport.d.ts +1 -0
  96. package/dist/codefixes/splitTypeOnlyImport.js +32 -0
  97. package/dist/codefixes/useBigintLiteral.d.ts +1 -0
  98. package/dist/codefixes/useBigintLiteral.js +29 -0
  99. package/dist/completions.d.ts +83 -0
  100. package/dist/completions.js +1720 -0
  101. package/dist/documentHighlights.d.ts +8 -0
  102. package/dist/documentHighlights.js +367 -0
  103. package/dist/documentRegistry.d.ts +36 -0
  104. package/dist/documentRegistry.js +63 -0
  105. package/dist/editingServices.d.ts +1 -0
  106. package/dist/editingServices.js +4 -0
  107. package/dist/findAllReferences.d.ts +113 -0
  108. package/dist/findAllReferences.js +1366 -0
  109. package/dist/formatting/formatting.d.ts +26 -0
  110. package/dist/formatting/formatting.js +1021 -0
  111. package/dist/formatting/formattingContext.d.ts +34 -0
  112. package/dist/formatting/formattingContext.js +78 -0
  113. package/dist/formatting/formattingScanner.d.ts +14 -0
  114. package/dist/formatting/formattingScanner.js +228 -0
  115. package/dist/formatting/rule.d.ts +31 -0
  116. package/dist/formatting/rule.js +22 -0
  117. package/dist/formatting/rules.d.ts +7 -0
  118. package/dist/formatting/rules.js +610 -0
  119. package/dist/formatting/rulesMap.d.ts +5 -0
  120. package/dist/formatting/rulesMap.js +127 -0
  121. package/dist/formatting/smartIndenter.d.ts +44 -0
  122. package/dist/formatting/smartIndenter.js +518 -0
  123. package/dist/getEditsForFileRename.d.ts +6 -0
  124. package/dist/getEditsForFileRename.js +86 -0
  125. package/dist/goToDefinition.d.ts +8 -0
  126. package/dist/goToDefinition.js +246 -0
  127. package/dist/importTracker.d.ts +50 -0
  128. package/dist/importTracker.js +422 -0
  129. package/dist/index.d.ts +1 -0
  130. package/dist/index.js +3 -0
  131. package/dist/navigationBar.d.ts +3 -0
  132. package/dist/navigationBar.js +549 -0
  133. package/dist/organizeImports.d.ts +18 -0
  134. package/dist/organizeImports.js +290 -0
  135. package/dist/outliningElementsCollector.d.ts +2 -0
  136. package/dist/outliningElementsCollector.js +261 -0
  137. package/dist/refactorProvider.d.ts +5 -0
  138. package/dist/refactorProvider.js +16 -0
  139. package/dist/refactors/addOrRemoveBracesToArrowFunction.d.ts +1 -0
  140. package/dist/refactors/addOrRemoveBracesToArrowFunction.js +86 -0
  141. package/dist/refactors/convertExport.d.ts +1 -0
  142. package/dist/refactors/convertExport.js +126 -0
  143. package/dist/refactors/convertImport.d.ts +1 -0
  144. package/dist/refactors/convertImport.js +116 -0
  145. package/dist/refactors/convertParamsToDestructuredObject.d.ts +1 -0
  146. package/dist/refactors/convertParamsToDestructuredObject.js +282 -0
  147. package/dist/refactors/convertStringOrTemplateLiteral.d.ts +1 -0
  148. package/dist/refactors/convertStringOrTemplateLiteral.js +148 -0
  149. package/dist/refactors/extractSymbol.d.ts +60 -0
  150. package/dist/refactors/extractSymbol.js +1281 -0
  151. package/dist/refactors/extractType.d.ts +1 -0
  152. package/dist/refactors/extractType.js +102 -0
  153. package/dist/refactors/moveToNewFile.d.ts +1 -0
  154. package/dist/refactors/moveToNewFile.js +477 -0
  155. package/dist/rename.d.ts +2 -0
  156. package/dist/rename.js +100 -0
  157. package/dist/services.d.ts +48 -0
  158. package/dist/services.js +1480 -0
  159. package/dist/signatureHelp.d.ts +8 -0
  160. package/dist/signatureHelp.js +414 -0
  161. package/dist/smartSelection.d.ts +2 -0
  162. package/dist/smartSelection.js +243 -0
  163. package/dist/stringCompletions.d.ts +4 -0
  164. package/dist/stringCompletions.js +220 -0
  165. package/dist/suggestionDiagnostics.d.ts +6 -0
  166. package/dist/suggestionDiagnostics.js +92 -0
  167. package/dist/symbolDisplay.d.ts +16 -0
  168. package/dist/symbolDisplay.js +400 -0
  169. package/dist/textChanges.d.ts +161 -0
  170. package/dist/textChanges.js +1163 -0
  171. package/dist/types.d.ts +908 -0
  172. package/dist/types.js +263 -0
  173. package/dist/utilities.d.ts +283 -0
  174. package/dist/utilities.js +1981 -0
  175. package/package.json +45 -3
  176. package/README.md +0 -3
@@ -0,0 +1,8 @@
1
+ import type { CancellationToken, CheckResult, HighlightSpan, SourceFile } from "./_namespaces/ts.js";
2
+ export interface DocumentHighlights {
3
+ fileName: string;
4
+ highlightSpans: HighlightSpan[];
5
+ }
6
+ export declare namespace DocumentHighlights {
7
+ function getDocumentHighlights(program: CheckResult, cancellationToken: CancellationToken, sourceFile: SourceFile, position: number, sourceFilesToSearch: readonly SourceFile[]): DocumentHighlights[] | undefined;
8
+ }
@@ -0,0 +1,367 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/documentHighlights.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, FindAllReferences, SyntaxKind, arrayFrom, arrayToMultiMap, arrayToSet, cast, concatenate, contains, createTextSpanFromBounds, createTextSpanFromNode, findAncestor, findChildOfKind, findModifier, forEach, forEachChild, forEachReturnStatement, getContainingFunction, getTouchingPropertyName, isAwaitExpression, isBlock, isBreakOrContinueStatement, isCaseClause, isDeclaration, isDefaultClause, isFunctionBlock, isFunctionLike, isIfStatement, isIterationStatement, isJsxClosingElement, isJsxOpeningElement, isModifierKind, isModuleDeclaration, isReturnStatement, isSwitchStatement, isThrowStatement, isTryStatement, isTypeAliasDeclaration, isTypeNode, isVariableStatement, isWhiteSpaceSingleLine, mapDefined, modifierToFlag, toArray, } from "./_namespaces/ts.js";
3
+ export var DocumentHighlights;
4
+ (function (DocumentHighlights) {
5
+ function getDocumentHighlights(program, cancellationToken, sourceFile, position, sourceFilesToSearch) {
6
+ const node = getTouchingPropertyName(sourceFile, position);
7
+ if (node.parent && (isJsxOpeningElement(node.parent) && node.parent.tagName === node || isJsxClosingElement(node.parent))) {
8
+ // For a JSX element, just highlight the matching tag, not all references.
9
+ const { openingElement, closingElement } = node.parent.parent;
10
+ const highlightSpans = [openingElement, closingElement].map(({ tagName }) => getHighlightSpanForNode(tagName, sourceFile));
11
+ return [{ fileName: sourceFile.fileName, highlightSpans }];
12
+ }
13
+ return getSemanticDocumentHighlights(position, node, program, cancellationToken, sourceFilesToSearch) || getSyntacticDocumentHighlights(node, sourceFile);
14
+ }
15
+ DocumentHighlights.getDocumentHighlights = getDocumentHighlights;
16
+ function getHighlightSpanForNode(node, sourceFile) {
17
+ return {
18
+ fileName: sourceFile.fileName,
19
+ textSpan: createTextSpanFromNode(node, sourceFile),
20
+ kind: "none" /* HighlightSpanKind.none */
21
+ };
22
+ }
23
+ function getSemanticDocumentHighlights(position, node, program, cancellationToken, sourceFilesToSearch) {
24
+ const sourceFilesSet = arrayToSet(sourceFilesToSearch, f => f.fileName);
25
+ const referenceEntries = FindAllReferences.getReferenceEntriesForNode(position, node, program, sourceFilesToSearch, cancellationToken, /*options*/ undefined, sourceFilesSet);
26
+ if (!referenceEntries)
27
+ return undefined;
28
+ const map = arrayToMultiMap(referenceEntries.map(FindAllReferences.toHighlightSpan), e => e.fileName, e => e.span);
29
+ // Na tag, o arquivo fora dos pesquisados era o redirecionado por um pacote, que o `Program` criava (o host, CK-47).
30
+ return arrayFrom(map.entries(), ([fileName, highlightSpans]) => ({ fileName, highlightSpans }));
31
+ }
32
+ function getSyntacticDocumentHighlights(node, sourceFile) {
33
+ const highlightSpans = getHighlightSpans(node, sourceFile);
34
+ return highlightSpans && [{ fileName: sourceFile.fileName, highlightSpans }];
35
+ }
36
+ function getHighlightSpans(node, sourceFile) {
37
+ switch (node.kind) {
38
+ case SyntaxKind.IfKeyword:
39
+ case SyntaxKind.ElseKeyword:
40
+ return isIfStatement(node.parent) ? getIfElseOccurrences(node.parent, sourceFile) : undefined;
41
+ case SyntaxKind.ReturnKeyword:
42
+ return useParent(node.parent, isReturnStatement, getReturnOccurrences);
43
+ case SyntaxKind.ThrowKeyword:
44
+ return useParent(node.parent, isThrowStatement, getThrowOccurrences);
45
+ case SyntaxKind.TryKeyword:
46
+ case SyntaxKind.CatchKeyword:
47
+ case SyntaxKind.FinallyKeyword:
48
+ const tryStatement = node.kind === SyntaxKind.CatchKeyword ? node.parent.parent : node.parent;
49
+ return useParent(tryStatement, isTryStatement, getTryCatchFinallyOccurrences);
50
+ case SyntaxKind.SwitchKeyword:
51
+ return useParent(node.parent, isSwitchStatement, getSwitchCaseDefaultOccurrences);
52
+ case SyntaxKind.CaseKeyword:
53
+ case SyntaxKind.DefaultKeyword: {
54
+ if (isDefaultClause(node.parent) || isCaseClause(node.parent)) {
55
+ return useParent(node.parent.parent.parent, isSwitchStatement, getSwitchCaseDefaultOccurrences);
56
+ }
57
+ return undefined;
58
+ }
59
+ case SyntaxKind.BreakKeyword:
60
+ case SyntaxKind.ContinueKeyword:
61
+ return useParent(node.parent, isBreakOrContinueStatement, getBreakOrContinueStatementOccurrences);
62
+ case SyntaxKind.ForKeyword:
63
+ case SyntaxKind.WhileKeyword:
64
+ case SyntaxKind.DoKeyword:
65
+ // Na tag, o laço com label também (CK-02).
66
+ return useParent(node.parent, (n) => isIterationStatement(n), getLoopBreakContinueOccurrences);
67
+ // Na tag, também o `constructor`, o `get` e o `set` de todas as declarações do símbolo, e o `yield` da função
68
+ // (CK-02, CK-56).
69
+ case SyntaxKind.AwaitKeyword:
70
+ return useParent(node.parent, isAwaitExpression, getAsyncAndAwaitOccurrences);
71
+ case SyntaxKind.AsyncKeyword:
72
+ return highlightSpans(getAsyncAndAwaitOccurrences(node));
73
+ default:
74
+ return isModifierKind(node.kind) && (isDeclaration(node.parent) || isVariableStatement(node.parent))
75
+ ? highlightSpans(getModifierOccurrences(node.kind, node.parent))
76
+ : undefined;
77
+ }
78
+ function useParent(node, nodeTest, getNodes) {
79
+ return nodeTest(node) ? highlightSpans(getNodes(node, sourceFile)) : undefined;
80
+ }
81
+ function highlightSpans(nodes) {
82
+ return nodes && nodes.map(node => getHighlightSpanForNode(node, sourceFile));
83
+ }
84
+ }
85
+ /**
86
+ * Aggregates all throw-statements within this node *without* crossing
87
+ * into function boundaries and try-blocks with catch-clauses.
88
+ */
89
+ function aggregateOwnedThrowStatements(node) {
90
+ if (isThrowStatement(node)) {
91
+ return [node];
92
+ }
93
+ else if (isTryStatement(node)) {
94
+ // Exceptions thrown within a try block lacking a catch clause are "owned" in the current context.
95
+ return concatenate(node.catchClause ? aggregateOwnedThrowStatements(node.catchClause) : node.tryBlock && aggregateOwnedThrowStatements(node.tryBlock), node.finallyBlock && aggregateOwnedThrowStatements(node.finallyBlock));
96
+ }
97
+ // Do not cross function boundaries.
98
+ return isFunctionLike(node) ? undefined : flatMapChildren(node, aggregateOwnedThrowStatements);
99
+ }
100
+ /**
101
+ * For lack of a better name, this function takes a throw statement and returns the
102
+ * nearest ancestor that is a try-block (whose try statement has a catch clause),
103
+ * function-block, or source file.
104
+ */
105
+ function getThrowStatementOwner(throwStatement) {
106
+ let child = throwStatement;
107
+ while (child.parent) {
108
+ const parent = child.parent;
109
+ if (isFunctionBlock(parent) || parent.kind === SyntaxKind.SourceFile) {
110
+ return parent;
111
+ }
112
+ // A throw-statement is only owned by a try-statement if the try-statement has
113
+ // a catch clause, and if the throw-statement occurs within the try block.
114
+ if (isTryStatement(parent) && parent.tryBlock === child && parent.catchClause) {
115
+ return child;
116
+ }
117
+ child = parent;
118
+ }
119
+ return undefined;
120
+ }
121
+ function aggregateAllBreakAndContinueStatements(node) {
122
+ return isBreakOrContinueStatement(node) ? [node] : isFunctionLike(node) ? undefined : flatMapChildren(node, aggregateAllBreakAndContinueStatements);
123
+ }
124
+ function flatMapChildren(node, cb) {
125
+ const result = [];
126
+ node.forEachChild(child => {
127
+ const value = cb(child);
128
+ if (value !== undefined) {
129
+ result.push(...toArray(value));
130
+ }
131
+ });
132
+ return result;
133
+ }
134
+ function ownsBreakOrContinueStatement(owner, statement) {
135
+ const actualOwner = getBreakOrContinueOwner(statement);
136
+ return !!actualOwner && actualOwner === owner;
137
+ }
138
+ function getBreakOrContinueOwner(statement) {
139
+ return findAncestor(statement, node => {
140
+ switch (node.kind) {
141
+ case SyntaxKind.SwitchStatement:
142
+ if (statement.kind === SyntaxKind.ContinueStatement) {
143
+ return false;
144
+ }
145
+ // falls through
146
+ case SyntaxKind.ForStatement:
147
+ case SyntaxKind.ForInStatement:
148
+ case SyntaxKind.ForOfStatement:
149
+ case SyntaxKind.WhileStatement:
150
+ case SyntaxKind.DoStatement:
151
+ // Na tag, o `break` e o `continue` com label só eram do laço do label (CK-02).
152
+ return true;
153
+ default:
154
+ // Não atravessa a fronteira de uma função.
155
+ return isFunctionLike(node) && "quit";
156
+ }
157
+ });
158
+ }
159
+ function getModifierOccurrences(modifier, declaration) {
160
+ return mapDefined(getNodesToSearchForModifier(declaration, modifierToFlag(modifier)), node => findModifier(node, modifier));
161
+ }
162
+ /**
163
+ * Os nós em que se procura o mesmo modificador: os statements em volta, ou os membros do type literal. Na tag, também
164
+ * os parâmetros e os membros da classe, do construtor, do método e da `function`, os da interface, o `abstract` e
165
+ * os parâmetros do construtor de um modificador de acesso (CK-02).
166
+ */
167
+ function getNodesToSearchForModifier(declaration, _modifierFlag) {
168
+ const container = declaration.parent;
169
+ switch (container.kind) {
170
+ case SyntaxKind.ModuleBlock:
171
+ case SyntaxKind.SourceFile:
172
+ case SyntaxKind.Block:
173
+ case SyntaxKind.CaseClause:
174
+ case SyntaxKind.DefaultClause:
175
+ return container.statements;
176
+ case SyntaxKind.TypeLiteral:
177
+ return container.members;
178
+ default:
179
+ Debug.assertNever(container, "Invalid container kind.");
180
+ }
181
+ }
182
+ function pushKeywordIf(keywordList, token, ...expected) {
183
+ if (token && contains(expected, token.kind)) {
184
+ keywordList.push(token);
185
+ return true;
186
+ }
187
+ return false;
188
+ }
189
+ function getLoopBreakContinueOccurrences(loopNode) {
190
+ const keywords = [];
191
+ if (pushKeywordIf(keywords, loopNode.getFirstToken(), SyntaxKind.ForKeyword, SyntaxKind.WhileKeyword, SyntaxKind.DoKeyword)) {
192
+ // If we succeeded and got a do-while loop, then start looking for a 'while' keyword.
193
+ if (loopNode.kind === SyntaxKind.DoStatement) {
194
+ const loopTokens = loopNode.getChildren();
195
+ for (let i = loopTokens.length - 1; i >= 0; i--) {
196
+ if (pushKeywordIf(keywords, loopTokens[i], SyntaxKind.WhileKeyword)) {
197
+ break;
198
+ }
199
+ }
200
+ }
201
+ }
202
+ forEach(aggregateAllBreakAndContinueStatements(loopNode.statement), statement => {
203
+ if (ownsBreakOrContinueStatement(loopNode, statement)) {
204
+ pushKeywordIf(keywords, statement.getFirstToken(), SyntaxKind.BreakKeyword, SyntaxKind.ContinueKeyword);
205
+ }
206
+ });
207
+ return keywords;
208
+ }
209
+ function getBreakOrContinueStatementOccurrences(breakOrContinueStatement) {
210
+ const owner = getBreakOrContinueOwner(breakOrContinueStatement);
211
+ if (owner) {
212
+ switch (owner.kind) {
213
+ case SyntaxKind.ForStatement:
214
+ case SyntaxKind.ForInStatement:
215
+ case SyntaxKind.ForOfStatement:
216
+ case SyntaxKind.DoStatement:
217
+ case SyntaxKind.WhileStatement:
218
+ return getLoopBreakContinueOccurrences(owner);
219
+ case SyntaxKind.SwitchStatement:
220
+ return getSwitchCaseDefaultOccurrences(owner);
221
+ }
222
+ }
223
+ return undefined;
224
+ }
225
+ function getSwitchCaseDefaultOccurrences(switchStatement) {
226
+ const keywords = [];
227
+ pushKeywordIf(keywords, switchStatement.getFirstToken(), SyntaxKind.SwitchKeyword);
228
+ // Go through each clause in the switch statement, collecting the 'case'/'default' keywords.
229
+ forEach(switchStatement.caseBlock.clauses, clause => {
230
+ pushKeywordIf(keywords, clause.getFirstToken(), SyntaxKind.CaseKeyword, SyntaxKind.DefaultKeyword);
231
+ forEach(aggregateAllBreakAndContinueStatements(clause), statement => {
232
+ if (ownsBreakOrContinueStatement(switchStatement, statement)) {
233
+ pushKeywordIf(keywords, statement.getFirstToken(), SyntaxKind.BreakKeyword);
234
+ }
235
+ });
236
+ });
237
+ return keywords;
238
+ }
239
+ function getTryCatchFinallyOccurrences(tryStatement, sourceFile) {
240
+ const keywords = [];
241
+ pushKeywordIf(keywords, tryStatement.getFirstToken(), SyntaxKind.TryKeyword);
242
+ if (tryStatement.catchClause) {
243
+ pushKeywordIf(keywords, tryStatement.catchClause.getFirstToken(), SyntaxKind.CatchKeyword);
244
+ }
245
+ if (tryStatement.finallyBlock) {
246
+ const finallyKeyword = findChildOfKind(tryStatement, SyntaxKind.FinallyKeyword, sourceFile);
247
+ pushKeywordIf(keywords, finallyKeyword, SyntaxKind.FinallyKeyword);
248
+ }
249
+ return keywords;
250
+ }
251
+ function getThrowOccurrences(throwStatement, sourceFile) {
252
+ const owner = getThrowStatementOwner(throwStatement);
253
+ if (!owner) {
254
+ return undefined;
255
+ }
256
+ const keywords = [];
257
+ forEach(aggregateOwnedThrowStatements(owner), throwStatement => {
258
+ keywords.push(findChildOfKind(throwStatement, SyntaxKind.ThrowKeyword, sourceFile));
259
+ });
260
+ // If the "owner" is a function, then we equate 'return' and 'throw' statements in their
261
+ // ability to "jump out" of the function, and include occurrences for both.
262
+ if (isFunctionBlock(owner)) {
263
+ forEachReturnStatement(owner, returnStatement => {
264
+ keywords.push(findChildOfKind(returnStatement, SyntaxKind.ReturnKeyword, sourceFile));
265
+ });
266
+ }
267
+ return keywords;
268
+ }
269
+ function getReturnOccurrences(returnStatement, sourceFile) {
270
+ const func = getContainingFunction(returnStatement);
271
+ if (!func) {
272
+ return undefined;
273
+ }
274
+ const keywords = [];
275
+ forEachReturnStatement(cast(func.body, isBlock), returnStatement => {
276
+ keywords.push(findChildOfKind(returnStatement, SyntaxKind.ReturnKeyword, sourceFile));
277
+ });
278
+ // Include 'throw' statements that do not occur within a try block.
279
+ forEach(aggregateOwnedThrowStatements(func.body), throwStatement => {
280
+ keywords.push(findChildOfKind(throwStatement, SyntaxKind.ThrowKeyword, sourceFile));
281
+ });
282
+ return keywords;
283
+ }
284
+ function getAsyncAndAwaitOccurrences(node) {
285
+ const func = getContainingFunction(node);
286
+ if (!func) {
287
+ return undefined;
288
+ }
289
+ const keywords = [];
290
+ if (func.modifiers) {
291
+ func.modifiers.forEach(modifier => {
292
+ pushKeywordIf(keywords, modifier, SyntaxKind.AsyncKeyword);
293
+ });
294
+ }
295
+ forEachChild(func, child => {
296
+ traverseWithoutCrossingFunction(child, node => {
297
+ if (isAwaitExpression(node)) {
298
+ pushKeywordIf(keywords, node.getFirstToken(), SyntaxKind.AwaitKeyword);
299
+ }
300
+ });
301
+ });
302
+ return keywords;
303
+ }
304
+ // Não atravessa a fronteira de uma função, de um namespace ou de um tipo. Na tag, também a da classe e a da interface
305
+ // (CK-02), e o `yield` de um generator tinha a mesma travessia (o `getYieldOccurrences`, CK-02).
306
+ function traverseWithoutCrossingFunction(node, cb) {
307
+ cb(node);
308
+ if (!isFunctionLike(node) && !isModuleDeclaration(node) && !isTypeAliasDeclaration(node) && !isTypeNode(node)) {
309
+ forEachChild(node, child => traverseWithoutCrossingFunction(child, cb));
310
+ }
311
+ }
312
+ function getIfElseOccurrences(ifStatement, sourceFile) {
313
+ const keywords = getIfElseKeywords(ifStatement, sourceFile);
314
+ const result = [];
315
+ // We'd like to highlight else/ifs together if they are only separated by whitespace
316
+ // (i.e. the keywords are separated by no comments, no newlines).
317
+ for (let i = 0; i < keywords.length; i++) {
318
+ if (keywords[i].kind === SyntaxKind.ElseKeyword && i < keywords.length - 1) {
319
+ const elseKeyword = keywords[i];
320
+ const ifKeyword = keywords[i + 1]; // this *should* always be an 'if' keyword.
321
+ let shouldCombineElseAndIf = true;
322
+ // Avoid recalculating getStart() by iterating backwards.
323
+ for (let j = ifKeyword.getStart(sourceFile) - 1; j >= elseKeyword.end; j--) {
324
+ if (!isWhiteSpaceSingleLine(sourceFile.text.charCodeAt(j))) {
325
+ shouldCombineElseAndIf = false;
326
+ break;
327
+ }
328
+ }
329
+ if (shouldCombineElseAndIf) {
330
+ result.push({
331
+ fileName: sourceFile.fileName,
332
+ textSpan: createTextSpanFromBounds(elseKeyword.getStart(), ifKeyword.end),
333
+ kind: "reference" /* HighlightSpanKind.reference */
334
+ });
335
+ i++; // skip the next keyword
336
+ continue;
337
+ }
338
+ }
339
+ // Ordinary case: just highlight the keyword.
340
+ result.push(getHighlightSpanForNode(keywords[i], sourceFile));
341
+ }
342
+ return result;
343
+ }
344
+ function getIfElseKeywords(ifStatement, sourceFile) {
345
+ const keywords = [];
346
+ // Traverse upwards through all parent if-statements linked by their else-branches.
347
+ while (isIfStatement(ifStatement.parent) && ifStatement.parent.elseStatement === ifStatement) {
348
+ ifStatement = ifStatement.parent;
349
+ }
350
+ // Now traverse back down through the else branches, aggregating if/else keywords of if-statements.
351
+ while (true) {
352
+ const children = ifStatement.getChildren(sourceFile);
353
+ pushKeywordIf(keywords, children[0], SyntaxKind.IfKeyword);
354
+ // Generally the 'else' keyword is second-to-last, so we traverse backwards.
355
+ for (let i = children.length - 1; i >= 0; i--) {
356
+ if (pushKeywordIf(keywords, children[i], SyntaxKind.ElseKeyword)) {
357
+ break;
358
+ }
359
+ }
360
+ if (!ifStatement.elseStatement || !isIfStatement(ifStatement.elseStatement)) {
361
+ break;
362
+ }
363
+ ifStatement = ifStatement.elseStatement;
364
+ }
365
+ return keywords;
366
+ }
367
+ })(DocumentHighlights || (DocumentHighlights = {}));
@@ -0,0 +1,36 @@
1
+ import type { IScriptSnapshot, Path, ScriptKind, SourceFile } from "./_namespaces/ts.js";
2
+ /**
3
+ * O registro de documentos guarda os `SourceFile` que várias instâncias do language service compartilham: cada uma
4
+ * segura as árvores dos arquivos do seu programa, e as árvores são quase toda a memória que ele ocupa. Com um registro
5
+ * só para todas, elas compartilham pelo menos a lib. Para criar um, `createDocumentRegistry`, passado a cada
6
+ * `createLanguageService`.
7
+ *
8
+ * Na tag, o registro separa as árvores por chave de opções de compilação, porque o alvo muda a forma da árvore. A
9
+ * configuração é fixa (CK-06), e há uma chave só: o registro é um mapa de caminho para árvore.
10
+ */
11
+ export interface DocumentRegistry {
12
+ /**
13
+ * A árvore guardada do arquivo `fileName`. A primeira aquisição a cria (`createLanguageServiceSourceFile`); as
14
+ * seguintes contam mais um usuário dela.
15
+ *
16
+ * @param scriptSnapshot o texto do arquivo; só se usa quando a árvore ainda não está no registro
17
+ * @param version a versão do arquivo; idem
18
+ */
19
+ acquireDocument(fileName: string, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
20
+ acquireDocumentWithKey(fileName: string, path: Path, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
21
+ /**
22
+ * A versão nova de uma árvore que já está no registro. A atualização chama o `updateLanguageServiceSourceFile`,
23
+ * que reparseia só o trecho que mudou quando o snapshot diz qual foi.
24
+ *
25
+ * @param scriptSnapshot o texto do arquivo
26
+ * @param version a versão do arquivo
27
+ */
28
+ updateDocument(fileName: string, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
29
+ updateDocumentWithKey(fileName: string, path: Path, scriptSnapshot: IScriptSnapshot, version: string, scriptKind?: ScriptKind): SourceFile;
30
+ /**
31
+ * Avisa que um usuário não precisa mais da árvore do arquivo. Só se libera a árvore que veio deste registro.
32
+ */
33
+ releaseDocument(fileName: string): void;
34
+ releaseDocumentWithKey(path: Path): void;
35
+ }
36
+ export declare function createDocumentRegistry(useCaseSensitiveFileNames?: boolean, currentDirectory?: string): DocumentRegistry;
@@ -0,0 +1,63 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/documentRegistry.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Debug, ScriptTarget, createGetCanonicalFileName, createLanguageServiceSourceFile, createMap, toPath, updateLanguageServiceSourceFile, } from "./_namespaces/ts.js";
3
+ export function createDocumentRegistry(useCaseSensitiveFileNames, currentDirectory = "") {
4
+ const entries = createMap();
5
+ const getCanonicalFileName = createGetCanonicalFileName(!!useCaseSensitiveFileNames);
6
+ function acquireDocument(fileName, scriptSnapshot, version, scriptKind) {
7
+ const path = toPath(fileName, currentDirectory, getCanonicalFileName);
8
+ return acquireDocumentWithKey(fileName, path, scriptSnapshot, version, scriptKind);
9
+ }
10
+ function acquireDocumentWithKey(fileName, path, scriptSnapshot, version, scriptKind) {
11
+ return acquireOrUpdateDocument(fileName, path, scriptSnapshot, version, /*acquiring*/ true, scriptKind);
12
+ }
13
+ function updateDocument(fileName, scriptSnapshot, version, scriptKind) {
14
+ const path = toPath(fileName, currentDirectory, getCanonicalFileName);
15
+ return updateDocumentWithKey(fileName, path, scriptSnapshot, version, scriptKind);
16
+ }
17
+ function updateDocumentWithKey(fileName, path, scriptSnapshot, version, scriptKind) {
18
+ return acquireOrUpdateDocument(fileName, path, scriptSnapshot, version, /*acquiring*/ false, scriptKind);
19
+ }
20
+ function acquireOrUpdateDocument(fileName, path, scriptSnapshot, version, acquiring, scriptKind) {
21
+ let entry = entries.get(path);
22
+ // O alvo da configuração fixa (CK-24).
23
+ const scriptTarget = ScriptTarget.ES2020;
24
+ if (!entry) {
25
+ const sourceFile = createLanguageServiceSourceFile(fileName, scriptSnapshot, scriptTarget, version, /*setNodeParents*/ false, scriptKind);
26
+ entry = {
27
+ sourceFile,
28
+ languageServiceRefCount: 1,
29
+ };
30
+ entries.set(path, entry);
31
+ }
32
+ else {
33
+ if (entry.sourceFile.version !== version) {
34
+ entry.sourceFile = updateLanguageServiceSourceFile(entry.sourceFile, scriptSnapshot, version, scriptSnapshot.getChangeRange(entry.sourceFile.scriptSnapshot));
35
+ }
36
+ if (acquiring) {
37
+ entry.languageServiceRefCount++;
38
+ }
39
+ }
40
+ Debug.assert(entry.languageServiceRefCount !== 0);
41
+ return entry.sourceFile;
42
+ }
43
+ function releaseDocument(fileName) {
44
+ const path = toPath(fileName, currentDirectory, getCanonicalFileName);
45
+ return releaseDocumentWithKey(path);
46
+ }
47
+ function releaseDocumentWithKey(path) {
48
+ const entry = Debug.checkDefined(entries.get(path));
49
+ entry.languageServiceRefCount--;
50
+ Debug.assert(entry.languageServiceRefCount >= 0);
51
+ if (entry.languageServiceRefCount === 0) {
52
+ entries.delete(path);
53
+ }
54
+ }
55
+ return {
56
+ acquireDocument,
57
+ acquireDocumentWithKey,
58
+ updateDocument,
59
+ updateDocumentWithKey,
60
+ releaseDocument,
61
+ releaseDocumentWithKey,
62
+ };
63
+ }
@@ -0,0 +1 @@
1
+ export {};
@@ -0,0 +1,4 @@
1
+ // A edição se registra na casca ao carregar (CK-67). A casca da leitura alcança a edição só por este registro, e não a
2
+ // importa: quem só lê não baixa a edição, e o método de edição de um language service sem ela falha.
3
+ import { OrganizeImports, codefix, formatting, getEditsForFileRename, refactor, registerEditingServices, } from "./_namespaces/edit.js";
4
+ registerEditingServices({ formatting, codefix, refactor, OrganizeImports, getEditsForFileRename });
@@ -0,0 +1,113 @@
1
+ import { SemanticMeaning } from "./_namespaces/ts.js";
2
+ import type { BinaryExpression, CallExpression, CancellationToken, CheckResult, ForInOrOfStatement, HighlightSpan, Identifier, ImplementationLocation, NamedDeclaration, Node, ReadonlyMap, ReferenceEntry, ReferencedSymbol, RenameLocation, SignatureDeclaration, SourceFile, StringLiteral, Symbol, TextSpan, TypeChecker } from "./_namespaces/ts.js";
3
+ export interface SymbolAndEntries {
4
+ readonly definition: Definition | undefined;
5
+ readonly references: readonly Entry[];
6
+ }
7
+ /** Na tag, também o label e o `this` (CK-02). */
8
+ export declare enum DefinitionKind {
9
+ Symbol = 0,
10
+ Keyword = 1,
11
+ String = 2
12
+ }
13
+ export type Definition = {
14
+ readonly type: DefinitionKind.Symbol;
15
+ readonly symbol: Symbol;
16
+ } | {
17
+ readonly type: DefinitionKind.Keyword;
18
+ readonly node: Node;
19
+ } | {
20
+ readonly type: DefinitionKind.String;
21
+ readonly node: StringLiteral;
22
+ };
23
+ export declare enum EntryKind {
24
+ Span = 0,
25
+ Node = 1,
26
+ StringLiteral = 2,
27
+ SearchedLocalFoundProperty = 3,
28
+ SearchedPropertyFoundLocal = 4
29
+ }
30
+ export type NodeEntryKind = EntryKind.Node | EntryKind.StringLiteral | EntryKind.SearchedLocalFoundProperty | EntryKind.SearchedPropertyFoundLocal;
31
+ export type Entry = NodeEntry | SpanEntry;
32
+ export interface ContextWithStartAndEndNode {
33
+ start: Node;
34
+ end: Node;
35
+ }
36
+ export type ContextNode = Node | ContextWithStartAndEndNode;
37
+ export interface NodeEntry {
38
+ readonly kind: NodeEntryKind;
39
+ readonly node: Node;
40
+ readonly context?: ContextNode;
41
+ }
42
+ export interface SpanEntry {
43
+ readonly kind: EntryKind.Span;
44
+ readonly fileName: string;
45
+ readonly textSpan: TextSpan;
46
+ }
47
+ export declare function nodeEntry(node: Node, kind?: NodeEntryKind): NodeEntry;
48
+ export declare function isContextWithStartAndEndNode(node: ContextNode): node is ContextWithStartAndEndNode;
49
+ export declare function getContextNode(node: NamedDeclaration | BinaryExpression | ForInOrOfStatement | undefined): ContextNode | undefined;
50
+ export declare function toContextSpan(textSpan: TextSpan, sourceFile: SourceFile, context?: ContextNode): {
51
+ contextSpan: TextSpan;
52
+ } | undefined;
53
+ export declare enum FindReferencesUse {
54
+ /**
55
+ * When searching for references to a symbol, the location will not be adjusted (this is the default behavior when not specified).
56
+ */
57
+ Other = 0,
58
+ /**
59
+ * When searching for references to a symbol, the location will be adjusted if the cursor was on a keyword.
60
+ */
61
+ References = 1,
62
+ /**
63
+ * When searching for references to a symbol, the location will be adjusted if the cursor was on a keyword.
64
+ * Unlike `References`, the location will only be adjusted keyword belonged to a declaration with a valid name.
65
+ * If set, we will find fewer references -- if it is referenced by several different names, we still only find references for the original name.
66
+ */
67
+ Rename = 2
68
+ }
69
+ export interface Options {
70
+ readonly findInStrings?: boolean;
71
+ readonly findInComments?: boolean;
72
+ readonly use?: FindReferencesUse;
73
+ /** True if we are searching for implementations. We will have a different method of adding references if so. */
74
+ readonly implementations?: boolean;
75
+ /**
76
+ * True to opt in for enhanced renaming of shorthand properties and import/export specifiers.
77
+ * The options controls the behavior for the whole rename operation; it cannot be changed on a per-file basis.
78
+ * Default is false for backwards compatibility.
79
+ */
80
+ readonly providePrefixAndSuffixTextForRename?: boolean;
81
+ }
82
+ export declare function findReferencedSymbols(program: CheckResult, cancellationToken: CancellationToken, sourceFiles: readonly SourceFile[], sourceFile: SourceFile, position: number): ReferencedSymbol[] | undefined;
83
+ export declare function getImplementationsAtPosition(program: CheckResult, cancellationToken: CancellationToken, sourceFiles: readonly SourceFile[], sourceFile: SourceFile, position: number): ImplementationLocation[] | undefined;
84
+ export declare function findReferenceOrRenameEntries<T>(program: CheckResult, cancellationToken: CancellationToken, sourceFiles: readonly SourceFile[], node: Node, position: number, options: Options | undefined, convertEntry: ToReferenceOrRenameEntry<T>): T[] | undefined;
85
+ export type ToReferenceOrRenameEntry<T> = (entry: Entry, originalNode: Node, checker: TypeChecker) => T;
86
+ export declare function getReferenceEntriesForNode(position: number, node: Node, program: CheckResult, sourceFiles: readonly SourceFile[], cancellationToken: CancellationToken, options?: Options, sourceFilesSet?: ReadonlyMap<true>): readonly Entry[] | undefined;
87
+ export declare function toRenameLocation(entry: Entry, originalNode: Node, checker: TypeChecker, providePrefixAndSuffixText: boolean): RenameLocation;
88
+ export declare function toReferenceEntry(entry: Entry): ReferenceEntry;
89
+ export declare function toHighlightSpan(entry: Entry): {
90
+ fileName: string;
91
+ span: HighlightSpan;
92
+ };
93
+ export declare function getTextSpanOfEntry(entry: Entry): TextSpan;
94
+ /** Encapsulates the core find-all-references algorithm. */
95
+ export declare namespace Core {
96
+ /** Core find-all-references algorithm. Handles special cases before delegating to `getReferencedSymbolsForSymbol`. */
97
+ function getReferencedSymbolsForNode(_position: number, node: Node, program: CheckResult, sourceFiles: readonly SourceFile[], cancellationToken: CancellationToken, options?: Options, sourceFilesSet?: ReadonlyMap<true>): readonly SymbolAndEntries[] | undefined;
98
+ function eachExportReference(sourceFiles: readonly SourceFile[], checker: TypeChecker, cancellationToken: CancellationToken | undefined, exportSymbol: Symbol, exportingModuleSymbol: Symbol, exportName: string, isDefaultExport: boolean, cb: (ref: Identifier) => void): void;
99
+ /** Used as a quick check for whether a symbol is used at all in a file (besides its definition). */
100
+ function isSymbolReferencedInFile(definition: Identifier, checker: TypeChecker, sourceFile: SourceFile, searchContainer?: Node): boolean;
101
+ function eachSymbolReferenceInFile<T>(definition: Identifier, checker: TypeChecker, sourceFile: SourceFile, cb: (token: Identifier) => T, searchContainer?: Node): T | undefined;
102
+ function eachSignatureCall(signature: SignatureDeclaration, sourceFiles: readonly SourceFile[], checker: TypeChecker, cb: (call: CallExpression) => void): void;
103
+ /**
104
+ * Given an initial searchMeaning, extracted from a location, widen the search scope based on the declarations
105
+ * of the corresponding symbol. e.g. if we are searching for "Foo" in value position, but "Foo" references a class
106
+ * then we need to widen the search to include type positions as well.
107
+ * On the contrary, if we are searching for "Bar" in type position and we trace bar to an interface, and an uninstantiated
108
+ * module, we want to keep the search limited to only types, as the two declarations (interface and uninstantiated module)
109
+ * do not intersect in any of the three spaces.
110
+ */
111
+ function getIntersectingMeaningFromDeclarations(node: Node, symbol: Symbol): SemanticMeaning;
112
+ function getReferenceEntriesForShorthandPropertyAssignment(node: Node, checker: TypeChecker, addReference: (node: Node) => void): void;
113
+ }