FileMap now internally stores absolute normalized file names

This commit is contained in:
Vladimir Matveev
2015-10-29 13:52:38 -07:00
parent 67026f3461
commit 93e942a6de
4 changed files with 12 additions and 10 deletions

View File

@@ -17,7 +17,7 @@ namespace ts {
True = -1
}
export function createFileMap<T>(getCanonicalFileName: (fileName: string) => string): FileMap<T> {
export function createFileMap<T>(getCanonicalFileName: (fileName: string) => string, currentDirectory: string): FileMap<T> {
let files: Map<T> = {};
return {
get,
@@ -50,7 +50,7 @@ namespace ts {
}
function normalizeKey(key: string) {
return getCanonicalFileName(normalizeSlashes(key));
return getCanonicalFileName(getNormalizedAbsolutePath(key, currentDirectory));
}
function clear() {

View File

@@ -346,10 +346,10 @@ namespace ts {
? ((moduleNames: string[], containingFile: string) => host.resolveModuleNames(moduleNames, containingFile))
: ((moduleNames: string[], containingFile: string) => map(moduleNames, moduleName => resolveModuleName(moduleName, containingFile, options, host).resolvedModule));
let filesByName = createFileMap<SourceFile>(getCanonicalFileName);
let filesByName = createFileMap<SourceFile>(getCanonicalFileName, currentDirectory);
// stores 'filename -> file association' ignoring case
// used to track cases when two file names differ only in casing
let filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createFileMap<SourceFile>(fileName => fileName.toLowerCase()) : undefined;
let filesByNameIgnoreCase = host.useCaseSensitiveFileNames() ? createFileMap<SourceFile>(fileName => fileName.toLowerCase(), currentDirectory) : undefined;
if (oldProgram) {
// check properties that can affect structure of the program or module resolution strategy

View File

@@ -93,8 +93,8 @@ namespace ts.server {
constructor(public host: ServerHost, public project: Project) {
const getCanonicalFileName = createGetCanonicalFileName(host.useCaseSensitiveFileNames);
this.resolvedModuleNames = createFileMap<Map<TimestampedResolvedModule>>(getCanonicalFileName);
this.filenameToScript = createFileMap<ScriptInfo>(getCanonicalFileName);
this.resolvedModuleNames = createFileMap<Map<TimestampedResolvedModule>>(getCanonicalFileName, host.getCurrentDirectory());
this.filenameToScript = createFileMap<ScriptInfo>(getCanonicalFileName, host.getCurrentDirectory());
this.moduleResolutionHost = {
fileExists: fileName => this.fileExists(fileName),
readFile: fileName => this.host.readFile(fileName)

View File

@@ -1698,7 +1698,7 @@ namespace ts {
constructor(private host: LanguageServiceHost, getCanonicalFileName: (fileName: string) => string) {
// script id => script index
this.fileNameToEntry = createFileMap<HostFileInformation>(getCanonicalFileName);
this.fileNameToEntry = createFileMap<HostFileInformation>(getCanonicalFileName, host.getCurrentDirectory());
// Initialize the list with the root file names
let rootFileNames = host.getScriptFileNames();
@@ -1993,7 +1993,7 @@ namespace ts {
}
export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean): DocumentRegistry {
export function createDocumentRegistry(useCaseSensitiveFileNames?: boolean, currentDirectory = ""): DocumentRegistry {
// Maps from compiler setting target (ES3, ES5, etc.) to all the cached documents we have
// for those settings.
let buckets: Map<FileMap<DocumentRegistryEntry>> = {};
@@ -2007,7 +2007,7 @@ namespace ts {
let key = getKeyFromCompilationSettings(settings);
let bucket = lookUp(buckets, key);
if (!bucket && createIfMissing) {
buckets[key] = bucket = createFileMap<DocumentRegistryEntry>(getCanonicalFileName);
buckets[key] = bucket = createFileMap<DocumentRegistryEntry>(getCanonicalFileName, currentDirectory);
}
return bucket;
}
@@ -2556,7 +2556,9 @@ namespace ts {
}
}
export function createLanguageService(host: LanguageServiceHost, documentRegistry: DocumentRegistry = createDocumentRegistry()): LanguageService {
export function createLanguageService(host: LanguageServiceHost,
documentRegistry: DocumentRegistry = createDocumentRegistry(host.useCaseSensitiveFileNames && host.useCaseSensitiveFileNames(), host.getCurrentDirectory())): LanguageService {
let syntaxTreeCache: SyntaxTreeCache = new SyntaxTreeCache(host);
let ruleProvider: formatting.RulesProvider;
let program: Program;