@@ -3673,6 +3673,93 @@ module ts {
3673
3673
return null ;
3674
3674
}
3675
3675
3676
+ function getRenameInfo ( fileName : string , position : number ) : RenameInfo {
3677
+ synchronizeHostData ( ) ;
3678
+
3679
+ fileName = TypeScript . switchToForwardSlashes ( fileName ) ;
3680
+ var sourceFile = getSourceFile ( fileName ) ;
3681
+
3682
+ var node = getNodeAtPosition ( sourceFile , position ) ;
3683
+
3684
+ // Can only rename an identifier.
3685
+ if ( node && node . kind === SyntaxKind . Identifier ) {
3686
+ var symbol = typeInfoResolver . getSymbolInfo ( node ) ;
3687
+
3688
+ // Only allow a symbol to be renamed if it actually has at least one declaration.
3689
+ if ( symbol && symbol . getDeclarations ( ) && symbol . getDeclarations ( ) . length > 0 ) {
3690
+ var kind = getKind ( symbol ) ;
3691
+ if ( kind ) {
3692
+ return RenameInfo . Create ( symbol . name , typeInfoResolver . getFullyQualifiedName ( symbol ) , kind , getKindModifiers ( symbol ) ,
3693
+ new TypeScript . TextSpan ( node . getStart ( ) , node . getWidth ( ) ) ) ;
3694
+ }
3695
+ }
3696
+ }
3697
+
3698
+ function getKindModifiers ( symbol : Symbol ) : string {
3699
+ var modifiers : string [ ] = [ ] ;
3700
+ var decl = symbol . getDeclarations ( ) [ 0 ] ;
3701
+
3702
+ if ( decl . flags & NodeFlags . Ambient ) {
3703
+ modifiers . push ( ScriptElementKindModifier . ambientModifier ) ;
3704
+ }
3705
+ if ( decl . flags & NodeFlags . Export ) {
3706
+ modifiers . push ( ScriptElementKindModifier . exportedModifier ) ;
3707
+ }
3708
+ if ( decl . flags & NodeFlags . Private ) {
3709
+ modifiers . push ( ScriptElementKindModifier . privateMemberModifier ) ;
3710
+ }
3711
+ if ( decl . flags & NodeFlags . Public ) {
3712
+ modifiers . push ( ScriptElementKindModifier . publicMemberModifier ) ;
3713
+ }
3714
+ if ( decl . flags & NodeFlags . Static ) {
3715
+ modifiers . push ( ScriptElementKindModifier . staticModifier ) ;
3716
+ }
3717
+
3718
+ return modifiers . length == 0 ? ScriptElementKindModifier . none : modifiers . join ( ',' ) ;
3719
+ }
3720
+
3721
+ function getKind ( symbol : Symbol ) : string {
3722
+ if ( symbol . flags & SymbolFlags . Module ) {
3723
+ return ScriptElementKind . moduleElement ;
3724
+ }
3725
+ else if ( symbol . flags & SymbolFlags . Class ) {
3726
+ return ScriptElementKind . classElement ;
3727
+ }
3728
+ else if ( symbol . flags & SymbolFlags . Interface ) {
3729
+ return ScriptElementKind . interfaceElement ;
3730
+ }
3731
+ else if ( symbol . flags & SymbolFlags . Enum ) {
3732
+ return ScriptElementKind . enumElement ;
3733
+ }
3734
+ else if ( symbol . flags & SymbolFlags . Variable ) {
3735
+ return ScriptElementKind . variableElement ;
3736
+ }
3737
+ else if ( symbol . flags & SymbolFlags . Function ) {
3738
+ return ScriptElementKind . functionElement ;
3739
+ }
3740
+ else if ( symbol . flags & SymbolFlags . Method ) {
3741
+ return ScriptElementKind . memberFunctionElement ;
3742
+ }
3743
+ else if ( symbol . flags & SymbolFlags . GetAccessor ) {
3744
+ return ScriptElementKind . memberGetAccessorElement ;
3745
+ }
3746
+ else if ( symbol . flags & SymbolFlags . SetAccessor ) {
3747
+ return ScriptElementKind . memberSetAccessorElement ;
3748
+ }
3749
+ else if ( symbol . flags & SymbolFlags . Property ) {
3750
+ return ScriptElementKind . memberVariableElement ;
3751
+ }
3752
+ else if ( symbol . flags & SymbolFlags . TypeParameter ) {
3753
+ return ScriptElementKind . typeParameterElement ;
3754
+ }
3755
+ else if ( symbol . flags & SymbolFlags . EnumMember ) {
3756
+ return ScriptElementKind . memberVariableElement ;
3757
+ }
3758
+ }
3759
+
3760
+ return RenameInfo . CreateError ( getLocaleSpecificMessage ( Diagnostics . You_cannot_rename_this_element . key ) ) ;
3761
+ }
3762
+
3676
3763
return {
3677
3764
dispose : dispose ,
3678
3765
cleanupSemanticCache : cleanupSemanticCache ,
@@ -3693,7 +3780,7 @@ module ts {
3693
3780
getNameOrDottedNameSpan : getNameOrDottedNameSpan ,
3694
3781
getBreakpointStatementAtPosition : getBreakpointStatementAtPosition ,
3695
3782
getNavigateToItems : ( searchValue ) => [ ] ,
3696
- getRenameInfo : ( fileName , position ) : RenameInfo => RenameInfo . CreateError ( getLocaleSpecificMessage ( Diagnostics . You_cannot_rename_this_element . key ) ) ,
3783
+ getRenameInfo : getRenameInfo ,
3697
3784
getNavigationBarItems : getNavigationBarItems ,
3698
3785
getOutliningSpans : getOutliningSpans ,
3699
3786
getTodoComments : getTodoComments ,
0 commit comments