|
18 | 18 | /// <reference path='outliningElementsCollector.ts' /> |
19 | 19 | /// <reference path='patternMatcher.ts' /> |
20 | 20 | /// <reference path='preProcess.ts' /> |
| 21 | +/// <reference path='rename.ts' /> |
21 | 22 | /// <reference path='signatureHelp.ts' /> |
22 | 23 | /// <reference path='symbolDisplay.ts' /> |
23 | 24 | /// <reference path='formatting\formatting.ts' /> |
@@ -1419,104 +1420,8 @@ namespace ts { |
1419 | 1420 |
|
1420 | 1421 | function getRenameInfo(fileName: string, position: number): RenameInfo { |
1421 | 1422 | synchronizeHostData(); |
1422 | | - |
1423 | | - const sourceFile = getValidSourceFile(fileName); |
1424 | | - const typeChecker = program.getTypeChecker(); |
1425 | | - |
1426 | 1423 | const defaultLibFileName = host.getDefaultLibFileName(host.getCompilationSettings()); |
1427 | | - const canonicalDefaultLibName = getCanonicalFileName(ts.normalizePath(defaultLibFileName)); |
1428 | | - |
1429 | | - const node = getTouchingWord(sourceFile, position, /*includeJsDocComment*/ true); |
1430 | | - |
1431 | | - if (node) { |
1432 | | - if (node.kind === SyntaxKind.Identifier || |
1433 | | - node.kind === SyntaxKind.StringLiteral || |
1434 | | - isLiteralNameOfPropertyDeclarationOrIndexAccess(node) || |
1435 | | - isThis(node)) { |
1436 | | - const symbol = typeChecker.getSymbolAtLocation(node); |
1437 | | - |
1438 | | - // Only allow a symbol to be renamed if it actually has at least one declaration. |
1439 | | - if (symbol) { |
1440 | | - const declarations = symbol.getDeclarations(); |
1441 | | - if (declarations && declarations.length > 0) { |
1442 | | - // Disallow rename for elements that are defined in the standard TypeScript library. |
1443 | | - if (forEach(declarations, isDefinedInLibraryFile)) { |
1444 | | - return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library)); |
1445 | | - } |
1446 | | - |
1447 | | - const displayName = stripQuotes(getDeclaredName(typeChecker, symbol, node)); |
1448 | | - const kind = SymbolDisplay.getSymbolKind(typeChecker, symbol, node); |
1449 | | - if (kind) { |
1450 | | - return { |
1451 | | - canRename: true, |
1452 | | - kind, |
1453 | | - displayName, |
1454 | | - localizedErrorMessage: undefined, |
1455 | | - fullDisplayName: typeChecker.getFullyQualifiedName(symbol), |
1456 | | - kindModifiers: SymbolDisplay.getSymbolModifiers(symbol), |
1457 | | - triggerSpan: createTriggerSpanForNode(node, sourceFile) |
1458 | | - }; |
1459 | | - } |
1460 | | - } |
1461 | | - } |
1462 | | - else if (node.kind === SyntaxKind.StringLiteral) { |
1463 | | - const type = getStringLiteralTypeForNode(<StringLiteral>node, typeChecker); |
1464 | | - if (type) { |
1465 | | - if (isDefinedInLibraryFile(node)) { |
1466 | | - return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_elements_that_are_defined_in_the_standard_TypeScript_library)); |
1467 | | - } |
1468 | | - else { |
1469 | | - const displayName = stripQuotes(type.text); |
1470 | | - return { |
1471 | | - canRename: true, |
1472 | | - kind: ScriptElementKind.variableElement, |
1473 | | - displayName, |
1474 | | - localizedErrorMessage: undefined, |
1475 | | - fullDisplayName: displayName, |
1476 | | - kindModifiers: ScriptElementKindModifier.none, |
1477 | | - triggerSpan: createTriggerSpanForNode(node, sourceFile) |
1478 | | - }; |
1479 | | - } |
1480 | | - } |
1481 | | - } |
1482 | | - } |
1483 | | - } |
1484 | | - |
1485 | | - return getRenameInfoError(getLocaleSpecificMessage(Diagnostics.You_cannot_rename_this_element)); |
1486 | | - |
1487 | | - function getRenameInfoError(localizedErrorMessage: string): RenameInfo { |
1488 | | - return { |
1489 | | - canRename: false, |
1490 | | - localizedErrorMessage: localizedErrorMessage, |
1491 | | - displayName: undefined, |
1492 | | - fullDisplayName: undefined, |
1493 | | - kind: undefined, |
1494 | | - kindModifiers: undefined, |
1495 | | - triggerSpan: undefined |
1496 | | - }; |
1497 | | - } |
1498 | | - |
1499 | | - function isDefinedInLibraryFile(declaration: Node) { |
1500 | | - if (defaultLibFileName) { |
1501 | | - const sourceFile = declaration.getSourceFile(); |
1502 | | - const canonicalName = getCanonicalFileName(ts.normalizePath(sourceFile.fileName)); |
1503 | | - if (canonicalName === canonicalDefaultLibName) { |
1504 | | - return true; |
1505 | | - } |
1506 | | - } |
1507 | | - return false; |
1508 | | - } |
1509 | | - |
1510 | | - function createTriggerSpanForNode(node: Node, sourceFile: SourceFile) { |
1511 | | - let start = node.getStart(sourceFile); |
1512 | | - let width = node.getWidth(sourceFile); |
1513 | | - if (node.kind === SyntaxKind.StringLiteral) { |
1514 | | - // Exclude the quotes |
1515 | | - start += 1; |
1516 | | - width -= 2; |
1517 | | - } |
1518 | | - return createTextSpan(start, width); |
1519 | | - } |
| 1424 | + return Rename.getRenameInfo(program.getTypeChecker(), defaultLibFileName, getCanonicalFileName, getValidSourceFile(fileName), position); |
1520 | 1425 | } |
1521 | 1426 |
|
1522 | 1427 | return { |
|
0 commit comments