Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
361 changes: 207 additions & 154 deletions src/compiler/checker.ts

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion src/compiler/parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3582,7 +3582,7 @@ module ts {
getCompilerHost: () => host,
getDiagnostics: getDiagnostics,
getGlobalDiagnostics: getGlobalDiagnostics,
getTypeChecker: () => createTypeChecker(program),
getTypeChecker: fullTypeCheckMode => createTypeChecker(program, fullTypeCheckMode),
getCommonSourceDirectory: () => commonSourceDirectory,
};
return program;
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/tsc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ module ts {
var reportStart = bindStart;
}
else {
var checker = program.getTypeChecker();
var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
var checkStart = new Date().getTime();
var semanticErrors = checker.getDiagnostics();
var emitStart = new Date().getTime();
Expand Down
2 changes: 1 addition & 1 deletion src/compiler/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -537,7 +537,7 @@ module ts {
getCompilerHost(): CompilerHost;
getDiagnostics(sourceFile?: SourceFile): Diagnostic[];
getGlobalDiagnostics(): Diagnostic[];
getTypeChecker(): TypeChecker;
getTypeChecker(fullTypeCheckMode: boolean): TypeChecker;
getCommonSourceDirectory(): string;
}

Expand Down
2 changes: 1 addition & 1 deletion src/harness/fourslash.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1904,7 +1904,7 @@ module FourSlash {

var host = Harness.Compiler.createCompilerHost(files, (fn, contents) => result = contents);
var program = ts.createProgram([fourslashFilename, fileName], { out: "fourslashTestOutput.js" }, host);
var checker = ts.createTypeChecker(program);
var checker = ts.createTypeChecker(program, /*fullTypeCheckMode*/ true);
checker.checkProgram();

var errs = checker.getDiagnostics(files[fileName]);
Expand Down
2 changes: 1 addition & 1 deletion src/harness/harness.ts
Original file line number Diff line number Diff line change
Expand Up @@ -736,7 +736,7 @@ module Harness {

var hadParseErrors = program.getDiagnostics().length > 0;

var checker = program.getTypeChecker();
var checker = program.getTypeChecker(/*fullTypeCheckMode*/ true);
checker.checkProgram();

// only emit if there weren't parse errors
Expand Down
2 changes: 1 addition & 1 deletion src/harness/projectsRunner.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ class ProjectRunner extends RunnerBase {
var errors = program.getDiagnostics();
var sourceMapData: ts.SourceMapData[] = null;
if (!errors.length) {
var checker = program.getTypeChecker();
var checker = program.getTypeChecker(/*fullTypeCheck*/ true);
errors = checker.getDiagnostics();
var emitResult = checker.emitFiles();
errors = ts.concatenate(errors, emitResult.errors);
Expand Down
40 changes: 25 additions & 15 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1256,7 +1256,11 @@ module ts {
var formattingRulesProvider: TypeScript.Services.Formatting.RulesProvider;
var hostCache: HostCache; // A cache of all the information about the files on the host side.
var program: Program;
var typeChecker: TypeChecker;
// this checker is used to answer all LS questions except errors
var typeInfoResolver: TypeChecker;
// the sole purpose of this checkes is to reutrn semantic diagnostics
// creation is deferred - use getFullTypeCheckChecker to get instance
var fullTypeCheckChecker_doNotAccessDirectly: TypeChecker;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i do not really care for the name that much. and this is used in only one place, so the extra layer of abstraction, is not really useful, i would just put it in getSemanticDiagnostics, to recreate if it does not exist and forget about it.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My preference in avoiding errors is to leave only one way that will do things right. Since accessing variable directly might fail without prior check - then this only was should be "always use function, do not touch the variable"

var useCaseSensitivefilenames = false;
var sourceFilesByName: Map<SourceFile> = {};
var documentRegistry = documentRegistry;
Expand All @@ -1272,6 +1276,10 @@ module ts {
return lookUp(sourceFilesByName, filename);
}

function getFullTypeCheckChecker() {
return fullTypeCheckChecker_doNotAccessDirectly || (fullTypeCheckChecker_doNotAccessDirectly = program.getTypeChecker(/*fullTypeCheck*/ true));
}

function createCompilerHost(): CompilerHost {
return {
getSourceFile: (filename, languageVersion) => {
Expand Down Expand Up @@ -1403,15 +1411,17 @@ module ts {

// Now create a new compiler
program = createProgram(hostfilenames, compilationSettings, createCompilerHost());
typeChecker = program.getTypeChecker();
typeInfoResolver = program.getTypeChecker(/*fullTypeCheckMode*/ false);
fullTypeCheckChecker_doNotAccessDirectly = undefined;
}

/// Clean up any semantic caches that are not needed.
/// The host can call this method if it wants to jettison unused memory.
/// We will just dump the typeChecker and recreate a new one. this should have the effect of destroying all the semantic caches.
function cleanupSemanticCache(): void {
if (program) {
typeChecker = program.getTypeChecker();
typeInfoResolver = program.getTypeChecker(/*fullTypeCheckMode*/ false);
fullTypeCheckChecker_doNotAccessDirectly = undefined;
}
}

Expand All @@ -1436,7 +1446,7 @@ module ts {

filename = TypeScript.switchToForwardSlashes(filename)

return typeChecker.getDiagnostics(getSourceFile(filename).getSourceFile());
return getFullTypeCheckChecker().getDiagnostics(getSourceFile(filename));
}

function getCompilerOptionsDiagnostics() {
Expand Down Expand Up @@ -1678,12 +1688,12 @@ module ts {
entries: [],
symbols: {},
location: mappedNode,
typeChecker: typeChecker
typeChecker: typeInfoResolver
};

// Right of dot member completion list
if (isRightOfDot) {
var type: Type = typeChecker.getTypeOfExpression(mappedNode);
var type: Type = typeInfoResolver.getTypeOfExpression(mappedNode);
if (!type) {
return undefined;
}
Expand Down Expand Up @@ -1731,7 +1741,7 @@ module ts {
isMemberCompletion = false;
/// TODO filter meaning based on the current context
var symbolMeanings = SymbolFlags.Type | SymbolFlags.Value | SymbolFlags.Namespace;
var symbols = typeChecker.getSymbolsInScope(mappedNode, symbolMeanings);
var symbols = typeInfoResolver.getSymbolsInScope(mappedNode, symbolMeanings);

getCompletionEntriesFromSymbols(symbols, activeCompletionSession);
}
Expand Down Expand Up @@ -1770,7 +1780,7 @@ module ts {
kind: completionEntry.kind,
kindModifiers: completionEntry.kindModifiers,
type: session.typeChecker.typeToString(type, session.location),
fullSymbolName: typeChecker.symbolToString(symbol, session.location),
fullSymbolName: typeInfoResolver.symbolToString(symbol, session.location),
docComment: ""
};
}
Expand Down Expand Up @@ -1882,13 +1892,13 @@ module ts {
var node = getNodeAtPosition(sourceFile.getSourceFile(), position);
if (!node) return undefined;

var symbol = typeChecker.getSymbolInfo(node);
var type = symbol && typeChecker.getTypeOfSymbol(symbol);
var symbol = typeInfoResolver.getSymbolInfo(node);
var type = symbol && typeInfoResolver.getTypeOfSymbol(symbol);
if (type) {
return {
memberName: new TypeScript.MemberNameString(typeChecker.typeToString(type)),
memberName: new TypeScript.MemberNameString(typeInfoResolver.typeToString(type)),
docComment: "",
fullSymbolName: typeChecker.symbolToString(symbol, getContainerNode(node)),
fullSymbolName: typeInfoResolver.symbolToString(symbol, getContainerNode(node)),
kind: getSymbolKind(symbol),
minChar: node.pos,
limChar: node.end
Expand Down Expand Up @@ -2034,7 +2044,7 @@ module ts {
return undefined;
}

var symbol = typeChecker.getSymbolInfo(node);
var symbol = typeInfoResolver.getSymbolInfo(node);

// Could not find a symbol e.g. node is string or number keyword,
// or the symbol was an internal symbol and does not have a declaration e.g. undefined symbol
Expand All @@ -2045,10 +2055,10 @@ module ts {
var result: DefinitionInfo[] = [];

var declarations = symbol.getDeclarations();
var symbolName = typeChecker.symbolToString(symbol, node);
var symbolName = typeInfoResolver.symbolToString(symbol, node);
var symbolKind = getSymbolKind(symbol);
var containerSymbol = symbol.parent;
var containerName = containerSymbol ? typeChecker.symbolToString(containerSymbol, node) : "";
var containerName = containerSymbol ? typeInfoResolver.symbolToString(containerSymbol, node) : "";
var containerKind = containerSymbol ? getSymbolKind(symbol) : "";

if (!tryAddConstructSignature(symbol, node, symbolKind, symbolName, containerName, result) &&
Expand Down