@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.
- package/LICENSE +55 -0
- package/NOTICE +13 -0
- package/dist/_namespaces/edit.d.ts +8 -0
- package/dist/_namespaces/edit.js +11 -0
- package/dist/_namespaces/ts.Completions.StringCompletions.d.ts +1 -0
- package/dist/_namespaces/ts.Completions.StringCompletions.js +2 -0
- package/dist/_namespaces/ts.Completions.d.ts +2 -0
- package/dist/_namespaces/ts.Completions.js +3 -0
- package/dist/_namespaces/ts.FindAllReferences.d.ts +2 -0
- package/dist/_namespaces/ts.FindAllReferences.js +3 -0
- package/dist/_namespaces/ts.GoToDefinition.d.ts +1 -0
- package/dist/_namespaces/ts.GoToDefinition.js +2 -0
- package/dist/_namespaces/ts.NavigationBar.d.ts +1 -0
- package/dist/_namespaces/ts.NavigationBar.js +2 -0
- package/dist/_namespaces/ts.OrganizeImports.d.ts +1 -0
- package/dist/_namespaces/ts.OrganizeImports.js +2 -0
- package/dist/_namespaces/ts.OutliningElementsCollector.d.ts +1 -0
- package/dist/_namespaces/ts.OutliningElementsCollector.js +2 -0
- package/dist/_namespaces/ts.Rename.d.ts +1 -0
- package/dist/_namespaces/ts.Rename.js +2 -0
- package/dist/_namespaces/ts.SignatureHelp.d.ts +1 -0
- package/dist/_namespaces/ts.SignatureHelp.js +2 -0
- package/dist/_namespaces/ts.SmartSelectionRange.d.ts +1 -0
- package/dist/_namespaces/ts.SmartSelectionRange.js +2 -0
- package/dist/_namespaces/ts.SymbolDisplay.d.ts +1 -0
- package/dist/_namespaces/ts.SymbolDisplay.js +2 -0
- package/dist/_namespaces/ts.codefix.d.ts +26 -0
- package/dist/_namespaces/ts.codefix.js +27 -0
- package/dist/_namespaces/ts.d.ts +17 -0
- package/dist/_namespaces/ts.formatting.d.ts +7 -0
- package/dist/_namespaces/ts.formatting.js +8 -0
- package/dist/_namespaces/ts.js +20 -0
- package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.d.ts +1 -0
- package/dist/_namespaces/ts.refactor.addOrRemoveBracesToArrowFunction.js +2 -0
- package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.d.ts +1 -0
- package/dist/_namespaces/ts.refactor.convertParamsToDestructuredObject.js +2 -0
- package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.d.ts +1 -0
- package/dist/_namespaces/ts.refactor.convertStringOrTemplateLiteral.js +2 -0
- package/dist/_namespaces/ts.refactor.d.ts +9 -0
- package/dist/_namespaces/ts.refactor.extractSymbol.d.ts +1 -0
- package/dist/_namespaces/ts.refactor.extractSymbol.js +2 -0
- package/dist/_namespaces/ts.refactor.js +10 -0
- package/dist/_namespaces/ts.textChanges.d.ts +1 -0
- package/dist/_namespaces/ts.textChanges.js +2 -0
- package/dist/classifier.d.ts +5 -0
- package/dist/classifier.js +439 -0
- package/dist/codeFixProvider.d.ts +13 -0
- package/dist/codeFixProvider.js +84 -0
- package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.d.ts +1 -0
- package/dist/codefixes/addConvertToUnknownForNonOverlappingTypes.js +21 -0
- package/dist/codefixes/addEmptyExportDeclaration.d.ts +1 -0
- package/dist/codefixes/addEmptyExportDeclaration.js +17 -0
- package/dist/codefixes/addMissingAsync.d.ts +1 -0
- package/dist/codefixes/addMissingAsync.js +75 -0
- package/dist/codefixes/addMissingAwait.d.ts +1 -0
- package/dist/codefixes/addMissingAwait.js +236 -0
- package/dist/codefixes/addMissingConst.d.ts +1 -0
- package/dist/codefixes/addMissingConst.js +91 -0
- package/dist/codefixes/addNameToNamelessParameter.d.ts +1 -0
- package/dist/codefixes/addNameToNamelessParameter.js +29 -0
- package/dist/codefixes/convertConstToLet.d.ts +1 -0
- package/dist/codefixes/convertConstToLet.js +30 -0
- package/dist/codefixes/convertToAsyncFunction.d.ts +1 -0
- package/dist/codefixes/convertToAsyncFunction.js +495 -0
- package/dist/codefixes/convertToMappedObjectType.d.ts +1 -0
- package/dist/codefixes/convertToMappedObjectType.js +48 -0
- package/dist/codefixes/correctQualifiedNameToIndexedAccessType.d.ts +1 -0
- package/dist/codefixes/correctQualifiedNameToIndexedAccessType.js +33 -0
- package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.d.ts +1 -0
- package/dist/codefixes/fixAddModuleReferTypeMissingTypeof.js +27 -0
- package/dist/codefixes/fixAwaitInSyncFunction.d.ts +1 -0
- package/dist/codefixes/fixAwaitInSyncFunction.js +69 -0
- package/dist/codefixes/fixExpectedComma.d.ts +1 -0
- package/dist/codefixes/fixExpectedComma.js +35 -0
- package/dist/codefixes/fixInvalidJsxCharacters.d.ts +1 -0
- package/dist/codefixes/fixInvalidJsxCharacters.js +41 -0
- package/dist/codefixes/fixMissingCallParentheses.d.ts +1 -0
- package/dist/codefixes/fixMissingCallParentheses.js +42 -0
- package/dist/codefixes/fixSpelling.d.ts +1 -0
- package/dist/codefixes/fixSpelling.js +94 -0
- package/dist/codefixes/fixUnreachableCode.d.ts +1 -0
- package/dist/codefixes/fixUnreachableCode.js +65 -0
- package/dist/codefixes/fixUnusedIdentifier.d.ts +1 -0
- package/dist/codefixes/fixUnusedIdentifier.js +224 -0
- package/dist/codefixes/helpers.d.ts +8 -0
- package/dist/codefixes/helpers.js +53 -0
- package/dist/codefixes/importFixes.d.ts +14 -0
- package/dist/codefixes/importFixes.js +441 -0
- package/dist/codefixes/inferFromUsage.d.ts +1 -0
- package/dist/codefixes/inferFromUsage.js +742 -0
- package/dist/codefixes/removeUnnecessaryAwait.d.ts +1 -0
- package/dist/codefixes/removeUnnecessaryAwait.js +41 -0
- package/dist/codefixes/returnValueCorrect.d.ts +1 -0
- package/dist/codefixes/returnValueCorrect.js +132 -0
- package/dist/codefixes/splitTypeOnlyImport.d.ts +1 -0
- package/dist/codefixes/splitTypeOnlyImport.js +32 -0
- package/dist/codefixes/useBigintLiteral.d.ts +1 -0
- package/dist/codefixes/useBigintLiteral.js +29 -0
- package/dist/completions.d.ts +83 -0
- package/dist/completions.js +1720 -0
- package/dist/documentHighlights.d.ts +8 -0
- package/dist/documentHighlights.js +367 -0
- package/dist/documentRegistry.d.ts +36 -0
- package/dist/documentRegistry.js +63 -0
- package/dist/editingServices.d.ts +1 -0
- package/dist/editingServices.js +4 -0
- package/dist/findAllReferences.d.ts +113 -0
- package/dist/findAllReferences.js +1366 -0
- package/dist/formatting/formatting.d.ts +26 -0
- package/dist/formatting/formatting.js +1021 -0
- package/dist/formatting/formattingContext.d.ts +34 -0
- package/dist/formatting/formattingContext.js +78 -0
- package/dist/formatting/formattingScanner.d.ts +14 -0
- package/dist/formatting/formattingScanner.js +228 -0
- package/dist/formatting/rule.d.ts +31 -0
- package/dist/formatting/rule.js +22 -0
- package/dist/formatting/rules.d.ts +7 -0
- package/dist/formatting/rules.js +610 -0
- package/dist/formatting/rulesMap.d.ts +5 -0
- package/dist/formatting/rulesMap.js +127 -0
- package/dist/formatting/smartIndenter.d.ts +44 -0
- package/dist/formatting/smartIndenter.js +518 -0
- package/dist/getEditsForFileRename.d.ts +6 -0
- package/dist/getEditsForFileRename.js +86 -0
- package/dist/goToDefinition.d.ts +8 -0
- package/dist/goToDefinition.js +246 -0
- package/dist/importTracker.d.ts +50 -0
- package/dist/importTracker.js +422 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +3 -0
- package/dist/navigationBar.d.ts +3 -0
- package/dist/navigationBar.js +549 -0
- package/dist/organizeImports.d.ts +18 -0
- package/dist/organizeImports.js +290 -0
- package/dist/outliningElementsCollector.d.ts +2 -0
- package/dist/outliningElementsCollector.js +261 -0
- package/dist/refactorProvider.d.ts +5 -0
- package/dist/refactorProvider.js +16 -0
- package/dist/refactors/addOrRemoveBracesToArrowFunction.d.ts +1 -0
- package/dist/refactors/addOrRemoveBracesToArrowFunction.js +86 -0
- package/dist/refactors/convertExport.d.ts +1 -0
- package/dist/refactors/convertExport.js +126 -0
- package/dist/refactors/convertImport.d.ts +1 -0
- package/dist/refactors/convertImport.js +116 -0
- package/dist/refactors/convertParamsToDestructuredObject.d.ts +1 -0
- package/dist/refactors/convertParamsToDestructuredObject.js +282 -0
- package/dist/refactors/convertStringOrTemplateLiteral.d.ts +1 -0
- package/dist/refactors/convertStringOrTemplateLiteral.js +148 -0
- package/dist/refactors/extractSymbol.d.ts +60 -0
- package/dist/refactors/extractSymbol.js +1281 -0
- package/dist/refactors/extractType.d.ts +1 -0
- package/dist/refactors/extractType.js +102 -0
- package/dist/refactors/moveToNewFile.d.ts +1 -0
- package/dist/refactors/moveToNewFile.js +477 -0
- package/dist/rename.d.ts +2 -0
- package/dist/rename.js +100 -0
- package/dist/services.d.ts +48 -0
- package/dist/services.js +1480 -0
- package/dist/signatureHelp.d.ts +8 -0
- package/dist/signatureHelp.js +414 -0
- package/dist/smartSelection.d.ts +2 -0
- package/dist/smartSelection.js +243 -0
- package/dist/stringCompletions.d.ts +4 -0
- package/dist/stringCompletions.js +220 -0
- package/dist/suggestionDiagnostics.d.ts +6 -0
- package/dist/suggestionDiagnostics.js +92 -0
- package/dist/symbolDisplay.d.ts +16 -0
- package/dist/symbolDisplay.js +400 -0
- package/dist/textChanges.d.ts +161 -0
- package/dist/textChanges.js +1163 -0
- package/dist/types.d.ts +908 -0
- package/dist/types.js +263 -0
- package/dist/utilities.d.ts +283 -0
- package/dist/utilities.js +1981 -0
- package/package.json +45 -3
- package/README.md +0 -3
|
@@ -0,0 +1,75 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addMissingAsync.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Diagnostics, ModifierFlags, createMap, createModifiersFromModifierFlags, createNodeArray, createTextSpanFromNode, find, findAncestor, getModifierFlags, getNodeId, getSynthesizedDeepClone, getTokenAtPosition, isArrowFunction, isNumber, some, textChanges, textSpanEnd, textSpansEqual, } from "../_namespaces/edit.js";
|
|
3
|
+
import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
|
|
4
|
+
const fixId = "addMissingAsync";
|
|
5
|
+
const errorCodes = [
|
|
6
|
+
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
|
|
7
|
+
Diagnostics.Type_0_is_not_assignable_to_type_1.code,
|
|
8
|
+
Diagnostics.Type_0_is_not_comparable_to_type_1.code
|
|
9
|
+
];
|
|
10
|
+
registerCodeFix({
|
|
11
|
+
fixIds: [fixId],
|
|
12
|
+
errorCodes,
|
|
13
|
+
getCodeActions: context => {
|
|
14
|
+
const { sourceFile, errorCode, cancellationToken, program, span } = context;
|
|
15
|
+
// Na tag, o checker que produz os diagnósticos do `Program`; o do `check` é um só (CK-47).
|
|
16
|
+
const diagnostic = find(program.getTypeChecker().getDiagnostics(sourceFile, cancellationToken), getIsMatchingAsyncError(span, errorCode));
|
|
17
|
+
const directSpan = diagnostic && diagnostic.relatedInformation && find(diagnostic.relatedInformation, r => r.code === Diagnostics.Did_you_mean_to_mark_this_function_as_async.code);
|
|
18
|
+
const decl = getFixableErrorSpanDeclaration(sourceFile, directSpan);
|
|
19
|
+
if (!decl) {
|
|
20
|
+
return;
|
|
21
|
+
}
|
|
22
|
+
const trackChanges = cb => textChanges.ChangeTracker.with(context, cb);
|
|
23
|
+
return [getFix(context, decl, trackChanges)];
|
|
24
|
+
},
|
|
25
|
+
getAllCodeActions: context => {
|
|
26
|
+
const { sourceFile } = context;
|
|
27
|
+
const fixedDeclarations = createMap();
|
|
28
|
+
return codeFixAll(context, errorCodes, (t, diagnostic) => {
|
|
29
|
+
const span = diagnostic.relatedInformation && find(diagnostic.relatedInformation, r => r.code === Diagnostics.Did_you_mean_to_mark_this_function_as_async.code);
|
|
30
|
+
const decl = getFixableErrorSpanDeclaration(sourceFile, span);
|
|
31
|
+
if (!decl) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
34
|
+
const trackChanges = cb => (cb(t), []);
|
|
35
|
+
return getFix(context, decl, trackChanges, fixedDeclarations);
|
|
36
|
+
});
|
|
37
|
+
},
|
|
38
|
+
});
|
|
39
|
+
function getFix(context, decl, trackChanges, fixedDeclarations) {
|
|
40
|
+
const changes = trackChanges(t => makeChange(t, context.sourceFile, decl, fixedDeclarations));
|
|
41
|
+
return createCodeFixAction(fixId, changes, Diagnostics.Add_async_modifier_to_containing_function, fixId, Diagnostics.Add_all_missing_async_modifiers);
|
|
42
|
+
}
|
|
43
|
+
function makeChange(changeTracker, sourceFile, insertionSite, fixedDeclarations) {
|
|
44
|
+
if (fixedDeclarations) {
|
|
45
|
+
if (fixedDeclarations.has(getNodeId(insertionSite).toString())) {
|
|
46
|
+
return;
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
fixedDeclarations?.set(getNodeId(insertionSite).toString(), true);
|
|
50
|
+
const cloneWithModifier = getSynthesizedDeepClone(insertionSite, /*includeTrivia*/ true);
|
|
51
|
+
cloneWithModifier.modifiers = createNodeArray(createModifiersFromModifierFlags(getModifierFlags(insertionSite) | ModifierFlags.Async));
|
|
52
|
+
cloneWithModifier.modifierFlagsCache = 0;
|
|
53
|
+
changeTracker.replaceNode(sourceFile, insertionSite, cloneWithModifier);
|
|
54
|
+
}
|
|
55
|
+
function getFixableErrorSpanDeclaration(sourceFile, span) {
|
|
56
|
+
if (!span)
|
|
57
|
+
return undefined;
|
|
58
|
+
const token = getTokenAtPosition(sourceFile, span.start);
|
|
59
|
+
// Checker has already done work to determine that async might be possible, and has attached
|
|
60
|
+
// related info to the node, so start by finding the signature that exactly matches up
|
|
61
|
+
// with the diagnostic range.
|
|
62
|
+
const decl = findAncestor(token, node => {
|
|
63
|
+
if (node.getStart(sourceFile) < span.start || node.getEnd() > textSpanEnd(span)) {
|
|
64
|
+
return "quit";
|
|
65
|
+
}
|
|
66
|
+
return isArrowFunction(node) && textSpansEqual(span, createTextSpanFromNode(node, sourceFile));
|
|
67
|
+
});
|
|
68
|
+
return decl;
|
|
69
|
+
}
|
|
70
|
+
function getIsMatchingAsyncError(span, errorCode) {
|
|
71
|
+
return ({ start, length, relatedInformation, code }) => isNumber(start) && isNumber(length) && textSpansEqual({ start, length }, span) &&
|
|
72
|
+
code === errorCode &&
|
|
73
|
+
!!relatedInformation &&
|
|
74
|
+
some(relatedInformation, related => related.code === Diagnostics.Did_you_mean_to_mark_this_function_as_async.code);
|
|
75
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addMissingAwait.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Diagnostics, FindAllReferences, ModifierFlags, NodeFlags, SyntaxKind, TypeFlags, addToSeen, compact, contains, createAwait, createMap, createParen, createTextSpanFromNode, find, findAncestor, findPrecedingToken, forEach, getAncestor, getSymbolId, getTokenAtPosition, hasModifier, isArrowFunction, isBinaryExpression, isBlock, isCallOrNewExpression, isExpression, isIdentifier, isNumber, isPropertyAccessExpression, isVariableDeclaration, positionIsASICandidate, some, textChanges, textSpanEnd, textSpansEqual, tryCast, } from "../_namespaces/edit.js";
|
|
3
|
+
import { codeFixAll, createCodeFixAction, createCodeFixActionWithoutFixAll, registerCodeFix, } from "../_namespaces/ts.codefix.js";
|
|
4
|
+
const fixId = "addMissingAwait";
|
|
5
|
+
const propertyAccessCode = Diagnostics.Property_0_does_not_exist_on_type_1.code;
|
|
6
|
+
// Na tag, também o que não se constrói (o `new`, CK-02).
|
|
7
|
+
const callableConstructableErrorCodes = [
|
|
8
|
+
Diagnostics.This_expression_is_not_callable.code,
|
|
9
|
+
];
|
|
10
|
+
// Na tag, também as mensagens do `for…of` que a cópia não acusa: as do alvo abaixo do ES2015 e do `downlevelIteration`
|
|
11
|
+
// (CK-24), e as do `Symbol.iterator` e do `Symbol.asyncIterator`, do protocolo de iteração (CK-55).
|
|
12
|
+
const errorCodes = [
|
|
13
|
+
Diagnostics.An_arithmetic_operand_must_be_of_type_any_number_bigint_or_an_enum_type.code,
|
|
14
|
+
Diagnostics.The_left_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code,
|
|
15
|
+
Diagnostics.The_right_hand_side_of_an_arithmetic_operation_must_be_of_type_any_number_bigint_or_an_enum_type.code,
|
|
16
|
+
Diagnostics.Operator_0_cannot_be_applied_to_type_1.code,
|
|
17
|
+
Diagnostics.Operator_0_cannot_be_applied_to_types_1_and_2.code,
|
|
18
|
+
Diagnostics.This_condition_will_always_return_0_since_the_types_1_and_2_have_no_overlap.code,
|
|
19
|
+
Diagnostics.Type_0_is_not_an_array_type.code,
|
|
20
|
+
Diagnostics.Argument_of_type_0_is_not_assignable_to_parameter_of_type_1.code,
|
|
21
|
+
propertyAccessCode,
|
|
22
|
+
...callableConstructableErrorCodes,
|
|
23
|
+
];
|
|
24
|
+
registerCodeFix({
|
|
25
|
+
fixIds: [fixId],
|
|
26
|
+
errorCodes,
|
|
27
|
+
getCodeActions: context => {
|
|
28
|
+
const { sourceFile, errorCode, span, cancellationToken, program } = context;
|
|
29
|
+
const expression = getFixableErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program);
|
|
30
|
+
if (!expression) {
|
|
31
|
+
return;
|
|
32
|
+
}
|
|
33
|
+
const checker = context.program.getTypeChecker();
|
|
34
|
+
const trackChanges = cb => textChanges.ChangeTracker.with(context, cb);
|
|
35
|
+
return compact([
|
|
36
|
+
getDeclarationSiteFix(context, expression, errorCode, checker, trackChanges),
|
|
37
|
+
getUseSiteFix(context, expression, errorCode, checker, trackChanges)
|
|
38
|
+
]);
|
|
39
|
+
},
|
|
40
|
+
getAllCodeActions: context => {
|
|
41
|
+
const { sourceFile, program, cancellationToken } = context;
|
|
42
|
+
const checker = context.program.getTypeChecker();
|
|
43
|
+
const fixedDeclarations = createMap();
|
|
44
|
+
return codeFixAll(context, errorCodes, (t, diagnostic) => {
|
|
45
|
+
const expression = getFixableErrorSpanExpression(sourceFile, diagnostic.code, diagnostic, cancellationToken, program);
|
|
46
|
+
if (!expression) {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
const trackChanges = cb => (cb(t), []);
|
|
50
|
+
return getDeclarationSiteFix(context, expression, diagnostic.code, checker, trackChanges, fixedDeclarations)
|
|
51
|
+
|| getUseSiteFix(context, expression, diagnostic.code, checker, trackChanges, fixedDeclarations);
|
|
52
|
+
});
|
|
53
|
+
},
|
|
54
|
+
});
|
|
55
|
+
function getDeclarationSiteFix(context, expression, errorCode, checker, trackChanges, fixedDeclarations) {
|
|
56
|
+
const { sourceFile, program, cancellationToken } = context;
|
|
57
|
+
const awaitableInitializers = findAwaitableInitializers(expression, sourceFile, cancellationToken, program, checker);
|
|
58
|
+
if (awaitableInitializers) {
|
|
59
|
+
const initializerChanges = trackChanges(t => {
|
|
60
|
+
forEach(awaitableInitializers.initializers, ({ expression }) => makeChange(t, errorCode, sourceFile, checker, expression, fixedDeclarations));
|
|
61
|
+
if (fixedDeclarations && awaitableInitializers.needsSecondPassForFixAll) {
|
|
62
|
+
makeChange(t, errorCode, sourceFile, checker, expression, fixedDeclarations);
|
|
63
|
+
}
|
|
64
|
+
});
|
|
65
|
+
// No fix-all because it will already be included once with the use site fix,
|
|
66
|
+
// and for simplicity the fix-all doesn‘t let the user choose between use-site and declaration-site fixes.
|
|
67
|
+
return createCodeFixActionWithoutFixAll("addMissingAwaitToInitializer", initializerChanges, awaitableInitializers.initializers.length === 1
|
|
68
|
+
? [Diagnostics.Add_await_to_initializer_for_0, awaitableInitializers.initializers[0].declarationSymbol.name]
|
|
69
|
+
: Diagnostics.Add_await_to_initializers);
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
function getUseSiteFix(context, expression, errorCode, checker, trackChanges, fixedDeclarations) {
|
|
73
|
+
const changes = trackChanges(t => makeChange(t, errorCode, context.sourceFile, checker, expression, fixedDeclarations));
|
|
74
|
+
return createCodeFixAction(fixId, changes, Diagnostics.Add_await, fixId, Diagnostics.Fix_all_expressions_possibly_missing_await);
|
|
75
|
+
}
|
|
76
|
+
function isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program) {
|
|
77
|
+
// Na tag, o checker que produz os diagnósticos do `Program`; o do `check` é um só (CK-47).
|
|
78
|
+
const checker = program.getTypeChecker();
|
|
79
|
+
const diagnostics = checker.getDiagnostics(sourceFile, cancellationToken);
|
|
80
|
+
return some(diagnostics, ({ start, length, relatedInformation, code }) => isNumber(start) && isNumber(length) && textSpansEqual({ start, length }, span) &&
|
|
81
|
+
code === errorCode &&
|
|
82
|
+
!!relatedInformation &&
|
|
83
|
+
some(relatedInformation, related => related.code === Diagnostics.Did_you_forget_to_use_await.code));
|
|
84
|
+
}
|
|
85
|
+
function getFixableErrorSpanExpression(sourceFile, errorCode, span, cancellationToken, program) {
|
|
86
|
+
const token = getTokenAtPosition(sourceFile, span.start);
|
|
87
|
+
// Checker has already done work to determine that await might be possible, and has attached
|
|
88
|
+
// related info to the node, so start by finding the expression that exactly matches up
|
|
89
|
+
// with the diagnostic range.
|
|
90
|
+
const expression = findAncestor(token, node => {
|
|
91
|
+
if (node.getStart(sourceFile) < span.start || node.getEnd() > textSpanEnd(span)) {
|
|
92
|
+
return "quit";
|
|
93
|
+
}
|
|
94
|
+
return isExpression(node) && textSpansEqual(span, createTextSpanFromNode(node, sourceFile));
|
|
95
|
+
});
|
|
96
|
+
return expression
|
|
97
|
+
&& isMissingAwaitError(sourceFile, errorCode, span, cancellationToken, program)
|
|
98
|
+
&& isInsideAwaitableBody(expression) ? expression : undefined;
|
|
99
|
+
}
|
|
100
|
+
function findAwaitableInitializers(expression, sourceFile, cancellationToken, program, checker) {
|
|
101
|
+
const identifiers = getIdentifiersFromErrorSpanExpression(expression, checker);
|
|
102
|
+
if (!identifiers) {
|
|
103
|
+
return;
|
|
104
|
+
}
|
|
105
|
+
let isCompleteFix = identifiers.isCompleteFix;
|
|
106
|
+
let initializers;
|
|
107
|
+
for (const identifier of identifiers.identifiers) {
|
|
108
|
+
const symbol = checker.getSymbolAtLocation(identifier);
|
|
109
|
+
if (!symbol) {
|
|
110
|
+
continue;
|
|
111
|
+
}
|
|
112
|
+
const declaration = tryCast(symbol.valueDeclaration, isVariableDeclaration);
|
|
113
|
+
const variableName = declaration && tryCast(declaration.name, isIdentifier);
|
|
114
|
+
const variableStatement = getAncestor(declaration, SyntaxKind.VariableStatement);
|
|
115
|
+
if (!declaration || !variableStatement ||
|
|
116
|
+
declaration.type ||
|
|
117
|
+
!declaration.initializer ||
|
|
118
|
+
variableStatement.getSourceFile() !== sourceFile ||
|
|
119
|
+
hasModifier(variableStatement, ModifierFlags.Export) ||
|
|
120
|
+
!variableName ||
|
|
121
|
+
!isInsideAwaitableBody(declaration.initializer)) {
|
|
122
|
+
isCompleteFix = false;
|
|
123
|
+
continue;
|
|
124
|
+
}
|
|
125
|
+
const diagnostics = program.getSemanticDiagnostics(sourceFile, cancellationToken);
|
|
126
|
+
const isUsedElsewhere = FindAllReferences.Core.eachSymbolReferenceInFile(variableName, checker, sourceFile, reference => {
|
|
127
|
+
return identifier !== reference && !symbolReferenceIsAlsoMissingAwait(reference, diagnostics, sourceFile, checker);
|
|
128
|
+
});
|
|
129
|
+
if (isUsedElsewhere) {
|
|
130
|
+
isCompleteFix = false;
|
|
131
|
+
continue;
|
|
132
|
+
}
|
|
133
|
+
(initializers || (initializers = [])).push({
|
|
134
|
+
expression: declaration.initializer,
|
|
135
|
+
declarationSymbol: symbol,
|
|
136
|
+
});
|
|
137
|
+
}
|
|
138
|
+
return initializers && {
|
|
139
|
+
initializers,
|
|
140
|
+
needsSecondPassForFixAll: !isCompleteFix,
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
function getIdentifiersFromErrorSpanExpression(expression, checker) {
|
|
144
|
+
if (isPropertyAccessExpression(expression.parent) && isIdentifier(expression.parent.expression)) {
|
|
145
|
+
return { identifiers: [expression.parent.expression], isCompleteFix: true };
|
|
146
|
+
}
|
|
147
|
+
if (isIdentifier(expression)) {
|
|
148
|
+
return { identifiers: [expression], isCompleteFix: true };
|
|
149
|
+
}
|
|
150
|
+
if (isBinaryExpression(expression)) {
|
|
151
|
+
let sides;
|
|
152
|
+
let isCompleteFix = true;
|
|
153
|
+
for (const side of [expression.left, expression.right]) {
|
|
154
|
+
const type = checker.getTypeAtLocation(side);
|
|
155
|
+
if (checker.getPromisedTypeOfPromise(type)) {
|
|
156
|
+
if (!isIdentifier(side)) {
|
|
157
|
+
isCompleteFix = false;
|
|
158
|
+
continue;
|
|
159
|
+
}
|
|
160
|
+
(sides || (sides = [])).push(side);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
return sides && { identifiers: sides, isCompleteFix };
|
|
164
|
+
}
|
|
165
|
+
}
|
|
166
|
+
function symbolReferenceIsAlsoMissingAwait(reference, diagnostics, sourceFile, checker) {
|
|
167
|
+
const errorNode = isPropertyAccessExpression(reference.parent) ? reference.parent.name :
|
|
168
|
+
isBinaryExpression(reference.parent) ? reference.parent :
|
|
169
|
+
reference;
|
|
170
|
+
const diagnostic = find(diagnostics, diagnostic => diagnostic.start === errorNode.getStart(sourceFile) &&
|
|
171
|
+
(diagnostic.start + diagnostic.length) === errorNode.getEnd());
|
|
172
|
+
return diagnostic && contains(errorCodes, diagnostic.code) ||
|
|
173
|
+
// A Promise is usually not correct in a binary expression (it’s not valid
|
|
174
|
+
// in an arithmetic expression and an equality comparison seems unusual),
|
|
175
|
+
// but if the other side of the binary expression has an error, the side
|
|
176
|
+
// is typed `any` which will squash the error that would identify this
|
|
177
|
+
// Promise as an invalid operand. So if the whole binary expression is
|
|
178
|
+
// typed `any` as a result, there is a strong likelihood that this Promise
|
|
179
|
+
// is accidentally missing `await`.
|
|
180
|
+
checker.getTypeAtLocation(errorNode).flags & TypeFlags.Any;
|
|
181
|
+
}
|
|
182
|
+
// Na tag, também o bloco de uma `function` declarada, de uma function expression e de um método (CK-02).
|
|
183
|
+
function isInsideAwaitableBody(node) {
|
|
184
|
+
return node.kind & NodeFlags.AwaitContext || !!findAncestor(node, ancestor => ancestor.parent && isArrowFunction(ancestor.parent) && ancestor.parent.body === ancestor ||
|
|
185
|
+
isBlock(ancestor) && (ancestor.parent.kind === SyntaxKind.ArrowFunction));
|
|
186
|
+
}
|
|
187
|
+
function makeChange(changeTracker, errorCode, sourceFile, checker, insertionSite, fixedDeclarations) {
|
|
188
|
+
if (isBinaryExpression(insertionSite)) {
|
|
189
|
+
for (const side of [insertionSite.left, insertionSite.right]) {
|
|
190
|
+
if (fixedDeclarations && isIdentifier(side)) {
|
|
191
|
+
const symbol = checker.getSymbolAtLocation(side);
|
|
192
|
+
if (symbol && fixedDeclarations.has(getSymbolId(symbol).toString())) {
|
|
193
|
+
continue;
|
|
194
|
+
}
|
|
195
|
+
}
|
|
196
|
+
const type = checker.getTypeAtLocation(side);
|
|
197
|
+
const newNode = checker.getPromisedTypeOfPromise(type) ? createAwait(side) : side;
|
|
198
|
+
changeTracker.replaceNode(sourceFile, side, newNode);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
else if (errorCode === propertyAccessCode && isPropertyAccessExpression(insertionSite.parent)) {
|
|
202
|
+
if (fixedDeclarations && isIdentifier(insertionSite.parent.expression)) {
|
|
203
|
+
const symbol = checker.getSymbolAtLocation(insertionSite.parent.expression);
|
|
204
|
+
if (symbol && fixedDeclarations.has(getSymbolId(symbol).toString())) {
|
|
205
|
+
return;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
changeTracker.replaceNode(sourceFile, insertionSite.parent.expression, createParen(createAwait(insertionSite.parent.expression)));
|
|
209
|
+
insertLeadingSemicolonIfNeeded(changeTracker, insertionSite.parent.expression, sourceFile);
|
|
210
|
+
}
|
|
211
|
+
else if (contains(callableConstructableErrorCodes, errorCode) && isCallOrNewExpression(insertionSite.parent)) {
|
|
212
|
+
if (fixedDeclarations && isIdentifier(insertionSite)) {
|
|
213
|
+
const symbol = checker.getSymbolAtLocation(insertionSite);
|
|
214
|
+
if (symbol && fixedDeclarations.has(getSymbolId(symbol).toString())) {
|
|
215
|
+
return;
|
|
216
|
+
}
|
|
217
|
+
}
|
|
218
|
+
changeTracker.replaceNode(sourceFile, insertionSite, createParen(createAwait(insertionSite)));
|
|
219
|
+
insertLeadingSemicolonIfNeeded(changeTracker, insertionSite, sourceFile);
|
|
220
|
+
}
|
|
221
|
+
else {
|
|
222
|
+
if (fixedDeclarations && isVariableDeclaration(insertionSite.parent) && isIdentifier(insertionSite.parent.name)) {
|
|
223
|
+
const symbol = checker.getSymbolAtLocation(insertionSite.parent.name);
|
|
224
|
+
if (symbol && !addToSeen(fixedDeclarations, getSymbolId(symbol))) {
|
|
225
|
+
return;
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
changeTracker.replaceNode(sourceFile, insertionSite, createAwait(insertionSite));
|
|
229
|
+
}
|
|
230
|
+
}
|
|
231
|
+
function insertLeadingSemicolonIfNeeded(changeTracker, beforeNode, sourceFile) {
|
|
232
|
+
const precedingToken = findPrecedingToken(beforeNode.pos, sourceFile);
|
|
233
|
+
if (precedingToken && positionIsASICandidate(precedingToken.end, precedingToken.parent, sourceFile)) {
|
|
234
|
+
changeTracker.insertText(sourceFile, beforeNode.getStart(sourceFile), ";");
|
|
235
|
+
}
|
|
236
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,91 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addMissingConst.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Diagnostics, NodeSet, SyntaxKind, every, findAncestor, getTokenAtPosition, isArrayLiteralExpression, isAssignmentExpression, isBinaryExpression, isExpressionStatement, isForInOrOfStatement, isIdentifier, textChanges, } from "../_namespaces/edit.js";
|
|
3
|
+
import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
|
|
4
|
+
const fixId = "addMissingConst";
|
|
5
|
+
const errorCodes = [
|
|
6
|
+
Diagnostics.Cannot_find_name_0.code,
|
|
7
|
+
Diagnostics.No_value_exists_in_scope_for_the_shorthand_property_0_Either_declare_one_or_provide_an_initializer.code
|
|
8
|
+
];
|
|
9
|
+
registerCodeFix({
|
|
10
|
+
errorCodes,
|
|
11
|
+
getCodeActions: (context) => {
|
|
12
|
+
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start, context.program));
|
|
13
|
+
if (changes.length > 0) {
|
|
14
|
+
return [createCodeFixAction(fixId, changes, Diagnostics.Add_const_to_unresolved_variable, fixId, Diagnostics.Add_const_to_all_unresolved_variables)];
|
|
15
|
+
}
|
|
16
|
+
},
|
|
17
|
+
fixIds: [fixId],
|
|
18
|
+
getAllCodeActions: context => {
|
|
19
|
+
const fixedNodes = new NodeSet();
|
|
20
|
+
return codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start, context.program, fixedNodes));
|
|
21
|
+
},
|
|
22
|
+
});
|
|
23
|
+
function makeChange(changeTracker, sourceFile, pos, program, fixedNodes) {
|
|
24
|
+
const token = getTokenAtPosition(sourceFile, pos);
|
|
25
|
+
const forInitializer = findAncestor(token, node => isForInOrOfStatement(node.parent) ? node.parent.initializer === node :
|
|
26
|
+
isPossiblyPartOfDestructuring(node) ? false : "quit");
|
|
27
|
+
if (forInitializer)
|
|
28
|
+
return applyChange(changeTracker, forInitializer, sourceFile, fixedNodes);
|
|
29
|
+
const parent = token.parent;
|
|
30
|
+
if (isBinaryExpression(parent) && parent.operatorToken.kind === SyntaxKind.EqualsToken && isExpressionStatement(parent.parent)) {
|
|
31
|
+
return applyChange(changeTracker, token, sourceFile, fixedNodes);
|
|
32
|
+
}
|
|
33
|
+
if (isArrayLiteralExpression(parent)) {
|
|
34
|
+
const checker = program.getTypeChecker();
|
|
35
|
+
if (!every(parent.elements, element => arrayElementCouldBeVariableDeclaration(element, checker))) {
|
|
36
|
+
return;
|
|
37
|
+
}
|
|
38
|
+
return applyChange(changeTracker, parent, sourceFile, fixedNodes);
|
|
39
|
+
}
|
|
40
|
+
const commaExpression = findAncestor(token, node => isExpressionStatement(node.parent) ? true :
|
|
41
|
+
isPossiblyPartOfCommaSeperatedInitializer(node) ? false : "quit");
|
|
42
|
+
if (commaExpression) {
|
|
43
|
+
const checker = program.getTypeChecker();
|
|
44
|
+
if (!expressionCouldBeVariableDeclaration(commaExpression, checker)) {
|
|
45
|
+
return;
|
|
46
|
+
}
|
|
47
|
+
return applyChange(changeTracker, commaExpression, sourceFile, fixedNodes);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
function applyChange(changeTracker, initializer, sourceFile, fixedNodes) {
|
|
51
|
+
if (!fixedNodes || fixedNodes.tryAdd(initializer)) {
|
|
52
|
+
changeTracker.insertModifierBefore(sourceFile, SyntaxKind.ConstKeyword, initializer);
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
function isPossiblyPartOfDestructuring(node) {
|
|
56
|
+
switch (node.kind) {
|
|
57
|
+
case SyntaxKind.Identifier:
|
|
58
|
+
case SyntaxKind.ArrayLiteralExpression:
|
|
59
|
+
case SyntaxKind.ObjectLiteralExpression:
|
|
60
|
+
case SyntaxKind.PropertyAssignment:
|
|
61
|
+
case SyntaxKind.ShorthandPropertyAssignment:
|
|
62
|
+
return true;
|
|
63
|
+
default:
|
|
64
|
+
return false;
|
|
65
|
+
}
|
|
66
|
+
}
|
|
67
|
+
function arrayElementCouldBeVariableDeclaration(expression, checker) {
|
|
68
|
+
const identifier = isIdentifier(expression) ? expression :
|
|
69
|
+
isAssignmentExpression(expression, /*excludeCompoundAssignment*/ true) && isIdentifier(expression.left) ? expression.left :
|
|
70
|
+
undefined;
|
|
71
|
+
return !!identifier && !checker.getSymbolAtLocation(identifier);
|
|
72
|
+
}
|
|
73
|
+
// Na tag, também a vírgula do operador vírgula (CK-02).
|
|
74
|
+
function isPossiblyPartOfCommaSeperatedInitializer(node) {
|
|
75
|
+
switch (node.kind) {
|
|
76
|
+
case SyntaxKind.Identifier:
|
|
77
|
+
case SyntaxKind.BinaryExpression:
|
|
78
|
+
return true;
|
|
79
|
+
default:
|
|
80
|
+
return false;
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
function expressionCouldBeVariableDeclaration(expression, checker) {
|
|
84
|
+
if (!isBinaryExpression(expression)) {
|
|
85
|
+
return false;
|
|
86
|
+
}
|
|
87
|
+
// Na tag, os dois lados de um operador vírgula, cada um como uma declaração (CK-02).
|
|
88
|
+
return expression.operatorToken.kind === SyntaxKind.EqualsToken
|
|
89
|
+
&& isIdentifier(expression.left)
|
|
90
|
+
&& !checker.getSymbolAtLocation(expression.left);
|
|
91
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/addNameToNamelessParameter.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Debug, Diagnostics, createParameter, createTypeReferenceNode, getTokenAtPosition, isIdentifier, isParameter, textChanges, } from "../_namespaces/edit.js";
|
|
3
|
+
import { codeFixAll, createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
|
|
4
|
+
const fixId = "addNameToNamelessParameter";
|
|
5
|
+
const errorCodes = [Diagnostics.Parameter_has_a_name_but_no_type_Did_you_mean_0_Colon_1.code];
|
|
6
|
+
registerCodeFix({
|
|
7
|
+
errorCodes,
|
|
8
|
+
getCodeActions: (context) => {
|
|
9
|
+
const changes = textChanges.ChangeTracker.with(context, t => makeChange(t, context.sourceFile, context.span.start));
|
|
10
|
+
return [createCodeFixAction(fixId, changes, Diagnostics.Add_parameter_name, fixId, Diagnostics.Add_names_to_all_parameters_without_names)];
|
|
11
|
+
},
|
|
12
|
+
fixIds: [fixId],
|
|
13
|
+
getAllCodeActions: context => codeFixAll(context, errorCodes, (changes, diag) => makeChange(changes, diag.file, diag.start)),
|
|
14
|
+
});
|
|
15
|
+
function makeChange(changeTracker, sourceFile, pos) {
|
|
16
|
+
const token = getTokenAtPosition(sourceFile, pos);
|
|
17
|
+
if (!isIdentifier(token)) {
|
|
18
|
+
return Debug.fail("add-name-to-nameless-parameter operates on identifiers, but got a " + Debug.formatSyntaxKind(token.kind));
|
|
19
|
+
}
|
|
20
|
+
const param = token.parent;
|
|
21
|
+
if (!isParameter(param)) {
|
|
22
|
+
return Debug.fail("Tried to add a parameter name to a non-parameter: " + Debug.formatSyntaxKind(token.kind));
|
|
23
|
+
}
|
|
24
|
+
const i = param.parent.parameters.indexOf(param);
|
|
25
|
+
Debug.assert(!param.type, "Tried to add a parameter name to a parameter that already had one.");
|
|
26
|
+
Debug.assert(i > -1, "Parameter not found in parent parameter list.");
|
|
27
|
+
const replacement = createParameter(param.modifiers, param.dotDotDotToken, "arg" + i, param.questionToken, createTypeReferenceNode(token, /*typeArguments*/ undefined), param.initializer);
|
|
28
|
+
changeTracker.replaceNode(sourceFile, token, replacement);
|
|
29
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
// Modificado de microsoft/TypeScript v3.9.10, src/services/codefixes/convertConstToLet.ts: o namespace virou módulo ES, com os imports explícitos.
|
|
2
|
+
import { Diagnostics, getTokenAtPosition, textChanges, } from "../_namespaces/edit.js";
|
|
3
|
+
import { createCodeFixAction, registerCodeFix, } from "../_namespaces/ts.codefix.js";
|
|
4
|
+
const fixId = "fixConvertConstToLet";
|
|
5
|
+
const errorCodes = [Diagnostics.Cannot_assign_to_0_because_it_is_a_constant.code];
|
|
6
|
+
registerCodeFix({
|
|
7
|
+
errorCodes,
|
|
8
|
+
getCodeActions: context => {
|
|
9
|
+
const { sourceFile, span, program } = context;
|
|
10
|
+
const variableStatement = getVariableStatement(sourceFile, span.start, program);
|
|
11
|
+
const changes = textChanges.ChangeTracker.with(context, t => doChange(t, sourceFile, variableStatement));
|
|
12
|
+
return [createCodeFixAction(fixId, changes, Diagnostics.Convert_const_to_let, fixId, Diagnostics.Convert_const_to_let)];
|
|
13
|
+
},
|
|
14
|
+
fixIds: [fixId]
|
|
15
|
+
});
|
|
16
|
+
function getVariableStatement(sourceFile, pos, program) {
|
|
17
|
+
const token = getTokenAtPosition(sourceFile, pos);
|
|
18
|
+
const checker = program.getTypeChecker();
|
|
19
|
+
const symbol = checker.getSymbolAtLocation(token);
|
|
20
|
+
if (symbol) {
|
|
21
|
+
return symbol.valueDeclaration.parent.parent;
|
|
22
|
+
}
|
|
23
|
+
}
|
|
24
|
+
function doChange(changes, sourceFile, variableStatement) {
|
|
25
|
+
if (!variableStatement) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const start = variableStatement.getStart();
|
|
29
|
+
changes.replaceRangeWithText(sourceFile, { pos: start, end: start + 5 }, "let");
|
|
30
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|