Skip to content

Commit f12eee2

Browse files
authored
Include *.json in the root files if they are specified as root (#34676)
Fixes #33827
1 parent a01c8ef commit f12eee2

File tree

2 files changed

+73
-3
lines changed

2 files changed

+73
-3
lines changed

src/services/services.ts

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -953,9 +953,7 @@ namespace ts {
953953
names.push(entry);
954954
}
955955
else {
956-
if (entry.scriptKind !== ScriptKind.JSON) {
957-
names.push(entry.hostFileName);
958-
}
956+
names.push(entry.hostFileName);
959957
}
960958
});
961959
return names;

src/testRunner/unittests/tsserver/projectErrors.ts

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -861,4 +861,76 @@ declare module '@custom/plugin' {
861861
]);
862862
});
863863
});
864+
865+
describe("unittests:: tsserver:: Project Errors with resolveJsonModule", () => {
866+
function createSessionForTest({ include }: { include: readonly string[]; }) {
867+
const test: File = {
868+
path: `${projectRoot}/src/test.ts`,
869+
content: `import * as blabla from "./blabla.json";
870+
declare var console: any;
871+
console.log(blabla);`
872+
};
873+
const blabla: File = {
874+
path: `${projectRoot}/src/blabla.json`,
875+
content: "{}"
876+
};
877+
const tsconfig: File = {
878+
path: `${projectRoot}/tsconfig.json`,
879+
content: JSON.stringify({
880+
compilerOptions: {
881+
resolveJsonModule: true,
882+
composite: true
883+
},
884+
include
885+
})
886+
};
887+
888+
const host = createServerHost([test, blabla, libFile, tsconfig]);
889+
const session = createSession(host, { canUseEvents: true });
890+
openFilesForSession([test], session);
891+
return { host, session, test, blabla, tsconfig };
892+
}
893+
894+
it("should not report incorrect error when json is root file found by tsconfig", () => {
895+
const { host, session, test } = createSessionForTest({
896+
include: ["./src/*.ts", "./src/*.json"]
897+
});
898+
verifyGetErrRequest({
899+
session,
900+
host,
901+
expected: [
902+
{
903+
file: test,
904+
syntax: [],
905+
semantic: [],
906+
suggestion: []
907+
}
908+
]
909+
});
910+
});
911+
912+
it("should report error when json is not root file found by tsconfig", () => {
913+
const { host, session, test, blabla, tsconfig } = createSessionForTest({
914+
include: ["./src/*.ts"]
915+
});
916+
const span = protocolTextSpanFromSubstring(test.content, `"./blabla.json"`);
917+
verifyGetErrRequest({
918+
session,
919+
host,
920+
expected: [{
921+
file: test,
922+
syntax: [],
923+
semantic: [
924+
createDiagnostic(
925+
span.start,
926+
span.end,
927+
Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern,
928+
[blabla.path, tsconfig.path]
929+
)
930+
],
931+
suggestion: []
932+
}]
933+
});
934+
});
935+
});
864936
}

0 commit comments

Comments
 (0)