MCPcopy Create free account
hub / github.com/Snapchat/Valdi / Workspace

Class Workspace

compiler/companion/src/Workspace.ts:108–502  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

106 onSourceFileInvalidated(path: string): void {}
107}
108
109export class Workspace implements IWorkspace {
110 workspaceRoot: string;
111 initialized: boolean = false;
112
113 private project: Project;
114 private importPathResolver: ImportPathResolver;
115
116 private pendingFilesToOpen: PendingFileToOpen[] = [];
117 private scheduleFlushOpenQueuedFiles: () => void;
118
119 constructor(
120 workspaceRoot: string,
121 shouldDebounceOpenFile: boolean,
122 readonly logger: ILogger | undefined,
123 readonly compilerOptions: ts.CompilerOptions | undefined,
124 readonly nativeApiMinVersion: number | undefined,
125 ) {
126 this.workspaceRoot = workspaceRoot;
127 const project = new Project(workspaceRoot, compilerOptions, logger ? new ProjectListener(logger) : undefined);
128 this.project = project;
129 this.importPathResolver = new ImportPathResolver(() => project.compilerOptions);
130
131 const flushOpenQueuedFiles = () => {
132 this.openQueuedFiles();
133 };
134 if (shouldDebounceOpenFile) {
135 this.scheduleFlushOpenQueuedFiles = debounce(flushOpenQueuedFiles, 20, { trailing: true });
136 } else {
137 this.scheduleFlushOpenQueuedFiles = flushOpenQueuedFiles;
138 }
139 }
140
141 initialize(): void {
142 const tsConfigCompilerOptions = this.project.compilerOptions;
143 // Doing this to make sure we automatically "open" any files referred to in
144 // tsconfig.compilerOptions.types _if they are present_.
145 //
146 // Note: we seem to be using tsconfig.compilerOptions.types in a _very_
147 // unexpected way (see docs: https://www.typescriptlang.org/tsconfig#types)
148 //
149 // It seems likely that the fact that this lets us make Long.d.ts available globally
150 // is accidental.
151 const typesFiles = tsConfigCompilerOptions.types ?? [];
152 const basePath = (tsConfigCompilerOptions.typeRoots ?? [''])[0];
153 const presentTypesFiles = typesFiles
154 .map((unresolvedTypesFilePath) => path.resolve(basePath, unresolvedTypesFilePath + '.d.ts'))
155 .filter((f) => this.project.fileExists(f));
156
157 presentTypesFiles.forEach((typesFilePath) => this.doOpenFile(typesFilePath));
158 this.initialized = true;
159 }
160
161 destroy(): void {
162 this.project.destroy();
163 }
164
165 addSourceFileAtPath(fileName: string) {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected