Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(typescript-estree): add debug logs for useProgramFromProjectService #8426

Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
18 changes: 18 additions & 0 deletions packages/typescript-estree/src/useProgramFromProjectService.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import debug from 'debug';
import { minimatch } from 'minimatch';

import { createProjectProgram } from './create-program/createProjectProgram';
Expand All @@ -9,12 +10,17 @@
} from './create-program/shared';
import type { MutableParseSettings } from './parseSettings';

const log = debug(
'typescript-eslint:typescript-estree:useProgramFromProjectService',
);

export function useProgramFromProjectService(
{ allowDefaultProjectForFiles, service }: ProjectServiceSettings,
parseSettings: Readonly<MutableParseSettings>,
hasFullTypeInformation: boolean,
): ASTAndDefiniteProgram | undefined {
const filePath = getCanonicalFileName(parseSettings.filePath);
log('Opening project service file for: %s', filePath);

Check warning on line 23 in packages/typescript-estree/src/useProgramFromProjectService.ts

View check run for this annotation

Codecov / codecov/patch

packages/typescript-estree/src/useProgramFromProjectService.ts#L23

Added line #L23 was not covered by tests

const opened = service.openClientFile(
ensureAbsolutePath(filePath, service.host.getCurrentDirectory()),
Expand All @@ -23,7 +29,14 @@
parseSettings.tsconfigRootDir,
);

log('Opened project service file: %o', opened);

Check warning on line 32 in packages/typescript-estree/src/useProgramFromProjectService.ts

View check run for this annotation

Codecov / codecov/patch

packages/typescript-estree/src/useProgramFromProjectService.ts#L32

Added line #L32 was not covered by tests

if (hasFullTypeInformation) {
log(

Check warning on line 35 in packages/typescript-estree/src/useProgramFromProjectService.ts

View check run for this annotation

Codecov / codecov/patch

packages/typescript-estree/src/useProgramFromProjectService.ts#L35

Added line #L35 was not covered by tests
'Project service type information enabled; checking for file path match on: %o',
allowDefaultProjectForFiles,
);

if (opened.configFileName) {
if (filePathMatchedBy(filePath, allowDefaultProjectForFiles)) {
throw new Error(
Expand All @@ -37,16 +50,21 @@
}
}

log('Retrieving scripti nfo and then program for: %s', filePath);

Check warning on line 53 in packages/typescript-estree/src/useProgramFromProjectService.ts

View check run for this annotation

Codecov / codecov/patch

packages/typescript-estree/src/useProgramFromProjectService.ts#L53

Added line #L53 was not covered by tests
JoshuaKGoldberg marked this conversation as resolved.
Show resolved Hide resolved

const scriptInfo = service.getScriptInfo(filePath);
const program = service
.getDefaultProjectForFile(scriptInfo!.fileName, true)!
.getLanguageService(/*ensureSynchronized*/ true)
.getProgram();

if (!program) {
log('Could not find project service program for: %s', filePath);

Check warning on line 62 in packages/typescript-estree/src/useProgramFromProjectService.ts

View check run for this annotation

Codecov / codecov/patch

packages/typescript-estree/src/useProgramFromProjectService.ts#L62

Added line #L62 was not covered by tests
return undefined;
}

log('Found project service program for: %s', filePath);

Check warning on line 66 in packages/typescript-estree/src/useProgramFromProjectService.ts

View check run for this annotation

Codecov / codecov/patch

packages/typescript-estree/src/useProgramFromProjectService.ts#L66

Added line #L66 was not covered by tests

return createProjectProgram(parseSettings, [program]);
}

Expand Down