Skip to content

Commit

Permalink
Add language service support for const
Browse files Browse the repository at this point in the history
  • Loading branch information
mhegazy committed Oct 16, 2014
1 parent e15f4e6 commit 60bb37b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
7 changes: 6 additions & 1 deletion src/services/navigationBar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,12 @@ module ts.NavigationBar {
return createItem(node, getTextOfNode((<FunctionDeclaration>node).name), ts.ScriptElementKind.functionElement);

case SyntaxKind.VariableDeclaration:
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.variableElement);
if (node.flags & NodeFlags.Const) {
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.constantElement);
}
else {
return createItem(node, getTextOfNode((<VariableDeclaration>node).name), ts.ScriptElementKind.variableElement);
}

case SyntaxKind.Constructor:
return createItem(node, "constructor", ts.ScriptElementKind.constructorImplementationElement);
Expand Down
10 changes: 8 additions & 2 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1235,7 +1235,9 @@ module ts {

static label = "label";

static alias = "alias"
static alias = "alias";

static constantElement = "constant";
}

export class ScriptElementKindModifier {
Expand Down Expand Up @@ -2720,6 +2722,9 @@ module ts {
if (isFirstDeclarationOfSymbolParameter(symbol)) {
return ScriptElementKind.parameterElement;
}
else if(forEach(symbol.declarations, d => d.flags & NodeFlags.Const)) {

This comment has been minimized.

Copy link
@JsonFreeman

JsonFreeman Oct 16, 2014

Contributor

There should only be one declaration, right?

This comment has been minimized.

Copy link
@mhegazy

mhegazy Oct 16, 2014

Author Contributor

yes. thanks.

This comment has been minimized.

Copy link
@mhegazy

mhegazy Oct 17, 2014

Author Contributor

done.

return ScriptElementKind.constantElement;
}
return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localVariableElement : ScriptElementKind.variableElement;
}
if (flags & SymbolFlags.Function) return isLocalVariableOrFunction(symbol) ? ScriptElementKind.localFunctionElement : ScriptElementKind.functionElement;
Expand Down Expand Up @@ -2751,7 +2756,7 @@ module ts {
case SyntaxKind.ClassDeclaration: return ScriptElementKind.classElement;
case SyntaxKind.InterfaceDeclaration: return ScriptElementKind.interfaceElement;
case SyntaxKind.EnumDeclaration: return ScriptElementKind.enumElement;
case SyntaxKind.VariableDeclaration: return ScriptElementKind.variableElement;
case SyntaxKind.VariableDeclaration: return node.flags & NodeFlags.Const ? ScriptElementKind.constantElement: ScriptElementKind.variableElement;
case SyntaxKind.FunctionDeclaration: return ScriptElementKind.functionElement;
case SyntaxKind.GetAccessor: return ScriptElementKind.memberGetAccessorElement;
case SyntaxKind.SetAccessor: return ScriptElementKind.memberSetAccessorElement;
Expand Down Expand Up @@ -2840,6 +2845,7 @@ module ts {
switch (symbolKind) {
case ScriptElementKind.memberVariableElement:
case ScriptElementKind.variableElement:
case ScriptElementKind.constantElement:
case ScriptElementKind.parameterElement:
case ScriptElementKind.localVariableElement:
// If it is call or construct signature of lambda's write type name
Expand Down
7 changes: 7 additions & 0 deletions tests/cases/fourslash/completionEntryForConst.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
///<reference path="fourslash.ts" />

////const c = "s";
/////**/

goTo.marker();
verify.completionListContains("c", /*text*/ undefined, /*documentation*/ undefined, "constant");
13 changes: 13 additions & 0 deletions tests/cases/fourslash/navbar_const.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
/// <reference path="fourslash.ts" />

//// {| "itemName": "c", "kind": "constant", "parentName": "" |}const c = 0;

test.markers().forEach(marker => {
verify.getScriptLexicalStructureListContains(
marker.data.itemName,
marker.data.kind,
marker.fileName,
marker.data.parentName,
marker.data.isAdditionalRange,
marker.position);
});
6 changes: 6 additions & 0 deletions tests/cases/fourslash/quickInfoForConstDeclaration.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
/// <reference path='fourslash.ts' />

////const /**/c = 0 ;

goTo.marker();
verify.quickInfoIs("(constant) c: number");

0 comments on commit 60bb37b

Please sign in to comment.