@tslite/services 0.0.0-stage → 1.13.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
package/dist/rename.js ADDED
@@ -0,0 +1,100 @@
1
+ // Modificado de microsoft/TypeScript v3.9.10, src/services/rename.ts: o namespace virou módulo ES, com os imports explícitos.
2
+ import { Diagnostics, SymbolDisplay, SymbolFlags, SyntaxKind, createTextSpan, endsWith, find, getAdjustedRenameLocation, getLocaleSpecificMessage, getTextOfIdentifierOrLiteral, getTouchingPropertyName, isExternalModuleNameRelative, isIdentifier, isImportOrExportSpecifierName, isLiteralNameOfPropertyDeclarationOrIndexAccess, isSourceFile, isStringLiteralLike, isStringOrNumericLiteralLike, removeFileExtension, stripQuotes, tryGetImportFromModuleSpecifier, tryRemoveSuffix, } from "./_namespaces/ts.js";
3
+ export function getRenameInfo(program, sourceFile, position, options) {
4
+ const node = getAdjustedRenameLocation(getTouchingPropertyName(sourceFile, position));
5
+ if (nodeIsEligibleForRename(node)) {
6
+ const renameInfo = getRenameInfoForNode(node, program.getTypeChecker(), sourceFile, declaration => program.isSourceFileDefaultLibrary(declaration.getSourceFile()), options);
7
+ if (renameInfo) {
8
+ return renameInfo;
9
+ }
10
+ }
11
+ return getRenameInfoError(Diagnostics.You_cannot_rename_this_element);
12
+ }
13
+ function getRenameInfoForNode(node, typeChecker, sourceFile, isDefinedInLibraryFile, options) {
14
+ const symbol = typeChecker.getSymbolAtLocation(node);
15
+ if (!symbol)
16
+ return;
17
+ // Only allow a symbol to be renamed if it actually has at least one declaration.
18
+ const { declarations } = symbol;
19
+ if (!declarations || declarations.length === 0)
20
+ return;
21
+ // O que a lib declara não se renomeia. A mensagem é a do que não se renomeia, como a do embutido, que não tem
22
+ // declaração (CK-48); na tag, ela falava da lib do TypeScript (CK-68).
23
+ if (declarations.some(isDefinedInLibraryFile)) {
24
+ return getRenameInfoError(Diagnostics.You_cannot_rename_this_element);
25
+ }
26
+ // Cannot rename `default` as in `import { default as foo } from "./someModule";
27
+ if (isIdentifier(node) && node.originalKeywordKind === SyntaxKind.DefaultKeyword && symbol.parent && symbol.parent.flags & SymbolFlags.Module) {
28
+ return undefined;
29
+ }
30
+ if (isStringLiteralLike(node) && tryGetImportFromModuleSpecifier(node)) {
31
+ return options && options.allowRenameOfImportPath ? getRenameInfoForModule(node, sourceFile, symbol) : undefined;
32
+ }
33
+ const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, node);
34
+ const specifierName = (isImportOrExportSpecifierName(node) || isStringOrNumericLiteralLike(node) && node.parent.kind === SyntaxKind.ComputedPropertyName)
35
+ ? stripQuotes(getTextOfIdentifierOrLiteral(node))
36
+ : undefined;
37
+ const displayName = specifierName || typeChecker.symbolToString(symbol);
38
+ const fullDisplayName = specifierName || typeChecker.getFullyQualifiedName(symbol);
39
+ return getRenameInfoSuccess(displayName, fullDisplayName, kind, SymbolDisplay.getSymbolModifiers(symbol), node, sourceFile);
40
+ }
41
+ function getRenameInfoForModule(node, sourceFile, moduleSymbol) {
42
+ if (!isExternalModuleNameRelative(node.text)) {
43
+ return getRenameInfoError(Diagnostics.You_cannot_rename_a_module_via_a_global_import);
44
+ }
45
+ const moduleSourceFile = find(moduleSymbol.declarations, isSourceFile);
46
+ if (!moduleSourceFile)
47
+ return undefined;
48
+ const withoutIndex = endsWith(node.text, "/index") || endsWith(node.text, "/index.js") ? undefined : tryRemoveSuffix(removeFileExtension(moduleSourceFile.fileName), "/index");
49
+ const name = withoutIndex === undefined ? moduleSourceFile.fileName : withoutIndex;
50
+ const kind = withoutIndex === undefined ? "module" /* ScriptElementKind.moduleElement */ : "directory" /* ScriptElementKind.directory */;
51
+ const indexAfterLastSlash = node.text.lastIndexOf("/") + 1;
52
+ // Span should only be the last component of the path. + 1 to account for the quote character.
53
+ const triggerSpan = createTextSpan(node.getStart(sourceFile) + 1 + indexAfterLastSlash, node.text.length - indexAfterLastSlash);
54
+ return {
55
+ canRename: true,
56
+ fileToRename: name,
57
+ kind,
58
+ displayName: name,
59
+ fullDisplayName: name,
60
+ kindModifiers: "" /* ScriptElementKindModifier.none */,
61
+ triggerSpan,
62
+ };
63
+ }
64
+ function getRenameInfoSuccess(displayName, fullDisplayName, kind, kindModifiers, node, sourceFile) {
65
+ return {
66
+ canRename: true,
67
+ fileToRename: undefined,
68
+ kind,
69
+ displayName,
70
+ fullDisplayName,
71
+ kindModifiers,
72
+ triggerSpan: createTriggerSpanForNode(node, sourceFile)
73
+ };
74
+ }
75
+ function getRenameInfoError(diagnostic) {
76
+ return { canRename: false, localizedErrorMessage: getLocaleSpecificMessage(diagnostic) };
77
+ }
78
+ function createTriggerSpanForNode(node, sourceFile) {
79
+ let start = node.getStart(sourceFile);
80
+ let width = node.getWidth(sourceFile);
81
+ if (isStringLiteralLike(node)) {
82
+ // Exclude the quotes
83
+ start += 1;
84
+ width -= 2;
85
+ }
86
+ return createTextSpan(start, width);
87
+ }
88
+ /** Na tag, também o nome `#private` e o `this` (CK-02). */
89
+ function nodeIsEligibleForRename(node) {
90
+ switch (node.kind) {
91
+ case SyntaxKind.Identifier:
92
+ case SyntaxKind.StringLiteral:
93
+ case SyntaxKind.NoSubstitutionTemplateLiteral:
94
+ return true;
95
+ case SyntaxKind.NumericLiteral:
96
+ return isLiteralNameOfPropertyDeclarationOrIndexAccess(node);
97
+ default:
98
+ return false;
99
+ }
100
+ }
@@ -0,0 +1,48 @@
1
+ import { ScriptKind, ScriptTarget } from "./_namespaces/ts.js";
2
+ import type { CancellationToken, DocumentRegistry, EditorOptions, EditorSettings, EmitTextWriter, FormatCodeOptions, FormatCodeSettings, HostCancellationToken, IScriptSnapshot, JsxAttributes, LanguageService, LanguageServiceHost, Node, ObjectLiteralElement, ObjectLiteralExpression, PropertyName, SourceFile, Symbol, SymbolDisplayPart, TextChangeRange, Type, TypeChecker, UnderscoreEscapedMap } from "./_namespaces/ts.js";
3
+ /** A versão da API do language service. */
4
+ export declare const servicesVersion = "0.8";
5
+ export interface DisplayPartsSymbolWriter extends EmitTextWriter {
6
+ displayParts(): SymbolDisplayPart[];
7
+ }
8
+ export declare function toEditorSettings(options: FormatCodeOptions | FormatCodeSettings): FormatCodeSettings;
9
+ export declare function toEditorSettings(options: EditorOptions | EditorSettings): EditorSettings;
10
+ export declare function displayPartsToString(displayParts: SymbolDisplayPart[] | undefined): string;
11
+ export declare function createLanguageServiceSourceFile(fileName: string, scriptSnapshot: IScriptSnapshot, scriptTarget: ScriptTarget, version: string, setNodeParents: boolean, scriptKind?: ScriptKind): SourceFile;
12
+ export declare function updateLanguageServiceSourceFile(sourceFile: SourceFile, scriptSnapshot: IScriptSnapshot, version: string, textChangeRange: TextChangeRange | undefined, aggressiveChecks?: boolean): SourceFile;
13
+ /** O cancelamento que pergunta ao host no máximo a cada `throttleWaitMilliseconds`: perguntar custa. */
14
+ export declare class ThrottledCancellationToken implements CancellationToken {
15
+ private hostCancellationToken;
16
+ private readonly throttleWaitMilliseconds;
17
+ private lastCancellationCheckTime;
18
+ constructor(hostCancellationToken: HostCancellationToken, throttleWaitMilliseconds?: number);
19
+ isCancellationRequested(): boolean;
20
+ throwIfCancellationRequested(): void;
21
+ }
22
+ /**
23
+ * A edição que a casca alcança: os namespaces da tag que os métodos de edição do `LanguageService` chamam. Na tag, a casca
24
+ * os chama direto; aqui ela os alcança por este registro, que o `@tslite/services/edit` faz ao carregar, para quem só lê
25
+ * não baixar a edição (CK-67), como o completion alcança o auto-import.
26
+ */
27
+ export interface EditingServices {
28
+ formatting: typeof import("./_namespaces/ts.formatting.js");
29
+ codefix: typeof import("./_namespaces/ts.codefix.js");
30
+ refactor: typeof import("./_namespaces/ts.refactor.js");
31
+ OrganizeImports: typeof import("./_namespaces/ts.OrganizeImports.js");
32
+ getEditsForFileRename: typeof import("./getEditsForFileRename.js").getEditsForFileRename;
33
+ }
34
+ /** Registra a edição na casca. O `@tslite/services/edit` o chama ao carregar; o registro vale para o processo. */
35
+ export declare function registerEditingServices(services: EditingServices): void;
36
+ export declare function createLanguageService(host: LanguageServiceHost, documentRegistry?: DocumentRegistry, syntaxOnly?: boolean): LanguageService;
37
+ /** Names in the name table are escaped, so an identifier `__foo` will have a name table entry `___foo`. */
38
+ export declare function getNameTable(sourceFile: SourceFile): UnderscoreEscapedMap<number>;
39
+ /**
40
+ * Returns the containing object literal property declaration given a possible name node, e.g. "a" in x = { "a": 1 }
41
+ */
42
+ export declare function getContainingObjectLiteralElement(node: Node): ObjectLiteralElementWithName | undefined;
43
+ export type ObjectLiteralElementWithName = ObjectLiteralElement & {
44
+ name: PropertyName;
45
+ parent: ObjectLiteralExpression | JsxAttributes;
46
+ };
47
+ /** Gets all symbols for one property. Does not get symbols for every property. */
48
+ export declare function getPropertySymbolsFromContextualType(node: ObjectLiteralElementWithName, checker: TypeChecker, contextualType: Type, unionSymbolOk: boolean): readonly Symbol[];