Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
2532738
initial change
mhegazy Jul 18, 2014
2ed3de1
push newline to compilerhost instead of using sys directelly. This al…
mhegazy Jul 19, 2014
33433b8
cleanup
mhegazy Jul 19, 2014
5819fd4
Change classes into interfaces
mhegazy Jul 19, 2014
9395eea
add module to defaults, and cleanup document management
mhegazy Jul 19, 2014
05eeba5
Do not use noResolve with the LS
mhegazy Jul 19, 2014
f8767a5
wire quick info
mhegazy Jul 22, 2014
8eda35a
Ensure SimpleArrowFunctionExpression has a NodeArray as its paramter …
mhegazy Jul 22, 2014
346809b
wire in getCompletions
mhegazy Jul 23, 2014
212c184
use Map instead of StringHashTable
mhegazy Jul 23, 2014
3bfc294
Switch some more classes to interfaces
mhegazy Jul 24, 2014
e5d8103
remove dependency on settings
mhegazy Jul 24, 2014
e23ff87
use Map instead of IIndexable
mhegazy Jul 24, 2014
5777320
remove unused files
mhegazy Jul 24, 2014
87763db
Move ByteOrderMark to services
mhegazy Jul 24, 2014
3877169
Delete unused files
mhegazy Jul 24, 2014
b4d5b98
Remove unused type
mhegazy Jul 24, 2014
52688af
Switch LanguageService from a class to a function
mhegazy Jul 24, 2014
410a657
Remove the "I" prefix from interface names
mhegazy Jul 24, 2014
cb3f8c1
switch some more classes to interfaces
mhegazy Jul 24, 2014
580eaeb
some more cleanup
mhegazy Jul 24, 2014
02fa159
move TypeScriptServicesFactory to shims.ts
mhegazy Jul 24, 2014
944195e
only expose needed types
mhegazy Jul 24, 2014
2475049
remove the 'I' prefix from interface names
mhegazy Jul 24, 2014
4182698
Clean up code and types in typeScriptServices.ts
mhegazy Jul 24, 2014
7421970
remove unused diagnostics interfaces
mhegazy Jul 24, 2014
6ed29c2
Switch classifer to a function
mhegazy Jul 24, 2014
4a4c749
clean up coreServices
mhegazy Jul 24, 2014
2dfd63e
consolidate all services in one file: services.ts
mhegazy Jul 24, 2014
bfdf2ac
remove some more unused files
mhegazy Jul 24, 2014
792f9c9
reorganize definitions
mhegazy Jul 24, 2014
f1ef966
Switch classes to interfaces
mhegazy Jul 24, 2014
70b8a56
move logInternalError to where it is used
mhegazy Jul 24, 2014
4afbcf7
Add Logger definition to services.ts
mhegazy Jul 24, 2014
7d5da6c
remove the I prefix from interface name
mhegazy Jul 24, 2014
6ca9a1a
Move updated code to the ts namespace
mhegazy Jul 25, 2014
2b04bcf
merge keyword completions in services.ts
mhegazy Jul 25, 2014
f8f061a
merge completion helpers in services.ts
mhegazy Jul 25, 2014
ee8c4e9
remove _ prefix when applicable
mhegazy Jul 25, 2014
89161c7
move DocumentRegistry to an interface
mhegazy Jul 25, 2014
87ddcbf
switch document to an interface
mhegazy Jul 25, 2014
e9f0c0a
Fix noimplicitany issues
mhegazy Jul 25, 2014
96a9cc9
remove unneded ts. qualifiers
mhegazy Jul 25, 2014
eb9fa72
Add missing getNewLine method to test implementations of CompilerHost
mhegazy Jul 25, 2014
9061e58
Change services output file name to typescriptservices.js
mhegazy Jul 25, 2014
4e57024
remove unused methods
mhegazy Jul 25, 2014
c6c77ea
move todoComment tests to old for now
mhegazy Jul 25, 2014
d4ba45c
move failing tests to old
mhegazy Jul 29, 2014
17f7ed5
delete unused file
mhegazy Jul 29, 2014
85393ab
enable formatting tests
mhegazy Jul 29, 2014
0a08a42
enbale fourslash tests
mhegazy Jul 29, 2014
4ad7452
Enable passing fourslash tests
mhegazy Jul 29, 2014
a6e87cd
enable fourslash tests by default
mhegazy Jul 29, 2014
7faad38
remove unused interface
mhegazy Jul 29, 2014
648af38
react to changes after rebase
mhegazy Jul 29, 2014
f5091c2
Use correct casing for file references
mhegazy Jul 29, 2014
9906699
update error positions after rebase
mhegazy Jul 29, 2014
0a206d8
Respond to code review comments:
mhegazy Jul 30, 2014
6143636
Merge branch 'master' into ls
mhegazy Aug 1, 2014
732ffc0
More changes to address code review comments
mhegazy Aug 1, 2014
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
12 changes: 5 additions & 7 deletions Jakefile
Original file line number Diff line number Diff line change
Expand Up @@ -62,19 +62,17 @@ var servicesSources = [
var harnessSources = [
"harness.ts",
"sourceMapRecorder.ts",
// TODO Re-enable
// "harnessLanguageService.ts",
// "fourslash.ts",
"runner.ts",
"harnessLanguageService.ts",
"fourslash.ts",
"external/json2.ts",
"runnerbase.ts",
"compilerRunner.ts",
"typeWriter.ts",
// TODO Re-enable fourslash and project tests
// "fourslashRunner.ts",
"fourslashRunner.ts",
"projectsRunner.ts",
"unittestrunner.ts",
"rwcRunner.ts",
"runner.ts"
].map(function (f) {
return path.join(harnessDirectory, f);
});
Expand Down Expand Up @@ -233,7 +231,7 @@ task("generate-diagnostics", [diagnosticInfoMapTs])
var tcFile = path.join(builtLocalDirectory, "tc.js");
compileFile(tcFile, compilerSources, [builtLocalDirectory, copyright].concat(compilerSources), [copyright], /*useBuiltCompiler:*/ false);

var tcServicesFile = path.join(builtLocalDirectory, "services.js");
var tcServicesFile = path.join(builtLocalDirectory, "typescriptServices.js");
compileFile(tcServicesFile, servicesSources, [builtLocalDirectory, copyright].concat(servicesSources), [copyright], /*useBuiltCompiler:*/ true);

// Local target to build the compiler and services
Expand Down
138 changes: 93 additions & 45 deletions src/compiler/checker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,32 @@ module ts {
var diagnostics: Diagnostic[] = [];
var diagnosticsModified: boolean = false;

var checker: TypeChecker;
var checker: TypeChecker = {
getProgram: () => program,
getDiagnostics: getDiagnostics,
getGlobalDiagnostics: getGlobalDiagnostics,
getNodeCount: () => sum(program.getSourceFiles(), "nodeCount"),
getIdentifierCount: () => sum(program.getSourceFiles(), "identifierCount"),
getSymbolCount: () => sum(program.getSourceFiles(), "symbolCount"),
getTypeCount: () => typeCount,
checkProgram: checkProgram,
emitFiles: invokeEmitter,
getSymbolOfNode: getSymbolOfNode,
getParentOfSymbol: getParentOfSymbol,
getTypeOfSymbol: getTypeOfSymbol,
getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol,
getPropertiesOfType: getPropertiesOfType,
getSignaturesOfType: getSignaturesOfType,
getIndexTypeOfType: getIndexTypeOfType,
getReturnTypeOfSignature: getReturnTypeOfSignature,
resolveEntityName: resolveEntityName,
getSymbolsInScope: getSymbolsInScope,
getSymbolOfIdentifier: getSymbolOfIdentifier,
getTypeOfExpression: getTypeOfExpression,
typeToString: typeToString,
symbolToString: symbolToString,
getAugmentedPropertiesOfApparentType: getAugmentedPropertiesOfApparentType
};

function addDiagnostic(diagnostic: Diagnostic) {
diagnostics.push(diagnostic);
Expand Down Expand Up @@ -739,10 +764,10 @@ module ts {
};
}

function typeToString(type: Type, flags?: TypeFormatFlags): string {
function typeToString(type: Type, enclosingDeclaration?:Node, flags?: TypeFormatFlags): string {
var stringWriter = createSingleLineTextWriter();
// TODO(shkamat): typeToString should take enclosingDeclaration as input, once we have implemented enclosingDeclaration
writeTypeToTextWriter(type, /*enclosingDeclaration*/ null, flags, stringWriter);
writeTypeToTextWriter(type, enclosingDeclaration, flags, stringWriter);
return stringWriter.getText();
}

Expand Down Expand Up @@ -1379,7 +1404,7 @@ module ts {
type.baseTypes.push(baseType);
}
else {
error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, TypeFormatFlags.WriteArrayAsGenericType));
error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
}
}
else {
Expand Down Expand Up @@ -1420,7 +1445,7 @@ module ts {
type.baseTypes.push(baseType);
}
else {
error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, TypeFormatFlags.WriteArrayAsGenericType));
error(declaration, Diagnostics.Type_0_recursively_references_itself_as_a_base_type, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType));
}
}
else {
Expand Down Expand Up @@ -1987,7 +2012,7 @@ module ts {
type = createTypeReference(<GenericType>type, map(node.typeArguments, t => getTypeFromTypeNode(t)));
}
else {
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length);
error(node, Diagnostics.Generic_type_0_requires_1_type_argument_s, typeToString(type, /*enclosingDeclaration*/ undefined, TypeFormatFlags.WriteArrayAsGenericType), typeParameters.length);
type = undefined;
}
}
Expand Down Expand Up @@ -2387,7 +2412,7 @@ module ts {

var errorInfo = chainDiagnosticMessages(undefined, Diagnostics.Named_properties_0_of_types_1_and_2_are_not_identical, prop.name, typeName1, typeName2);
errorInfo = chainDiagnosticMessages(errorInfo, Diagnostics.Interface_0_cannot_simultaneously_extend_types_1_and_2_Colon, typeToString(type), typeName1, typeName2);
addDiagnostic(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo));
addDiagnostic(createDiagnosticForNodeFromMessageChain(typeNode, errorInfo, program.getCompilerHost().getNewLine()));
}
}
}
Expand Down Expand Up @@ -2434,7 +2459,7 @@ module ts {
error(errorNode, Diagnostics.Excessive_stack_depth_comparing_types_0_and_1, typeToString(source), typeToString(target));
}
else if (errorInfo) {
addDiagnostic(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo));
addDiagnostic(createDiagnosticForNodeFromMessageChain(errorNode, errorInfo, program.getCompilerHost().getNewLine()));
}
return result;

