@@ -56,7 +56,7 @@ public RemoveUnusedDeclarationQuickFix(ParserRuleContext context, QualifiedSelec
56
56
57
57
public override void Fix ( )
58
58
{
59
- if ( _target . DeclarationType == DeclarationType . Variable )
59
+ if ( _target . DeclarationType == DeclarationType . Variable || _target . DeclarationType == DeclarationType . Constant )
60
60
{
61
61
RemoveVariable ( _target ) ;
62
62
}
@@ -65,9 +65,7 @@ public override void Fix()
65
65
var module = Selection . QualifiedName . Component . CodeModule ;
66
66
var selection = Selection . Selection ;
67
67
68
- var originalCodeLines = module . Lines [ selection . StartLine , selection . LineCount ]
69
- . Replace ( "\r \n " , " " )
70
- . Replace ( "_" , string . Empty ) ;
68
+ var originalCodeLines = module . Lines [ selection . StartLine , selection . LineCount ] ;
71
69
72
70
var originalInstruction = Context . GetText ( ) ;
73
71
module . DeleteLines ( selection . StartLine , selection . LineCount ) ;
@@ -84,14 +82,12 @@ private void RemoveVariable(Declaration target)
84
82
{
85
83
Selection selection ;
86
84
var declarationText = target . Context . GetText ( ) . Replace ( " _" + Environment . NewLine , string . Empty ) ;
87
- var multipleDeclarations = target . HasMultipleDeclarationsInStatement ( ) ;
88
-
89
- var variableStmtContext = target . GetVariableStmtContext ( ) ;
85
+ var multipleDeclarations = target . DeclarationType == DeclarationType . Variable && target . HasMultipleDeclarationsInStatement ( ) ;
90
86
91
87
if ( ! multipleDeclarations )
92
88
{
93
- declarationText = variableStmtContext . GetText ( ) . Replace ( " _" + Environment . NewLine , string . Empty ) ;
94
- selection = target . GetVariableStmtContextSelection ( ) ;
89
+ declarationText = GetStmtContext ( target ) . GetText ( ) . Replace ( " _" + Environment . NewLine , string . Empty ) ;
90
+ selection = GetStmtContextSelection ( target ) ;
95
91
}
96
92
else
97
93
{
@@ -107,7 +103,7 @@ private void RemoveVariable(Declaration target)
107
103
108
104
if ( multipleDeclarations )
109
105
{
110
- selection = target . GetVariableStmtContextSelection ( ) ;
106
+ selection = GetStmtContextSelection ( target ) ;
111
107
newLines = RemoveExtraComma ( codeModule . GetLines ( selection ) . Replace ( oldLines , newLines ) ,
112
108
target . CountOfDeclarationsInStatement ( ) , target . IndexOfVariableDeclarationInStatement ( ) ) ;
113
109
}
@@ -144,6 +140,20 @@ private void RemoveVariable(Declaration target)
144
140
}
145
141
}
146
142
143
+ private Selection GetStmtContextSelection ( Declaration target )
144
+ {
145
+ return target . DeclarationType == DeclarationType . Variable
146
+ ? target . GetVariableStmtContextSelection ( )
147
+ : target . GetConstStmtContextSelection ( ) ;
148
+ }
149
+
150
+ private ParserRuleContext GetStmtContext ( Declaration target )
151
+ {
152
+ return target . DeclarationType == DeclarationType . Variable
153
+ ? ( ParserRuleContext ) target . GetVariableStmtContext ( )
154
+ : ( ParserRuleContext ) target . GetConstStmtContext ( ) ;
155
+ }
156
+
147
157
private string RemoveExtraComma ( string str , int numParams , int indexRemoved )
148
158
{
149
159
// Example use cases for this method (fields and variables):
0 commit comments