moveToNewFile: Support selecting the name of a declaration (#24331)

This commit is contained in:
Andy 2018-05-22 14:00:29 -07:00 committed by GitHub
parent 9cda2bdba0
commit 5622bc2dd6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 1 deletions

View file

@ -22,8 +22,14 @@ namespace ts.refactor {
const startNodeIndex = findIndex(statements, s => s.end > range.pos);
if (startNodeIndex === -1) return undefined;
const startStatement = statements[startNodeIndex];
if (isNamedDeclaration(startStatement) && startStatement.name && rangeContainsRange(startStatement.name, range)) {
return { first: startNodeIndex, afterLast: startNodeIndex + 1 };
}
// Can't only partially include the start node or be partially into the next node
if (range.pos > statements[startNodeIndex].getStart(file)) return undefined;
if (range.pos > startStatement.getStart(file)) return undefined;
const afterEndNodeIndex = findIndex(statements, s => s.end > range.end, startNodeIndex);
// Can't be partially into the next node
if (afterEndNodeIndex !== -1 && (afterEndNodeIndex === 0 || statements[afterEndNodeIndex].getStart(file) < range.end)) return undefined;

View file

@ -0,0 +1,19 @@
/// <reference path='fourslash.ts' />
// @Filename: /a.ts
////export {};
////function e[|f|]f() { gee(); }
////function gee() { eff(); }
verify.moveToNewFile({
newFileContents: {
"/a.ts":
`import { eff } from "./eff";
export {};
export function gee() { eff(); }`,
"/eff.ts":
`import { gee } from "./a";
export function eff() { gee(); }`,
},
});