diff --git a/src/harness/unittests/tsserverProjectSystem.ts b/src/harness/unittests/tsserverProjectSystem.ts index e2c2a395581..a816bea1ae2 100644 --- a/src/harness/unittests/tsserverProjectSystem.ts +++ b/src/harness/unittests/tsserverProjectSystem.ts @@ -17,27 +17,13 @@ namespace ts.projectSystem { }) }; - const typeMapList = { + const customSafeList = { path: "/typeMapList.json", content: JSON.stringify({ - "jquery": { - // jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js") - "match": "/jquery(-(\\.?\\d+)+)?(\\.intellisense)?(\\.min)?\\.js$", - "types": ["jquery"] + "quack": { + "match": "/duckquack-(\\d+)\\.min\\.js", + "types": ["duck-types"] }, - "WinJS": { - "match": "^(.*/winjs)/base\\.js$", // If the winjs/base.js file is found.. - "exclude": [["^", 1, "/.*"]], // ..then exclude all files under the winjs folder - "types": ["winjs"] // And fetch the @types package for WinJS - }, - "Office Nuget": { - "match": "^(.*/1/office)/excel\\.debug\\.js$", // Office NuGet package is installed under a "1/office" folder - "exclude": [["^", 1, "/.*"]], // Exclude that whole folder if the file indicated above is found in it - "types": ["office"] // @types package to fetch instead - }, - "Minified files": { - "match": "^.*\\.min\\.js$" // Catch-all for minified files. Default exclude is the matched file. - } }) }; @@ -1432,17 +1418,20 @@ namespace ts.projectSystem { content: "export let x = 5" }; const office = { - path: "lib/1/office/excel.debug.js", + path: "/lib/duckquack-3.min.js", content: "whoa do @@ not parse me ok thanks!!!" }; - const host = createServerHost([typeMapList, file1, office]); + const host = createServerHost([customSafeList, file1, office]); const projectService = createProjectService(host); - projectService.loadSafeList(typeMapList.path); - - projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, office.path]) }); - const proj = projectService.externalProjects[0]; - assert.deepEqual(proj.getFileNames(true), [file1.path]); - assert.deepEqual(proj.getTypeAcquisition().include, ["office"]); + projectService.loadSafeList(customSafeList.path); + try { + projectService.openExternalProject({ projectFileName: "project", options: {}, rootFiles: toExternalFiles([file1.path, office.path]) }); + const proj = projectService.externalProjects[0]; + assert.deepEqual(proj.getFileNames(true), [file1.path]); + assert.deepEqual(proj.getTypeAcquisition().include, ["duck-types"]); + } finally { + projectService.resetSafeList(); + } }); it("open file become a part of configured project if it is referenced from root file", () => { diff --git a/src/server/editorServices.ts b/src/server/editorServices.ts index 4bbae55083d..fe060362550 100644 --- a/src/server/editorServices.ts +++ b/src/server/editorServices.ts @@ -61,6 +61,24 @@ namespace ts.server { "smart": IndentStyle.Smart }); + const defaultTypeSafeList: SafeList = { + "jquery": { + // jquery files can have names like "jquery-1.10.2.min.js" (or "jquery.intellisense.js") + "match": /jquery(-(\.?\d+)+)?(\.intellisense)?(\.min)?\.js$/gi, + "types": ["jquery"] + }, + "WinJS": { + "match": /^(.*\/winjs)\/base\.js$/gi, // If the winjs/base.js file is found.. + "exclude": [["^", 1, "/.*"]], // ..then exclude all files under the winjs folder + "types": ["winjs"] // And fetch the @types package for WinJS + }, + "Office Nuget": { + "match": /^(.*\/1\/office)\/excel\.debug\.js$/gi, // Office NuGet package is installed under a "1/office" folder + "exclude": [["^", 1, "/.*"]], // Exclude that whole folder if the file indicated above is found in it + "types": ["office"] // @types package to fetch instead + } + }; + export function convertFormatOptions(protocolOptions: protocol.FormatCodeSettings): FormatCodeSettings { if (typeof protocolOptions.indentStyle === "string") { protocolOptions.indentStyle = indentStyle.get(protocolOptions.indentStyle.toLowerCase()); @@ -263,7 +281,7 @@ namespace ts.server { private readonly throttledOperations: ThrottledOperations; private readonly hostConfiguration: HostConfiguration; - private static safelist: SafeList = {}; + private static safelist: SafeList = defaultTypeSafeList; private changedFiles: ScriptInfo[]; @@ -1407,6 +1425,10 @@ namespace ts.server { return filename.replace(this.filenameEscapeRegexp, "\\$&"); } + resetSafeList(): void { + ProjectService.safelist = defaultTypeSafeList; + } + loadSafeList(fileName: string): void { const raw: SafeList = JSON.parse(this.host.readFile(fileName, "utf-8")); // Parse the regexps