Fixed semantic colorization for module names on the value side.

This commit is contained in:
Daniel Rosenwasser
2014-10-10 17:04:30 -07:00
parent 461147a356
commit 41c45a9088
5 changed files with 79 additions and 3 deletions

View File

@@ -4656,7 +4656,6 @@ module ts {
function classifySymbol(symbol: Symbol, meaningAtPosition: SemanticMeaning) {
var flags = symbol.getFlags();
// TODO(drosen): use meaningAtPosition.
if (flags & SymbolFlags.Class) {
return ClassificationTypeNames.className;
}
@@ -4672,10 +4671,25 @@ module ts {
}
}
else if (flags & SymbolFlags.Module) {
return ClassificationTypeNames.moduleName;
// Only classify a module as such if
// - It appears in a namespace context.
// - There exists a module declaration which actually impacts the value side.
if (meaningAtPosition & SemanticMeaning.Namespace ||
(meaningAtPosition & SemanticMeaning.Value && hasValueSideModule(symbol))) {
return ClassificationTypeNames.moduleName;
}
}
return undefined;
/**
* Returns true if there exists a module that introduces entities on the value side.
*/
function hasValueSideModule(symbol: Symbol): boolean {
return !!forEach(symbol.declarations, declaration => {
return declaration.kind === SyntaxKind.ModuleDeclaration && isInstantiated(declaration);
});
}
}
function processNode(node: Node) {

View File

@@ -9,4 +9,4 @@
////var M = { I: 10 };
var c = classification;
verify.semanticClassificationsAre(c.moduleName("M"), c.interfaceName("I"), c.moduleName("M"));
verify.semanticClassificationsAre(c.moduleName("M"), c.interfaceName("I"));

View File

@@ -0,0 +1,19 @@
/// <reference path="fourslash.ts"/>
////module M {
//// export interface I {
//// }
////}
////
////var M = {
//// foo: 10,
//// bar: 20
////}
////
////var v: M.I;
////
////var x = M;
var c = classification;
verify.semanticClassificationsAre(
c.moduleName("M"), c.interfaceName("I"), c.moduleName("M"), c.interfaceName("I"));

View File

@@ -0,0 +1,20 @@
/// <reference path="fourslash.ts"/>
////module M {
//// export interface I {
//// }
//// var x = 10;
////}
////
////var M = {
//// foo: 10,
//// bar: 20
////}
////
////var v: M.I;
////
////var x = M;
var c = classification;
verify.semanticClassificationsAre(
c.moduleName("M"), c.interfaceName("I"), c.moduleName("M"), c.interfaceName("I"), c.moduleName("M"));

View File

@@ -0,0 +1,23 @@
/// <reference path="fourslash.ts"/>
////module M {
//// export interface I {
//// }
////}
////
////module M {
//// var x = 10;
////}
////
////var M = {
//// foo: 10,
//// bar: 20
////}
////
////var v: M.I;
////
////var x = M;
var c = classification;
verify.semanticClassificationsAre(
c.moduleName("M"), c.interfaceName("I"), c.moduleName("M"), c.moduleName("M"), c.interfaceName("I"), c.moduleName("M"));