Expand Down Expand Up @@ -4784,14 +4809,6 @@ module ts {
return (node.flags & NodeFlags.Private) && isInAmbientContext(node);
}

function isInAmbientContext(node: Node): boolean {
while (node) {
if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) return true;
node = node.parent;
}
return false;
}

function checkSpecializedSignatureDeclaration(signatureDeclarationNode: SignatureDeclaration): void {
var signature = getSignatureFromDeclaration(signatureDeclarationNode);
if (!signature.hasStringLiterals) {
Expand Down Expand Up @@ -6181,7 +6198,7 @@ module ts {
// True if the given identifier is part of a type reference
function isTypeReferenceIdentifier(identifier: Identifier): boolean {
var node: Node = identifier;
while (node.parent && node.parent.kind === SyntaxKind.QualifiedName) node = node.parent;
if (node.parent && node.parent.kind === SyntaxKind.QualifiedName) node = node.parent;
return node.parent && node.parent.kind === SyntaxKind.TypeReference;
}

Expand Down Expand Up @@ -6245,27 +6262,79 @@ module ts {
return false;
}

function isRightSideOfQualifiedName(node: Node) {
return (node.parent.kind === SyntaxKind.QualifiedName || node.parent.kind === SyntaxKind.PropertyAccess) &&
(<QualifiedName>node.parent).right === node;
}

function getSymbolOfIdentifier(identifier: Identifier) {
if (isExpression(identifier)) {
if (isRightSideOfQualifiedName()) {
// TODO
if (isRightSideOfQualifiedName(identifier)) {
var node = <QualifiedName>identifier.parent;
var symbol = getNodeLinks(node).resolvedSymbol;
if (!symbol) {
checkPropertyAccess(node);
}
return getNodeLinks(node).resolvedSymbol;
}
return resolveEntityName(identifier, identifier, SymbolFlags.Value);
}
if (isDeclarationIdentifier(identifier)) {
return getSymbolOfNode(identifier.parent);
}
if (isTypeReferenceIdentifier(identifier)) {
var entityName = isRightSideOfQualifiedName() ? identifier.parent : identifier;
var entityName = isRightSideOfQualifiedName(identifier) ? identifier.parent : identifier;
var meaning = entityName.parent.kind === SyntaxKind.TypeReference ? SymbolFlags.Type : SymbolFlags.Namespace;
return resolveEntityName(entityName, entityName, meaning);
}
function isRightSideOfQualifiedName() {
return (identifier.parent.kind === SyntaxKind.QualifiedName || identifier.parent.kind === SyntaxKind.PropertyAccess) &&
(<QualifiedName>identifier.parent).right === identifier;
}

function getTypeOfExpression(node: Node) {
if (isExpression(node)) {
while (isRightSideOfQualifiedName(node)) {
node = node.parent;
}
return <Type>getApparentType(checkExpression(node));
}
return unknownType;
}

function getAugmentedPropertiesOfApparentType(type: Type): Symbol[]{
var apparentType = getApparentType(type);

if (apparentType.flags & TypeFlags.ObjectType) {
// Augment the apprent type with Function and Object memeber as applicaple
var propertiesByName: Map<Symbol> = {};
var results: Symbol[] = [];

forEach(getPropertiesOfType(apparentType), (s) => {
propertiesByName[s.name] = s;
results.push(s);
});

var resolved = resolveObjectTypeMembers(<ObjectType>type);
forEachValue(resolved.members, (s) => {
if (symbolIsValue(s) && !propertiesByName[s.name]) {
propertiesByName[s.name] = s;
results.push(s);
}
});

if (resolved === anyFunctionType || resolved.callSignatures.length || resolved.constructSignatures.length) {
forEach(getPropertiesOfType(globalFunctionType), (s) => {
if (!propertiesByName[s.name]) {
propertiesByName[s.name] = s;
results.push(s);
}
});
}

return results;
}
else {
return getPropertiesOfType(<Type>apparentType);
}
}
// Emitter support

function isExternalModuleSymbol(symbol: Symbol): boolean {
Expand Down Expand Up @@ -6459,28 +6528,7 @@ module ts {
}

initializeTypeChecker();
checker = {
getProgram: () => program,
getDiagnostics: getDiagnostics,
getGlobalDiagnostics: getGlobalDiagnostics,
getNodeCount: () => sum(program.getSourceFiles(), "nodeCount"),
getIdentifierCount: () => sum(program.getSourceFiles(), "identifierCount"),
getSymbolCount: () => sum(program.getSourceFiles(), "symbolCount"),
getTypeCount: () => typeCount,
checkProgram: checkProgram,
emitFiles: invokeEmitter,
getSymbolOfNode: getSymbolOfNode,
getParentOfSymbol: getParentOfSymbol,
getTypeOfSymbol: getTypeOfSymbol,
getDeclaredTypeOfSymbol: getDeclaredTypeOfSymbol,
getPropertiesOfType: getPropertiesOfType,
getSignaturesOfType: getSignaturesOfType,
getIndexTypeOfType: getIndexTypeOfType,
getReturnTypeOfSignature: getReturnTypeOfSignature,
resolveEntityName: resolveEntityName,
getSymbolsInScope: getSymbolsInScope,
getSymbolOfIdentifier: getSymbolOfIdentifier
};

return checker;
}
}
16 changes: 14 additions & 2 deletions src/compiler/core.ts
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,18 @@ module ts {
return result;
}

export function forEachKey<T, U>(map: Map<T>, callback: (key: string) => U): U {
var result: U;
for (var id in map) {
if (result = callback(id)) break;
}
return result;
}

export function lookUp<T>(map: Map<T>, key: string): T {
return hasProperty(map, key) ? map[key] : undefined;
}

export function mapToArray<T>(map: Map<T>): T[] {
var result: T[] = [];
for (var id in map) result.push(map[id]);
Expand Down Expand Up @@ -214,15 +226,15 @@ module ts {
}
}

export function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain): Diagnostic {
export function flattenDiagnosticChain(file: SourceFile, start: number, length: number, diagnosticChain: DiagnosticMessageChain, newLine: string): Diagnostic {
var code = diagnosticChain.code;
var category = diagnosticChain.category;
var messageText = "";

var indent = 0;
while (diagnosticChain) {
if (indent) {
messageText += sys.newLine;
messageText += newLine;

for (var i = 0; i < indent; i++) {
messageText += " ";
Expand Down
5 changes: 3 additions & 2 deletions src/compiler/emitter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ module ts {
var compilerOptions = program.getCompilerOptions();
var sourceMapDataList: SourceMapData[] = compilerOptions.sourceMap ? [] : undefined;
var diagnostics: Diagnostic[] = [];
var newLine = program.getCompilerHost().getNewLine();

function getSourceFilePathInNewDir(newDirPath: string, sourceFile: SourceFile) {
var sourceFilePath = getNormalizedPathFromPathCompoments(getNormalizedPathComponents(sourceFile.filename, compilerHost.getCurrentDirectory()));
Expand Down Expand Up @@ -126,7 +127,7 @@ module ts {

function writeLine() {
if (!lineStart) {
output += sys.newLine;
output += newLine;
lineCount++;
linePos = output.length;
lineStart = true;
Expand Down Expand Up @@ -2252,7 +2253,7 @@ module ts {
compilerHost.getCurrentDirectory(),
/*isAbsolutePathAnUrl*/ false);

referencePathsOutput += "/// <reference path='" + declFileName + "' />" + sys.newLine;
referencePathsOutput += "/// <reference path='" + declFileName + "' />" + newLine;
}

if (root) {
Expand Down
19 changes: 16 additions & 3 deletions src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -88,12 +88,12 @@ module ts {
return createFileDiagnostic(file, start, length, message, arg0, arg1, arg2);
}

export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain): Diagnostic {
export function createDiagnosticForNodeFromMessageChain(node: Node, messageChain: DiagnosticMessageChain, newLine: string): Diagnostic {
node = getErrorSpanForNode(node);
var file = getSourceFileOfNode(node);
var start = skipTrivia(file.text, node.pos);
var length = node.end - start;
return flattenDiagnosticChain(file, start, length, messageChain);
return flattenDiagnosticChain(file, start, length, messageChain, newLine);
}

export function getErrorSpanForNode(node: Node): Node {
Expand Down Expand Up @@ -327,6 +327,14 @@ module ts {
return s.parameters.length > 0 && (s.parameters[s.parameters.length - 1].flags & NodeFlags.Rest) !== 0;
}

export function isInAmbientContext(node: Node): boolean {
while (node) {
if (node.flags & (NodeFlags.Ambient | NodeFlags.DeclarationFile)) return true;
node = node.parent;
}
return false;
}

enum ParsingContext {
SourceElements, // Elements in source file
ModuleElements, // Elements in module declaration
Expand Down Expand Up @@ -1624,7 +1632,12 @@ module ts {
parameter.name = identifier;
finishNode(parameter);

var signature = <ParsedSignature> { parameters: [parameter] };
var parameters = <NodeArray<ParameterDeclaration>>[];
parameters.push(parameter);
parameters.pos = parameter.pos;
parameters.end = parameter.end;

var signature = <ParsedSignature> { parameters: parameters };

return parseArrowExpressionTail(identifier.pos, signature, /*noIn:*/ false);
}
Expand Down
3 changes: 2 additions & 1 deletion src/compiler/tc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,8 @@ module ts {
writeFile: writeFile,
getCurrentDirectory: () => currentDirectory || (currentDirectory = sys.getCurrentDirectory()),
useCaseSensitiveFileNames: () => sys.useCaseSensitiveFileNames,
getCanonicalFileName: getCanonicalFileName
getCanonicalFileName: getCanonicalFileName,
getNewLine: () => sys.newLine
};
}

Expand Down
Loading