Skip to content

Commit

Permalink
make the scope consistent with service container in test, don't updat…
Browse files Browse the repository at this point in the history
…e while scheduling project file update
  • Loading branch information
jasonlyu123 committed Aug 13, 2024
1 parent d2f4110 commit 3d25d43
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 17 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,7 @@ export class LSAndTSDocResolver {
watchDirectory: this.options?.watchDirectory
? this.watchDirectory.bind(this)
: undefined,
nonRecursiveWatchPattern: this.options?.nonRecursiveWatchPattern,
projectReferenceInfo: new Map()
nonRecursiveWatchPattern: this.options?.nonRecursiveWatchPattern
};
}

Expand Down
22 changes: 9 additions & 13 deletions packages/language-server/src/plugins/typescript/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ const configFileForOpenFiles = new FileMap<string>();
const pendingReloads = new FileSet();
const documentRegistries = new Map<string, ts.DocumentRegistry>();
const pendingForAllServices = new Set<Promise<void>>();
const projectReferenceInfo = new FileMap<TsConfigInfo | null>();

/**
* For testing only: Reset the cache for services.
Expand All @@ -136,7 +137,6 @@ export interface LanguageServiceDocumentContext {
projectService: ProjectService | undefined;
watchDirectory: ((patterns: RelativePattern[]) => void) | undefined;
nonRecursiveWatchPattern: string | undefined;
projectReferenceInfo: Map<string, TsConfigInfo | null>;
}

export async function getService(
Expand All @@ -156,7 +156,6 @@ export async function getService(
const needAssign = !configFileForOpenFiles.has(path);
let service = await getServiceForTsconfig(tsconfigPath, dirname(tsconfigPath), docContext);
if (!needAssign) {
configFileForOpenFiles.set(path, tsconfigPath);
return service;
}

Expand Down Expand Up @@ -246,7 +245,7 @@ export async function getServiceForTsconfig(
}

pendingReloads.delete(tsconfigPath);
docContext.projectReferenceInfo.delete(tsconfigPath);
projectReferenceInfo.delete(tsconfigPath);
const newService = createLanguageService(tsconfigPath, workspacePath, docContext);
services.set(tsconfigPathOrWorkspacePath, newService);
service = await newService;
Expand Down Expand Up @@ -409,7 +408,7 @@ async function createLanguageService(
configFileName: string
) {
const cached = configFileName
? docContext.projectReferenceInfo.get(configFileName)
? projectReferenceInfo.get(configFileName)
: undefined;
if (cached?.snapshotManager) {
return cached.snapshotManager;
Expand Down Expand Up @@ -571,8 +570,11 @@ async function createLanguageService(
pendingProjectFileUpdate = true;
}

const projectReferences = getProjectReferences();
for (const config of projectReferences) {
if (!projectConfig.projectReferences) {
return;
}
for (const ref of projectConfig.projectReferences) {
const config = projectReferenceInfo.get(ref.path);
if (
config &&
// handled by the respective service
Expand Down Expand Up @@ -635,7 +637,7 @@ async function createLanguageService(
let parsedConfig: ts.ParsedCommandLine;
let extendedConfigPaths: Set<string>;

const exist = tsconfigPath && docContext.projectReferenceInfo.get(tsconfigPath);
const exist = tsconfigPath && projectReferenceInfo.get(tsconfigPath);
if (exist) {
compilerOptions = exist.parsedCommandLine.options;
parsedConfig = exist.parsedCommandLine;
Expand Down Expand Up @@ -1016,7 +1018,6 @@ async function createLanguageService(
}

function ensureTsConfigInfoUpToDate(configFilePath: string) {
const projectReferenceInfo = docContext.projectReferenceInfo;
const cached = projectReferenceInfo.get(configFilePath);
if (cached !== undefined) {
ensureProjectFileUpToDate(cached);
Expand Down Expand Up @@ -1068,11 +1069,6 @@ async function createLanguageService(
}

function getParsedCommandLine(configFilePath: string) {
const info = docContext.projectReferenceInfo.get(configFilePath);
if (info) {
return info.parsedCommandLine;
}

return ensureTsConfigInfoUpToDate(configFilePath)?.parsedCommandLine;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ describe('service', () => {
onProjectReloaded: undefined,
projectService: undefined,
nonRecursiveWatchPattern: undefined,
watchDirectory: undefined,
projectReferenceInfo: new Map()
watchDirectory: undefined
};

return { virtualSystem, lsDocumentContext, rootUris };
Expand Down

0 comments on commit 3d25d43

Please sign in to comment.