Skip to content

Commit 593ee68

Browse files
Merge pull request #14095 from RyanCavanaugh/preserveConstEnums
Preserve const enums for tsserver
2 parents e4d7dc4 + 8b9fa4c commit 593ee68

25 files changed

+83028
-66662
lines changed

Jakefile.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -571,7 +571,7 @@ var typingsInstallerFile = path.join(builtLocalDirectory, "typingsInstaller.js")
571571
compileFile(typingsInstallerFile, typingsInstallerSources, [builtLocalDirectory].concat(typingsInstallerSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { outDir: builtLocalDirectory, noOutFile: false });
572572

573573
var serverFile = path.join(builtLocalDirectory, "tsserver.js");
574-
compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile].concat(serverSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"] });
574+
compileFile(serverFile, serverSources, [builtLocalDirectory, copyright, cancellationTokenFile, typingsInstallerFile].concat(serverSources), /*prefixes*/ [copyright], /*useBuiltCompiler*/ true, { types: ["node"], preserveConstEnums: true });
575575
var tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
576576
var tsserverLibraryDefinitionFile = path.join(builtLocalDirectory, "tsserverlibrary.d.ts");
577577
compileFile(
@@ -580,7 +580,7 @@ compileFile(
580580
[builtLocalDirectory, copyright, builtLocalCompiler].concat(languageServiceLibrarySources).concat(libraryTargets),
581581
/*prefixes*/[copyright],
582582
/*useBuiltCompiler*/ true,
583-
{ noOutFile: false, generateDeclarations: true, stripInternal: true },
583+
{ noOutFile: false, generateDeclarations: true, stripInternal: true, preserveConstEnums: true },
584584
/*callback*/ function () {
585585
prependFile(copyright, tsserverLibraryDefinitionFile);
586586

lib/cancellationToken.js

Lines changed: 41 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,15 @@ and limitations under the License.
1515

1616
"use strict";
1717
var fs = require("fs");
18+
function pipeExists(name) {
19+
try {
20+
fs.statSync(name);
21+
return true;
22+
}
23+
catch (e) {
24+
return false;
25+
}
26+
}
1827
function createCancellationToken(args) {
1928
var cancellationPipeName;
2029
for (var i = 0; i < args.length - 1; i++) {
@@ -24,18 +33,39 @@ function createCancellationToken(args) {
2433
}
2534
}
2635
if (!cancellationPipeName) {
27-
return { isCancellationRequested: function () { return false; } };
36+
return {
37+
isCancellationRequested: function () { return false; },
38+
setRequest: function (_requestId) { return void 0; },
39+
resetRequest: function (_requestId) { return void 0; }
40+
};
2841
}
29-
return {
30-
isCancellationRequested: function () {
31-
try {
32-
fs.statSync(cancellationPipeName);
33-
return true;
34-
}
35-
catch (e) {
36-
return false;
37-
}
42+
if (cancellationPipeName.charAt(cancellationPipeName.length - 1) === "*") {
43+
var namePrefix_1 = cancellationPipeName.slice(0, -1);
44+
if (namePrefix_1.length === 0 || namePrefix_1.indexOf("*") >= 0) {
45+
throw new Error("Invalid name for template cancellation pipe: it should have length greater than 2 characters and contain only one '*'.");
3846
}
39-
};
47+
var perRequestPipeName_1;
48+
var currentRequestId_1;
49+
return {
50+
isCancellationRequested: function () { return perRequestPipeName_1 !== undefined && pipeExists(perRequestPipeName_1); },
51+
setRequest: function (requestId) {
52+
currentRequestId_1 = currentRequestId_1;
53+
perRequestPipeName_1 = namePrefix_1 + requestId;
54+
},
55+
resetRequest: function (requestId) {
56+
if (currentRequestId_1 !== requestId) {
57+
throw new Error("Mismatched request id, expected " + currentRequestId_1 + ", actual " + requestId);
58+
}
59+
perRequestPipeName_1 = undefined;
60+
}
61+
};
62+
}
63+
else {
64+
return {
65+
isCancellationRequested: function () { return pipeExists(cancellationPipeName); },
66+
setRequest: function (_requestId) { return void 0; },
67+
resetRequest: function (_requestId) { return void 0; }
68+
};
69+
}
4070
}
4171
module.exports = createCancellationToken;

0 commit comments

Comments
 (0)