Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit d88ea4e

Browse filesBrowse files
author
Jesse Trinity
committed
address PR comments
1 parent ca58c0e commit d88ea4e
Copy full SHA for d88ea4e

12 files changed

+37-16Lines changed: 37 additions & 16 deletions
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎src/services/codefixes/generateAccessors.ts‎

Copy file name to clipboardExpand all lines: src/services/codefixes/generateAccessors.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,9 @@ namespace ts.codefix {
104104
return modifierFlags;
105105
}
106106

107-
export function getAccessorConvertiblePropertyAtPosition(file: SourceFile, start: number, end: number, userRequested = true): Info | undefined {
107+
export function getAccessorConvertiblePropertyAtPosition(file: SourceFile, start: number, end: number, considerEmptySpans = true): Info | undefined {
108108
const node = getTokenAtPosition(file, start);
109-
const cursorRequest = start === end && userRequested;
109+
const cursorRequest = start === end && considerEmptySpans;
110110
const declaration = findAncestor(node.parent, isAcceptedDeclaration);
111111
// make sure declaration have AccessibilityModifier or Static Modifier or Readonly Modifier
112112
const meaning = ModifierFlags.AccessibilityModifier | ModifierFlags.Static | ModifierFlags.Readonly;
Collapse file

‎src/services/refactors/addOrRemoveBracesToArrowFunction.ts‎

Copy file name to clipboardExpand all lines: src/services/refactors/addOrRemoveBracesToArrowFunction.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,12 @@ namespace ts.refactor.addOrRemoveBracesToArrowFunction {
7070
return { renameFilename: undefined, renameLocation: undefined, edits };
7171
}
7272

73-
function getConvertibleArrowFunctionAtPosition(file: SourceFile, startPosition: number, userRequested = true): Info | undefined {
73+
function getConvertibleArrowFunctionAtPosition(file: SourceFile, startPosition: number, considerFunctionBodies = true): Info | undefined {
7474
const node = getTokenAtPosition(file, startPosition);
7575
const func = getContainingFunction(node);
7676
// Only offer a refactor in the function body on explicit refactor requests.
7777
if (!func || !isArrowFunction(func) || (!rangeContainsRange(func, node)
78-
|| (rangeContainsRange(func.body, node) && !userRequested))) return undefined;
78+
|| (rangeContainsRange(func.body, node) && !considerFunctionBodies))) return undefined;
7979

8080
if (isExpression(func.body)) {
8181
return {
Collapse file

‎src/services/refactors/convertExport.ts‎

Copy file name to clipboardExpand all lines: src/services/refactors/convertExport.ts
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,11 @@ namespace ts.refactor {
2727
readonly exportingModuleSymbol: Symbol;
2828
}
2929

30-
function getInfo(context: RefactorContext, userRequested = true): Info | undefined {
30+
function getInfo(context: RefactorContext, considerPartialSpans = true): Info | undefined {
3131
const { file } = context;
3232
const span = getRefactorContextSpan(context);
3333
const token = getTokenAtPosition(file, span.start);
34-
const cursorRequest = userRequested && span;
35-
const exportNode = !!(getSyntacticModifierFlags(token.parent) & ModifierFlags.Export) && cursorRequest ? token.parent : getParentNodeInSpan(token, file, span);
34+
const exportNode = !!(token.parent && getSyntacticModifierFlags(token.parent) & ModifierFlags.Export) && considerPartialSpans ? token.parent : getParentNodeInSpan(token, file, span);
3635
if (!exportNode || (!isSourceFile(exportNode.parent) && !(isModuleBlock(exportNode.parent) && isAmbientModule(exportNode.parent.parent)))) {
3736
return undefined;
3837
}
Collapse file

‎src/services/refactors/convertImport.ts‎

Copy file name to clipboardExpand all lines: src/services/refactors/convertImport.ts
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,11 @@ namespace ts.refactor {
1919
});
2020

2121
// Can convert imports of the form `import * as m from "m";` or `import d, { x, y } from "m";`.
22-
function getImportToConvert(context: RefactorContext, userRequested = true): NamedImportBindings | undefined {
22+
function getImportToConvert(context: RefactorContext, considerPartialSpans = true): NamedImportBindings | undefined {
2323
const { file } = context;
2424
const span = getRefactorContextSpan(context);
2525
const token = getTokenAtPosition(file, span.start);
26-
const cursorRequest = userRequested && span.length === 0;
27-
const importDecl = cursorRequest ? findAncestor(token, isImportDeclaration) : getParentNodeInSpan(token, file, span);
26+
const importDecl = considerPartialSpans ? findAncestor(token, isImportDeclaration) : getParentNodeInSpan(token, file, span);
2827
if (!importDecl || !isImportDeclaration(importDecl) || (importDecl.getEnd() < span.start + span.length)) return undefined;
2928
const { importClause } = importDecl;
3029
return importClause && importClause.namedBindings;
Collapse file

‎src/services/refactors/extractSymbol.ts‎

Copy file name to clipboardExpand all lines: src/services/refactors/extractSymbol.ts
+3-3Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -186,12 +186,12 @@ namespace ts.refactor.extractSymbol {
186186
* not shown to the user, but can be used by us diagnostically)
187187
*/
188188
// exported only for tests
189-
export function getRangeToExtract(sourceFile: SourceFile, span: TextSpan, userRequested = true): RangeToExtract {
189+
export function getRangeToExtract(sourceFile: SourceFile, span: TextSpan, considerEmptySpans = true): RangeToExtract {
190190
const { length } = span;
191-
if (length === 0 && !userRequested) {
191+
if (length === 0 && !considerEmptySpans) {
192192
return { errors: [createFileDiagnostic(sourceFile, span.start, length, Messages.cannotExtractEmpty)] };
193193
}
194-
const cursorRequest = length === 0 && userRequested;
194+
const cursorRequest = length === 0 && considerEmptySpans;
195195

196196
// Walk up starting from the the start position until we find a non-SourceFile node that subsumes the selected span.
197197
// This may fail (e.g. you select two statements in the root of a source file)
Collapse file

‎src/services/refactors/extractType.ts‎

Copy file name to clipboardExpand all lines: src/services/refactors/extractType.ts
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -58,12 +58,12 @@ namespace ts.refactor {
5858

5959
type Info = TypeAliasInfo | InterfaceInfo;
6060

61-
function getRangeToExtract(context: RefactorContext, userRequested = true): Info | undefined {
61+
function getRangeToExtract(context: RefactorContext, considerEmptySpans = true): Info | undefined {
6262
const { file, startPosition } = context;
6363
const isJS = isSourceFileJS(file);
6464
const current = getTokenAtPosition(file, startPosition);
6565
const range = createTextRangeFromSpan(getRefactorContextSpan(context));
66-
const cursorRequest = range.pos === range.end && userRequested;
66+
const cursorRequest = range.pos === range.end && considerEmptySpans;
6767

6868
const selection = findAncestor(current, (node => node.parent && isTypeNode(node) && !rangeContainsSkipTrivia(range, node.parent, file) &&
6969
(cursorRequest || nodeOverlapsWithStartEnd(current, file, range.pos, range.end))));
Collapse file

‎…BracesToArrowFunctionForTriggerReason.ts‎ ‎…racesToArrowFunctionForTriggerReason1.ts‎tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunctionForTriggerReason.ts renamed to tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunctionForTriggerReason1.ts tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunctionForTriggerReason.ts renamed to tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunctionForTriggerReason1.ts

Copy file name to clipboardExpand all lines: tests/cases/fourslash/refactorAddOrRemoveBracesToArrowFunctionForTriggerReason1.ts
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
//// const a = (a: number) => { return/*a*//*b*/ a; };
44

5-
// Only offer refactor for empty span if explicity requested
5+
// Only offer refactor for empty span in body if explicity requested
66
goTo.select("a", "b");
77
verify.not.refactorAvailableForTriggerReason("implicit", "Add or remove braces in an arrow function");
88
verify.refactorAvailableForTriggerReason("invoked", "Add or remove braces in an arrow function", "Remove braces from arrow function");
Collapse file
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
//// const a = (a: number) => { re/*a*/tur/*b*/n a; };
4+
5+
// Only offer refactor in body if explicity requested
6+
goTo.select("a", "b");
7+
verify.not.refactorAvailableForTriggerReason("implicit", "Add or remove braces in an arrow function");
8+
verify.refactorAvailableForTriggerReason("invoked", "Add or remove braces in an arrow function", "Remove braces from arrow function");
Collapse file

‎…refactorConvertImportForTriggerReason.ts‎ ‎…efactorConvertImportForTriggerReason1.ts‎tests/cases/fourslash/refactorConvertImportForTriggerReason.ts renamed to tests/cases/fourslash/refactorConvertImportForTriggerReason1.ts tests/cases/fourslash/refactorConvertImportForTriggerReason.ts renamed to tests/cases/fourslash/refactorConvertImportForTriggerReason1.ts

Copy file name to clipboard
File renamed without changes.
Collapse file
+8Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
/// <reference path='fourslash.ts' />
2+
3+
////import d, * as /*a*/n/*b*/ from "m";
4+
5+
// Only offer refactor for sub span if explicity requested
6+
goTo.select("a", "b");
7+
verify.not.refactorAvailableForTriggerReason("implicit", "Convert import");
8+
verify.refactorAvailableForTriggerReason("invoked", "Convert import");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.