Skip to content

Commit

Permalink
fix: DocumentSpan should attempt to load the source file if it's no…
Browse files Browse the repository at this point in the history
…t loaded yet (#1291)
  • Loading branch information
dsherret committed Jun 3, 2022
1 parent f1b4ea2 commit 1eda69c
Show file tree
Hide file tree
Showing 19 changed files with 275 additions and 176 deletions.
11 changes: 6 additions & 5 deletions deno/bootstrap/ts_morph_bootstrap.js
@@ -1,4 +1,4 @@
import { DocumentRegistry, ts, StringUtils, FileUtils, Memoize, TransactionalFileSystem, TsConfigResolver, errors, InMemoryFileSystemHost, RealFileSystemHost, CompilerOptionsContainer, createHosts, runtime, createModuleResolutionHost } from '../common/mod.ts';
import { DocumentRegistry, StringUtils, ts, FileUtils, Memoize, TransactionalFileSystem, TsConfigResolver, errors, InMemoryFileSystemHost, RealFileSystemHost, CompilerOptionsContainer, createHosts, runtime, createModuleResolutionHost } from '../common/mod.ts';
export { CompilerOptionsContainer, InMemoryFileSystemHost, ResolutionHosts, SettingsContainer, ts } from '../common/mod.ts';

/*! *****************************************************************************
Expand Down Expand Up @@ -49,9 +49,6 @@ class SourceFileCache {
getSourceFileFromCacheFromFilePath(filePath) {
return this.sourceFilesByFilePath.get(filePath);
}
addLibFileToCacheByText(filePath, fileText, scriptKind) {
return this.documentRegistry.createOrUpdateSourceFile(filePath, this.compilerOptions.get(), ts.ScriptSnapshot.fromString(fileText), scriptKind);
}
async addOrGetSourceFileFromFilePath(filePath, options) {
let sourceFile = this.sourceFilesByFilePath.get(filePath);
if (sourceFile == null) {
Expand Down Expand Up @@ -123,7 +120,11 @@ function createProjectSync(options = {}) {
function createProjectCommon(options) {
verifyOptions();
const fileSystem = getFileSystem();
const fileSystemWrapper = new TransactionalFileSystem(fileSystem);
const fileSystemWrapper = new TransactionalFileSystem({
fileSystem,
libFolderPath: options.libFolderPath,
skipLoadingLibFiles: options.skipLoadingLibFiles,
});
const tsConfigResolver = options.tsConfigFilePath == null
? undefined
: new TsConfigResolver(fileSystemWrapper, fileSystemWrapper.getStandardizedAbsolutePath(options.tsConfigFilePath), getEncodingFromProvidedOptions());
Expand Down
27 changes: 18 additions & 9 deletions deno/common/ts_morph_common.d.ts
Expand Up @@ -325,12 +325,6 @@ export interface TsSourceFileContainer {
markInProject: boolean;
scriptKind: ScriptKind | undefined;
}): ts.SourceFile | undefined;
/**
* Adds a lib file whose existence is virtual to the cache.
* @param filePath - File path to get.
* @param scriptKind - Script kind of the source file.
*/
addLibFileToCacheByText(filePath: StandardizedFilePath, fileText: string, scriptKind: ScriptKind | undefined): ts.SourceFile;
/**
* Gets the source file version of the specified source file.
* @param sourceFile - Source file to inspect.
Expand Down Expand Up @@ -758,18 +752,25 @@ export interface DirEntry {
isSymlink: boolean;
}

export interface TransactionalFileSystemOptions {
fileSystem: FileSystemHost;
skipLoadingLibFiles: boolean | undefined;
libFolderPath: string | undefined;
}

/**
* FileSystemHost wrapper that allows transactionally queuing operations to the file system.
*/
export declare class TransactionalFileSystem {
private readonly fileSystem;
private readonly directories;
private readonly pathCasingMaintainer;
private readonly fileSystem;
private readonly libFileMap;
/**
* Constructor.
* @param fileSystem - File system host to commit the operations to.
*/
constructor(fileSystem: FileSystemHost);
constructor(options: TransactionalFileSystemOptions);
queueFileDelete(filePath: StandardizedFilePath): void;
removeFileDelete(filePath: StandardizedFilePath): void;
queueMkdir(dirPath: StandardizedFilePath): void;
Expand Down Expand Up @@ -800,7 +801,7 @@ export declare class TransactionalFileSystem {
deleteDirectoryImmediatelySync(dirPath: StandardizedFilePath): void;
private deleteSuppressNotFound;
private deleteSuppressNotFoundSync;
fileExists(filePath: StandardizedFilePath): false | Promise<boolean>;
fileExists(filePath: StandardizedFilePath): boolean | Promise<boolean>;
fileExistsSync(filePath: StandardizedFilePath): boolean;
private _fileDeletedInMemory;
directoryExistsSync(dirPath: StandardizedFilePath): boolean;
Expand Down Expand Up @@ -835,6 +836,9 @@ export declare class TransactionalFileSystem {
private ensureDirectoryExists;
private ensureDirectoryExistsSync;
private removeMkDirOperationsForDir;
private libFileExists;
private readLibFile;
private throwIfLibFile;
}

/** Gets the TypeScript lib files (.d.ts files). */
Expand All @@ -843,6 +847,11 @@ export declare function getLibFiles(): {
text: string;
}[];

export declare function getLibFolderPath(options: {
libFolderPath?: string;
skipLoadingLibFiles?: boolean;
}): string;

/** The folder to use to "store" the in memory lib files. */
export declare const libFolderInMemoryPath: StandardizedFilePath;

Expand Down
116 changes: 69 additions & 47 deletions deno/common/ts_morph_common.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 1eda69c

Please sign in to comment.