Skip to content

Commit 5048a33

Browse files
committed
Switch public types to interfaces
1 parent 8be8e1f commit 5048a33

File tree

2 files changed

+163
-145
lines changed

2 files changed

+163
-145
lines changed

src/services/getScriptLexicalStructureWalker.ts

Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -152,69 +152,82 @@ module TypeScript.Services {
152152
}
153153
}
154154

155+
private getNavigationBarItem(text: string, kind: string, kindModifiers: string, spans: TypeScript.TextSpan[], childItems?: ts.NavigationBarItem[], indent: number = 0): ts.NavigationBarItem {
156+
return {
157+
text: text,
158+
kind: kind,
159+
kindModifiers: kindModifiers,
160+
spans: spans,
161+
childItems: childItems,
162+
indent: indent,
163+
bolded: false,
164+
grayed: false
165+
};
166+
}
167+
155168
private createChildItem(node: ISyntaxNode): ts.NavigationBarItem {
156169
switch (node.kind()) {
157170
case SyntaxKind.Parameter:
158171
var parameter = <ParameterSyntax>node;
159172
if (parameter.modifiers.length === 0) {
160173
return null;
161174
}
162-
return new ts.NavigationBarItem(parameter.identifier.text(), ts.ScriptElementKind.memberVariableElement, this.getKindModifiers(parameter.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
175+
return this.getNavigationBarItem(parameter.identifier.text(), ts.ScriptElementKind.memberVariableElement, this.getKindModifiers(parameter.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
163176

164177
case SyntaxKind.MemberFunctionDeclaration:
165178
var memberFunction = <MemberFunctionDeclarationSyntax>node;
166-
return new ts.NavigationBarItem(memberFunction.propertyName.text(), ts.ScriptElementKind.memberFunctionElement, this.getKindModifiers(memberFunction.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
179+
return this.getNavigationBarItem(memberFunction.propertyName.text(), ts.ScriptElementKind.memberFunctionElement, this.getKindModifiers(memberFunction.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
167180

168181
case SyntaxKind.GetAccessor:
169182
var getAccessor = <GetAccessorSyntax>node;
170-
return new ts.NavigationBarItem(getAccessor.propertyName.text(), ts.ScriptElementKind.memberGetAccessorElement, this.getKindModifiers(getAccessor.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
183+
return this.getNavigationBarItem(getAccessor.propertyName.text(), ts.ScriptElementKind.memberGetAccessorElement, this.getKindModifiers(getAccessor.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
171184

172185
case SyntaxKind.SetAccessor:
173186
var setAccessor = <SetAccessorSyntax>node;
174-
return new ts.NavigationBarItem(setAccessor.propertyName.text(), ts.ScriptElementKind.memberSetAccessorElement, this.getKindModifiers(setAccessor.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
187+
return this.getNavigationBarItem(setAccessor.propertyName.text(), ts.ScriptElementKind.memberSetAccessorElement, this.getKindModifiers(setAccessor.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
175188

176189
case SyntaxKind.IndexSignature:
177190
var indexSignature = <IndexSignatureSyntax>node;
178-
return new ts.NavigationBarItem("[]", ts.ScriptElementKind.indexSignatureElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
191+
return this.getNavigationBarItem("[]", ts.ScriptElementKind.indexSignatureElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
179192

180193
case SyntaxKind.EnumElement:
181194
var enumElement = <EnumElementSyntax>node;
182-
return new ts.NavigationBarItem(enumElement.propertyName.text(), ts.ScriptElementKind.memberVariableElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
195+
return this.getNavigationBarItem(enumElement.propertyName.text(), ts.ScriptElementKind.memberVariableElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
183196

184197
case SyntaxKind.CallSignature:
185198
var callSignature = <CallSignatureSyntax>node;
186-
return new ts.NavigationBarItem("()", ts.ScriptElementKind.callSignatureElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
199+
return this.getNavigationBarItem("()", ts.ScriptElementKind.callSignatureElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
187200

188201
case SyntaxKind.ConstructSignature:
189202
var constructSignature = <ConstructSignatureSyntax>node;
190-
return new ts.NavigationBarItem("new()", ts.ScriptElementKind.constructSignatureElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
203+
return this.getNavigationBarItem("new()", ts.ScriptElementKind.constructSignatureElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
191204

192205
case SyntaxKind.MethodSignature:
193206
var methodSignature = <MethodSignatureSyntax>node;
194-
return new ts.NavigationBarItem(methodSignature.propertyName.text(), ts.ScriptElementKind.memberFunctionElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
207+
return this.getNavigationBarItem(methodSignature.propertyName.text(), ts.ScriptElementKind.memberFunctionElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
195208

196209
case SyntaxKind.PropertySignature:
197210
var propertySignature = <PropertySignatureSyntax>node;
198-
return new ts.NavigationBarItem(propertySignature.propertyName.text(), ts.ScriptElementKind.memberVariableElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
211+
return this.getNavigationBarItem(propertySignature.propertyName.text(), ts.ScriptElementKind.memberVariableElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
199212

200213
case SyntaxKind.FunctionDeclaration:
201214
var functionDeclaration = <FunctionDeclarationSyntax>node;
202215
if (!this.isTopLevelFunctionDeclaration(functionDeclaration)) {
203-
return new ts.NavigationBarItem(functionDeclaration.identifier.text(), ts.ScriptElementKind.functionElement, this.getKindModifiers(functionDeclaration.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
216+
return this.getNavigationBarItem(functionDeclaration.identifier.text(), ts.ScriptElementKind.functionElement, this.getKindModifiers(functionDeclaration.modifiers), [TextSpan.fromBounds(start(node), end(node))]);
204217
}
205218
break;
206219

207220
case SyntaxKind.MemberVariableDeclaration:
208221
var memberVariableDeclaration = <MemberVariableDeclarationSyntax>node;
209-
return new ts.NavigationBarItem(memberVariableDeclaration.variableDeclarator.propertyName.text(), ts.ScriptElementKind.memberVariableElement, this.getKindModifiers(memberVariableDeclaration.modifiers), [TextSpan.fromBounds(start(memberVariableDeclaration.variableDeclarator), end(memberVariableDeclaration.variableDeclarator))]);
222+
return this.getNavigationBarItem(memberVariableDeclaration.variableDeclarator.propertyName.text(), ts.ScriptElementKind.memberVariableElement, this.getKindModifiers(memberVariableDeclaration.modifiers), [TextSpan.fromBounds(start(memberVariableDeclaration.variableDeclarator), end(memberVariableDeclaration.variableDeclarator))]);
210223

211224
case SyntaxKind.VariableDeclarator:
212225
var variableDeclarator = <VariableDeclaratorSyntax>node;
213-
return new ts.NavigationBarItem(variableDeclarator.propertyName.text(), ts.ScriptElementKind.variableElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(variableDeclarator), end(variableDeclarator))]);
226+
return this.getNavigationBarItem(variableDeclarator.propertyName.text(), ts.ScriptElementKind.variableElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(variableDeclarator), end(variableDeclarator))]);
214227

215228
case SyntaxKind.ConstructorDeclaration:
216229
var constructorDeclaration = <ConstructorDeclarationSyntax>node;
217-
return new ts.NavigationBarItem("constructor", ts.ScriptElementKind.constructorImplementationElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
230+
return this.getNavigationBarItem("constructor", ts.ScriptElementKind.constructorImplementationElement, ts.ScriptElementKindModifier.none, [TextSpan.fromBounds(start(node), end(node))]);
218231
}
219232

220233
return null;
@@ -273,7 +286,7 @@ module TypeScript.Services {
273286

274287
var childItems = this.getItemsWorker(() => this.getChildNodes(node.moduleElements), n => this.createChildItem(n));
275288

276-
return new ts.NavigationBarItem(moduleNames.join("."),
289+
return this.getNavigationBarItem(moduleNames.join("."),
277290
ts.ScriptElementKind.moduleElement,
278291
this.getKindModifiers(node.modifiers),
279292
[TextSpan.fromBounds(start(node), end(node))],
@@ -284,7 +297,7 @@ module TypeScript.Services {
284297
private createFunctionItem(node: FunctionDeclarationSyntax) {
285298
var childItems = this.getItemsWorker(() => node.block.statements, n => this.createChildItem(n));
286299

287-
return new ts.NavigationBarItem(node.identifier.text(),
300+
return this.getNavigationBarItem(node.identifier.text(),
288301
ts.ScriptElementKind.functionElement,
289302
this.getKindModifiers(node.modifiers),
290303
[TextSpan.fromBounds(start(node), end(node))],
@@ -300,7 +313,7 @@ module TypeScript.Services {
300313
}
301314

302315
this.hasGlobalNode = true;
303-
return new ts.NavigationBarItem("<global>",
316+
return this.getNavigationBarItem("<global>",
304317
ts.ScriptElementKind.moduleElement,
305318
ts.ScriptElementKindModifier.none,
306319
[TextSpan.fromBounds(start(node), end(node))],
@@ -317,7 +330,7 @@ module TypeScript.Services {
317330
: node.classElements;
318331

319332
var childItems = this.getItemsWorker(() => nodes, n => this.createChildItem(n));
320-
return new ts.NavigationBarItem(
333+
return this.getNavigationBarItem(
321334
node.identifier.text(),
322335
ts.ScriptElementKind.classElement,
323336
this.getKindModifiers(node.modifiers),
@@ -328,7 +341,7 @@ module TypeScript.Services {
328341

329342
private createEnumItem(node: TypeScript.EnumDeclarationSyntax): ts.NavigationBarItem {
330343
var childItems = this.getItemsWorker(() => node.enumElements, n => this.createChildItem(n));
331-
return new ts.NavigationBarItem(
344+
return this.getNavigationBarItem(
332345
node.identifier.text(),
333346
ts.ScriptElementKind.enumElement,
334347
this.getKindModifiers(node.modifiers),
@@ -339,7 +352,7 @@ module TypeScript.Services {
339352

340353
private createIterfaceItem(node: TypeScript.InterfaceDeclarationSyntax): ts.NavigationBarItem {
341354
var childItems = this.getItemsWorker(() => node.body.typeMembers, n => this.createChildItem(n));
342-
return new ts.NavigationBarItem(
355+
return this.getNavigationBarItem(
343356
node.identifier.text(),
344357
ts.ScriptElementKind.interfaceElement,
345358
this.getKindModifiers(node.modifiers),

0 commit comments

Comments
 (0)