Skip to content

Commit

Permalink
Include *.json in the root files if they are specified as root
Browse files Browse the repository at this point in the history
Fixes #33827
  • Loading branch information
sheetalkamat committed Oct 23, 2019
1 parent dcb6de6 commit a1c5daf
Show file tree
Hide file tree
Showing 2 changed files with 59 additions and 7 deletions.
4 changes: 1 addition & 3 deletions src/services/services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -953,9 +953,7 @@ namespace ts {
names.push(entry);
}
else {
if (entry.scriptKind !== ScriptKind.JSON) {
names.push(entry.hostFileName);
}
names.push(entry.hostFileName);
}
});
return names;
Expand Down
62 changes: 58 additions & 4 deletions src/testRunner/unittests/tsserver/projectErrors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -863,7 +863,7 @@ declare module '@custom/plugin' {
});

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

const host = createServerHost([test, blabla, libFile, tsconfig]);
const session = createSession(host);
const session = createSession(host, { canUseEvents: true });
openFilesForSession([test], session);
return { host, session, test, blabla, tsconfig };
}

it("should not report incorrect error when json is root file found by tsconfig", () => {
const { host, session, test } = createSessionForTest({
include: ["./src/*.ts", "./src/*.json"]
});
verifyGetErrRequest({
session,
host,
expected: [
{ file: test, syntax: [], semantic: [], suggestion: [] }
{
file: test,
syntax: [],
semantic: [],
suggestion: [
createDiagnostic(
{ line: 1, offset: 1 },
{ line: 1, offset: test.content.length + 1 },
Diagnostics._0_is_declared_but_its_value_is_never_read,
["blabla"],
"suggestion",
/*reportsUnnecessary*/ true
)
]
}
]
});
});

it("should report error when json is not root file found by tsconfig", () => {
const { host, session, test, blabla, tsconfig } = createSessionForTest({
include: ["./src/*.ts"]
});
const span = protocolTextSpanFromSubstring(test.content, `"./blabla.json"`);
verifyGetErrRequest({
session,
host,
expected: [{
file: test,
syntax: [],
semantic: [
createDiagnostic(
span.start,
span.end,
Diagnostics.File_0_is_not_listed_within_the_file_list_of_project_1_Projects_must_list_all_files_or_use_an_include_pattern,
[blabla.path, tsconfig.path]
)
],
suggestion: [
createDiagnostic(
{ line: 1, offset: 1 },
{ line: 1, offset: test.content.length + 1 },
Diagnostics._0_is_declared_but_its_value_is_never_read,
["blabla"],
"suggestion",
/*reportsUnnecessary*/ true
)
]
}]
});
});
});
}

0 comments on commit a1c5daf

Please sign in to comment.