remove 'path' suffix from FileMap methods
This commit is contained in:
parent
e1b4f01e77
commit
534bb62c59
|
@ -20,10 +20,10 @@ namespace ts {
|
|||
export function createFileMap<T>(keyMapper?: (key: string) => string): FileMap<T> {
|
||||
let files: Map<T> = {};
|
||||
return {
|
||||
getPath,
|
||||
setPath,
|
||||
containsPath,
|
||||
removePath,
|
||||
get,
|
||||
set,
|
||||
contains,
|
||||
remove,
|
||||
forEachValue: forEachValueInMap,
|
||||
clear
|
||||
};
|
||||
|
@ -35,19 +35,19 @@ namespace ts {
|
|||
}
|
||||
|
||||
// path should already be well-formed so it does not need to be normalized
|
||||
function getPath(path: Path): T {
|
||||
function get(path: Path): T {
|
||||
return files[toKey(path)];
|
||||
}
|
||||
|
||||
function setPath(path: Path, value: T) {
|
||||
function set(path: Path, value: T) {
|
||||
files[toKey(path)] = value;
|
||||
}
|
||||
|
||||
function containsPath(path: Path) {
|
||||
function contains(path: Path) {
|
||||
return hasProperty(files, toKey(path));
|
||||
}
|
||||
|
||||
function removePath(path: Path) {
|
||||
function remove(path: Path) {
|
||||
const key = toKey(path);
|
||||
delete files[key];
|
||||
}
|
||||
|
|
|
@ -500,7 +500,7 @@ namespace ts {
|
|||
|
||||
// update fileName -> file mapping
|
||||
for (let i = 0, len = newSourceFiles.length; i < len; ++i) {
|
||||
filesByName.setPath(filePaths[i], newSourceFiles[i]);
|
||||
filesByName.set(filePaths[i], newSourceFiles[i]);
|
||||
}
|
||||
|
||||
files = newSourceFiles;
|
||||
|
@ -570,7 +570,7 @@ namespace ts {
|
|||
}
|
||||
|
||||
function getSourceFile(fileName: string): SourceFile {
|
||||
return filesByName.getPath(toPath(fileName, currentDirectory, getCanonicalFileName));
|
||||
return filesByName.get(toPath(fileName, currentDirectory, getCanonicalFileName));
|
||||
}
|
||||
|
||||
function getDiagnosticsHelper(
|
||||
|
@ -787,8 +787,8 @@ namespace ts {
|
|||
|
||||
// Get source file from normalized fileName
|
||||
function findSourceFile(fileName: string, normalizedAbsolutePath: Path, isDefaultLib: boolean, refFile?: SourceFile, refPos?: number, refEnd?: number): SourceFile {
|
||||
if (filesByName.containsPath(normalizedAbsolutePath)) {
|
||||
const file = filesByName.getPath(normalizedAbsolutePath);
|
||||
if (filesByName.contains(normalizedAbsolutePath)) {
|
||||
const file = filesByName.get(normalizedAbsolutePath);
|
||||
// try to check if we've already seen this file but with a different casing in path
|
||||
// NOTE: this only makes sense for case-insensitive file systems
|
||||
if (file && options.forceConsistentCasingInFileNames && getNormalizedAbsolutePath(file.fileName, currentDirectory) !== normalizedAbsolutePath) {
|
||||
|
@ -809,18 +809,18 @@ namespace ts {
|
|||
}
|
||||
});
|
||||
|
||||
filesByName.setPath(normalizedAbsolutePath, file);
|
||||
filesByName.set(normalizedAbsolutePath, file);
|
||||
if (file) {
|
||||
file.path = normalizedAbsolutePath;
|
||||
|
||||
if (host.useCaseSensitiveFileNames()) {
|
||||
// for case-sensitive file systems check if we've already seen some file with similar filename ignoring case
|
||||
const existingFile = filesByNameIgnoreCase.getPath(normalizedAbsolutePath);
|
||||
const existingFile = filesByNameIgnoreCase.get(normalizedAbsolutePath);
|
||||
if (existingFile) {
|
||||
reportFileNamesDifferOnlyInCasingError(fileName, existingFile.fileName, refFile, refPos, refEnd);
|
||||
}
|
||||
else {
|
||||
filesByNameIgnoreCase.setPath(normalizedAbsolutePath, file);
|
||||
filesByNameIgnoreCase.set(normalizedAbsolutePath, file);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -8,10 +8,10 @@ namespace ts {
|
|||
export type Path = string & { __pathBrand: any };
|
||||
|
||||
export interface FileMap<T> {
|
||||
getPath(fileName: Path): T;
|
||||
setPath(fileName: Path, value: T): void;
|
||||
containsPath(fileName: Path): boolean;
|
||||
removePath(fileName: Path): void;
|
||||
get(fileName: Path): T;
|
||||
set(fileName: Path, value: T): void;
|
||||
contains(fileName: Path): boolean;
|
||||
remove(fileName: Path): void;
|
||||
|
||||
forEachValue(f: (key: Path, v: T) => void): void;
|
||||
clear(): void;
|
||||
|
|
|
@ -106,7 +106,7 @@ namespace ts.server {
|
|||
|
||||
resolveModuleNames(moduleNames: string[], containingFile: string): ResolvedModule[] {
|
||||
let path = toPath(containingFile, this.host.getCurrentDirectory(), this.getCanonicalFileName);
|
||||
let currentResolutionsInFile = this.resolvedModuleNames.getPath(path);
|
||||
let currentResolutionsInFile = this.resolvedModuleNames.get(path);
|
||||
|
||||
let newResolutions: Map<TimestampedResolvedModule> = {};
|
||||
let resolvedModules: ResolvedModule[] = [];
|
||||
|
@ -135,7 +135,7 @@ namespace ts.server {
|
|||
}
|
||||
|
||||
// replace old results with a new one
|
||||
this.resolvedModuleNames.setPath(path, newResolutions);
|
||||
this.resolvedModuleNames.set(path, newResolutions);
|
||||
return resolvedModules;
|
||||
|
||||
function moduleResolutionIsValid(resolution: TimestampedResolvedModule): boolean {
|
||||
|
@ -205,35 +205,35 @@ namespace ts.server {
|
|||
|
||||
removeReferencedFile(info: ScriptInfo) {
|
||||
if (!info.isOpen) {
|
||||
this.filenameToScript.removePath(info.path);
|
||||
this.resolvedModuleNames.removePath(info.path);
|
||||
this.filenameToScript.remove(info.path);
|
||||
this.resolvedModuleNames.remove(info.path);
|
||||
}
|
||||
}
|
||||
|
||||
getScriptInfo(filename: string): ScriptInfo {
|
||||
let path = toPath(filename, this.host.getCurrentDirectory(), this.getCanonicalFileName);
|
||||
let scriptInfo = this.filenameToScript.getPath(path);
|
||||
let scriptInfo = this.filenameToScript.get(path);
|
||||
if (!scriptInfo) {
|
||||
scriptInfo = this.project.openReferencedFile(filename);
|
||||
if (scriptInfo) {
|
||||
this.filenameToScript.setPath(path, scriptInfo);
|
||||
this.filenameToScript.set(path, scriptInfo);
|
||||
}
|
||||
}
|
||||
return scriptInfo;
|
||||
}
|
||||
|
||||
addRoot(info: ScriptInfo) {
|
||||
if (!this.filenameToScript.containsPath(info.path)) {
|
||||
this.filenameToScript.setPath(info.path, info);
|
||||
if (!this.filenameToScript.contains(info.path)) {
|
||||
this.filenameToScript.set(info.path, info);
|
||||
this.roots.push(info);
|
||||
}
|
||||
}
|
||||
|
||||
removeRoot(info: ScriptInfo) {
|
||||
if (!this.filenameToScript.containsPath(info.path)) {
|
||||
this.filenameToScript.removePath(info.path);
|
||||
if (!this.filenameToScript.contains(info.path)) {
|
||||
this.filenameToScript.remove(info.path);
|
||||
this.roots = copyListRemovingItem(info, this.roots);
|
||||
this.resolvedModuleNames.removePath(info.path);
|
||||
this.resolvedModuleNames.remove(info.path);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -283,7 +283,7 @@ namespace ts.server {
|
|||
*/
|
||||
lineToTextSpan(filename: string, line: number): ts.TextSpan {
|
||||
let path = toPath(filename, this.host.getCurrentDirectory(), this.getCanonicalFileName);
|
||||
const script: ScriptInfo = this.filenameToScript.getPath(path);
|
||||
const script: ScriptInfo = this.filenameToScript.get(path);
|
||||
const index = script.snap().index;
|
||||
|
||||
const lineInfo = index.lineNumberToInfo(line + 1);
|
||||
|
@ -304,7 +304,7 @@ namespace ts.server {
|
|||
*/
|
||||
lineOffsetToPosition(filename: string, line: number, offset: number): number {
|
||||
let path = toPath(filename, this.host.getCurrentDirectory(), this.getCanonicalFileName);
|
||||
const script: ScriptInfo = this.filenameToScript.getPath(path);
|
||||
const script: ScriptInfo = this.filenameToScript.get(path);
|
||||
const index = script.snap().index;
|
||||
|
||||
const lineInfo = index.lineNumberToInfo(line);
|
||||
|
@ -318,7 +318,7 @@ namespace ts.server {
|
|||
*/
|
||||
positionToLineOffset(filename: string, position: number): ILineInfo {
|
||||
let path = toPath(filename, this.host.getCurrentDirectory(), this.getCanonicalFileName);
|
||||
const script: ScriptInfo = this.filenameToScript.getPath(path);
|
||||
const script: ScriptInfo = this.filenameToScript.get(path);
|
||||
const index = script.snap().index;
|
||||
const lineOffset = index.charOffsetToLineNumberAndPos(position);
|
||||
return { line: lineOffset.line, offset: lineOffset.offset + 1 };
|
||||
|
|
|
@ -1728,16 +1728,16 @@ namespace ts {
|
|||
};
|
||||
}
|
||||
|
||||
this.fileNameToEntry.setPath(path, entry);
|
||||
this.fileNameToEntry.set(path, entry);
|
||||
return entry;
|
||||
}
|
||||
|
||||
private getEntry(path: Path): HostFileInformation {
|
||||
return this.fileNameToEntry.getPath(path);
|
||||
return this.fileNameToEntry.get(path);
|
||||
}
|
||||
|
||||
private contains(path: Path): boolean {
|
||||
return this.fileNameToEntry.containsPath(path);
|
||||
return this.fileNameToEntry.contains(path);
|
||||
}
|
||||
|
||||
public getOrCreateEntry(fileName: string): HostFileInformation {
|
||||
|
@ -2053,7 +2053,7 @@ namespace ts {
|
|||
|
||||
let bucket = getBucketForCompilationSettings(compilationSettings, /*createIfMissing*/ true);
|
||||
let path = toPath(fileName, currentDirectory, getCanonicalFileName);
|
||||
let entry = bucket.getPath(path);
|
||||
let entry = bucket.get(path);
|
||||
if (!entry) {
|
||||
Debug.assert(acquiring, "How could we be trying to update a document that the registry doesn't have?");
|
||||
|
||||
|
@ -2065,7 +2065,7 @@ namespace ts {
|
|||
languageServiceRefCount: 0,
|
||||
owners: []
|
||||
};
|
||||
bucket.setPath(path, entry);
|
||||
bucket.set(path, entry);
|
||||
}
|
||||
else {
|
||||
// We have an entry for this file. However, it may be for a different version of
|
||||
|
@ -2095,12 +2095,12 @@ namespace ts {
|
|||
|
||||
let path = toPath(fileName, currentDirectory, getCanonicalFileName);
|
||||
|
||||
let entry = bucket.getPath(path);
|
||||
let entry = bucket.get(path);
|
||||
entry.languageServiceRefCount--;
|
||||
|
||||
Debug.assert(entry.languageServiceRefCount >= 0);
|
||||
if (entry.languageServiceRefCount === 0) {
|
||||
bucket.removePath(path);
|
||||
bucket.remove(path);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue