Skip to content

Commit a1c5daf

Browse files
committed
Include *.json in the root files if they are specified as root
Fixes #33827
1 parent dcb6de6 commit a1c5daf

File tree

2 files changed

+59
-7
lines changed

2 files changed

+59
-7
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: 58 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,7 +863,7 @@ declare module '@custom/plugin' {
863863
});
864864

865865
describe("unittests:: tsserver:: Project Errors with resolveJsonModule", () => {
866-
it("should not report incorrect error when json is root file found by tsconfig", () => {
866+
function createSessionForTest({ include }: { include: readonly string[]; }) {
867867
const test: File = {
868868
path: `${projectRoot}/src/test.ts`,
869869
content: `import * as blabla from "./blabla.json"`
@@ -879,20 +879,74 @@ declare module '@custom/plugin' {
879879
resolveJsonModule: true,
880880
composite: true
881881
},
882-
include: ["./src/*.ts", "./src/*.json"]
882+
include
883883
})
884884
};
885885

886886
const host = createServerHost([test, blabla, libFile, tsconfig]);
887-
const session = createSession(host);
887+
const session = createSession(host, { canUseEvents: true });
888888
openFilesForSession([test], session);
889+
return { host, session, test, blabla, tsconfig };
890+
}
891+
892+
it("should not report incorrect error when json is root file found by tsconfig", () => {
893+
const { host, session, test } = createSessionForTest({
894+
include: ["./src/*.ts", "./src/*.json"]
895+
});
889896
verifyGetErrRequest({
890897
session,
891898
host,
892899
expected: [
893-
{ file: test, syntax: [], semantic: [], suggestion: [] }
900+
{
901+
file: test,
902+
syntax: [],
903+
semantic: [],
904+
suggestion: [
905+
createDiagnostic(
906+
{ line: 1, offset: 1 },
907+
{ line: 1, offset: test.content.length + 1 },
908+
Diagnostics._0_is_declared_but_its_value_is_never_read,
909+
["blabla"],
910+
"suggestion",
911+
/*reportsUnnecessary*/ true
912+
)
913+
]
914+
}
894915
]
895916
});
896917
});
918+
919+
it("should report error when json is not root file found by tsconfig", () => {
920+
const { host, session, test, blabla, tsconfig } = createSessionForTest({
921+
include: ["./src/*.ts"]
922+
});
923+
const span = protocolTextSpanFromSubstring(test.content, `"./blabla.json"`);
924+
verifyGetErrRequest({
925+
session,
926+
host,
927+
expected: [{
928+
file: test,
929+
syntax: [],
930+
semantic: [
931+
createDiagnostic(
932+
span.start,
933+
span.end,
934+
Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern,
935+
[blabla.path, tsconfig.path]
936+
)
937+
],
938+
suggestion: [
939+
createDiagnostic(
940+
{ line: 1, offset: 1 },
941+
{ line: 1, offset: test.content.length + 1 },
942+
Diagnostics._0_is_declared_but_its_value_is_never_read,
943+
["blabla"],
944+
"suggestion",
945+
/*reportsUnnecessary*/ true
946+
)
947+
]
948+
}]
949+
});
950+
});
897951
});
898952
}

0 commit comments

Comments
 (0)