On linux or editor with canUseEvents to prefer immediate directory if its not in root or node_modules (#58866)

This commit is contained in:
Sheetal Nandi
2024-06-27 11:32:33 -07:00
committed by GitHub
parent fe0bdc8cde
commit f7833b2a72
86 changed files with 135375 additions and 230 deletions
+8 -2
View File
@@ -1083,13 +1083,17 @@ function getHostWatcherMap<T>(): HostWatcherMap<T> {
return { idToCallbacks: new Map(), pathToId: new Map() };
}
function getCanUseWatchEvents(service: ProjectService, canUseWatchEvents: boolean | undefined) {
return !!canUseWatchEvents && !!service.eventHandler && !!service.session;
}
function createWatchFactoryHostUsingWatchEvents(service: ProjectService, canUseWatchEvents: boolean | undefined): WatchFactoryHost | undefined {
if (!canUseWatchEvents || !service.eventHandler || !service.session) return undefined;
if (!getCanUseWatchEvents(service, canUseWatchEvents)) return undefined;
const watchedFiles = getHostWatcherMap<FileWatcherCallback>();
const watchedDirectories = getHostWatcherMap<DirectoryWatcherCallback>();
const watchedDirectoriesRecursive = getHostWatcherMap<DirectoryWatcherCallback>();
let ids = 1;
service.session.addProtocolHandler(protocol.CommandTypes.WatchChange, req => {
service.session!.addProtocolHandler(protocol.CommandTypes.WatchChange, req => {
onWatchChange((req as protocol.WatchChangeRequest).arguments);
return { responseRequired: false };
});
@@ -1327,6 +1331,7 @@ export class ProjectService {
/** @internal */ verifyDocumentRegistry = noop;
/** @internal */ verifyProgram: (project: Project) => void = noop;
/** @internal */ onProjectCreation: (project: Project) => void = noop;
/** @internal */ canUseWatchEvents: boolean;
readonly jsDocParsingMode: JSDocParsingMode | undefined;
@@ -1396,6 +1401,7 @@ export class ProjectService {
log,
getDetailWatchInfo,
);
this.canUseWatchEvents = getCanUseWatchEvents(this, opts.canUseWatchEvents);
opts.incrementalVerifier?.(this);
}
+2
View File
@@ -555,6 +555,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
protected typeAcquisition: TypeAcquisition | undefined;
/** @internal */
createHash = maybeBind(this.projectService.host, this.projectService.host.createHash);
/** @internal*/ preferNonRecursiveWatch: boolean | undefined;
readonly jsDocParsingMode: JSDocParsingMode | undefined;
@@ -615,6 +616,7 @@ export abstract class Project implements LanguageServiceHost, ModuleResolutionHo
this.trace = s => host.trace!(s);
}
this.realpath = maybeBind(host, host.realpath);
this.preferNonRecursiveWatch = this.projectService.canUseWatchEvents || host.preferNonRecursiveWatch;
// Use the current directory as resolution root only if the project created using current directory string
this.resolutionCache = createResolutionCache(
+1
View File
@@ -29,6 +29,7 @@ export type RequireResult = ModuleImportResult;
export interface ServerHost extends System {
watchFile(path: string, callback: FileWatcherCallback, pollingInterval?: number, options?: WatchOptions): FileWatcher;
watchDirectory(path: string, callback: DirectoryWatcherCallback, recursive?: boolean, options?: WatchOptions): FileWatcher;
preferNonRecursiveWatch?: boolean;
setTimeout(callback: (...args: any[]) => void, ms: number, ...args: any[]): any;
clearTimeout(timeoutId: any): void;
setImmediate(callback: (...args: any[]) => void, ...args: any[]): any;