mirror of
https://github.com/microsoft/TypeScript.git
synced 2026-07-05 00:32:41 -05:00
FileMap now internally stores absolute normalized file names
This commit is contained in:
@@ -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() {
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user