Skip to content

Commit f5698fc

Browse files
committed
Merge branch 'EmitStringEnumsInProtocol' into release-2.5
2 parents baeedab + 3e5de59 commit f5698fc

File tree

6 files changed

+104
-7
lines changed

6 files changed

+104
-7
lines changed

lib/protocol.d.ts

Lines changed: 79 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1963,6 +1963,7 @@ declare namespace ts.server.protocol {
19631963
System = "System",
19641964
ES6 = "ES6",
19651965
ES2015 = "ES2015",
1966+
ESNext = "ESNext",
19661967
}
19671968
const enum ModuleResolutionKind {
19681969
Classic = "Classic",
@@ -1977,6 +1978,9 @@ declare namespace ts.server.protocol {
19771978
ES5 = "ES5",
19781979
ES6 = "ES6",
19791980
ES2015 = "ES2015",
1981+
ES2016 = "ES2016",
1982+
ES2017 = "ES2017",
1983+
ESNext = "ESNext",
19801984
}
19811985
}
19821986
declare namespace ts.server.protocol {
@@ -1998,6 +2002,81 @@ declare namespace ts.server.protocol {
19982002
position: number;
19992003
}
20002004

2005+
enum HighlightSpanKind {
2006+
none = "none",
2007+
definition = "definition",
2008+
reference = "reference",
2009+
writtenReference = "writtenReference",
2010+
}
2011+
2012+
enum ScriptElementKind {
2013+
unknown = "",
2014+
warning = "warning",
2015+
/** predefined type (void) or keyword (class) */
2016+
keyword = "keyword",
2017+
/** top level script node */
2018+
scriptElement = "script",
2019+
/** module foo {} */
2020+
moduleElement = "module",
2021+
/** class X {} */
2022+
classElement = "class",
2023+
/** var x = class X {} */
2024+
localClassElement = "local class",
2025+
/** interface Y {} */
2026+
interfaceElement = "interface",
2027+
/** type T = ... */
2028+
typeElement = "type",
2029+
/** enum E */
2030+
enumElement = "enum",
2031+
enumMemberElement = "enum member",
2032+
/**
2033+
* Inside module and script only
2034+
* const v = ..
2035+
*/
2036+
variableElement = "var",
2037+
/** Inside function */
2038+
localVariableElement = "local var",
2039+
/**
2040+
* Inside module and script only
2041+
* function f() { }
2042+
*/
2043+
functionElement = "function",
2044+
/** Inside function */
2045+
localFunctionElement = "local function",
2046+
/** class X { [public|private]* foo() {} } */
2047+
memberFunctionElement = "method",
2048+
/** class X { [public|private]* [get|set] foo:number; } */
2049+
memberGetAccessorElement = "getter",
2050+
memberSetAccessorElement = "setter",
2051+
/**
2052+
* class X { [public|private]* foo:number; }
2053+
* interface Y { foo:number; }
2054+
*/
2055+
memberVariableElement = "property",
2056+
/** class X { constructor() { } } */
2057+
constructorImplementationElement = "constructor",
2058+
/** interface Y { ():number; } */
2059+
callSignatureElement = "call",
2060+
/** interface Y { []:number; } */
2061+
indexSignatureElement = "index",
2062+
/** interface Y { new():Y; } */
2063+
constructSignatureElement = "construct",
2064+
/** function foo(*Y*: string) */
2065+
parameterElement = "parameter",
2066+
typeParameterElement = "type parameter",
2067+
primitiveType = "primitive type",
2068+
label = "label",
2069+
alias = "alias",
2070+
constElement = "const",
2071+
letElement = "let",
2072+
directory = "directory",
2073+
externalModuleName = "external module name",
2074+
/**
2075+
* <JsxTagName attribute1 attribute2={0} />
2076+
*/
2077+
jsxAttribute = "JSX attribute",
2078+
}
2079+
20012080
interface TypeAcquisition {
20022081
enableAutoDiscovery?: boolean;
20032082
enable?: boolean;
@@ -2033,8 +2112,6 @@ declare namespace ts.server.protocol {
20332112
}
20342113
declare namespace ts {
20352114
// these types are empty stubs for types from services and should not be used directly
2036-
export type HighlightSpanKind = never;
2037-
export type ScriptElementKind = never;
20382115
export type ScriptKind = never;
20392116
export type IndentStyle = never;
20402117
export type JsxEmit = never;

lib/tsserver.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77866,6 +77866,7 @@ var ts;
7786677866
ModuleKind["System"] = "System";
7786777867
ModuleKind["ES6"] = "ES6";
7786877868
ModuleKind["ES2015"] = "ES2015";
77869+
ModuleKind["ESNext"] = "ESNext";
7786977870
})(ModuleKind = protocol.ModuleKind || (protocol.ModuleKind = {}));
7787077871
var ModuleResolutionKind;
7787177872
(function (ModuleResolutionKind) {
@@ -77883,6 +77884,9 @@ var ts;
7788377884
ScriptTarget["ES5"] = "ES5";
7788477885
ScriptTarget["ES6"] = "ES6";
7788577886
ScriptTarget["ES2015"] = "ES2015";
77887+
ScriptTarget["ES2016"] = "ES2016";
77888+
ScriptTarget["ES2017"] = "ES2017";
77889+
ScriptTarget["ESNext"] = "ESNext";
7788677890
})(ScriptTarget = protocol.ScriptTarget || (protocol.ScriptTarget = {}));
7788777891
})(protocol = server.protocol || (server.protocol = {}));
7788877892
})(server = ts.server || (ts.server = {}));

lib/tsserverlibrary.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4730,6 +4730,7 @@ declare namespace ts.server.protocol {
47304730
System = "System",
47314731
ES6 = "ES6",
47324732
ES2015 = "ES2015",
4733+
ESNext = "ESNext",
47334734
}
47344735
enum ModuleResolutionKind {
47354736
Classic = "Classic",
@@ -4744,6 +4745,9 @@ declare namespace ts.server.protocol {
47444745
ES5 = "ES5",
47454746
ES6 = "ES6",
47464747
ES2015 = "ES2015",
4748+
ES2016 = "ES2016",
4749+
ES2017 = "ES2017",
4750+
ESNext = "ESNext",
47474751
}
47484752
}
47494753
declare namespace ts.server {

lib/tsserverlibrary.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77209,6 +77209,7 @@ var ts;
7720977209
ModuleKind["System"] = "System";
7721077210
ModuleKind["ES6"] = "ES6";
7721177211
ModuleKind["ES2015"] = "ES2015";
77212+
ModuleKind["ESNext"] = "ESNext";
7721277213
})(ModuleKind = protocol.ModuleKind || (protocol.ModuleKind = {}));
7721377214
var ModuleResolutionKind;
7721477215
(function (ModuleResolutionKind) {
@@ -77226,6 +77227,9 @@ var ts;
7722677227
ScriptTarget["ES5"] = "ES5";
7722777228
ScriptTarget["ES6"] = "ES6";
7722877229
ScriptTarget["ES2015"] = "ES2015";
77230+
ScriptTarget["ES2016"] = "ES2016";
77231+
ScriptTarget["ES2017"] = "ES2017";
77232+
ScriptTarget["ESNext"] = "ESNext";
7722977233
})(ScriptTarget = protocol.ScriptTarget || (protocol.ScriptTarget = {}));
7723077234
})(protocol = server.protocol || (server.protocol = {}));
7723177235
})(server = ts.server || (ts.server = {}));

scripts/buildProtocol.ts

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,23 @@ function endsWith(s: string, suffix: string) {
77
return s.lastIndexOf(suffix, s.length - suffix.length) !== -1;
88
}
99

10+
function isStringEnum(declaration: ts.EnumDeclaration) {
11+
return declaration.members.length && declaration.members.every(m => m.initializer && m.initializer.kind === ts.SyntaxKind.StringLiteral);
12+
}
13+
1014
class DeclarationsWalker {
1115
private visitedTypes: ts.Type[] = [];
1216
private text = "";
1317
private removedTypes: ts.Type[] = [];
14-
18+
1519
private constructor(private typeChecker: ts.TypeChecker, private protocolFile: ts.SourceFile) {
1620
}
1721

1822
static getExtraDeclarations(typeChecker: ts.TypeChecker, protocolFile: ts.SourceFile): string {
1923
let text = "declare namespace ts.server.protocol {\n";
2024
var walker = new DeclarationsWalker(typeChecker, protocolFile);
2125
walker.visitTypeNodes(protocolFile);
22-
text = walker.text
26+
text = walker.text
2327
? `declare namespace ts.server.protocol {\n${walker.text}}`
2428
: "";
2529
if (walker.removedTypes) {
@@ -52,7 +56,7 @@ class DeclarationsWalker {
5256
if (sourceFile === this.protocolFile || path.basename(sourceFile.fileName) === "lib.d.ts") {
5357
return;
5458
}
55-
if (decl.kind === ts.SyntaxKind.EnumDeclaration) {
59+
if (decl.kind === ts.SyntaxKind.EnumDeclaration && !isStringEnum(decl as ts.EnumDeclaration)) {
5660
this.removedTypes.push(type);
5761
return;
5862
}
@@ -91,7 +95,7 @@ class DeclarationsWalker {
9195
for (const type of heritageClauses[0].types) {
9296
this.processTypeOfNode(type);
9397
}
94-
}
98+
}
9599
break;
96100
}
97101
}
@@ -110,7 +114,7 @@ class DeclarationsWalker {
110114
this.processType(type);
111115
}
112116
}
113-
}
117+
}
114118
}
115119

116120
function writeProtocolFile(outputFile: string, protocolTs: string, typeScriptServicesDts: string) {

src/server/protocol.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2473,6 +2473,7 @@ namespace ts.server.protocol {
24732473
System = "System",
24742474
ES6 = "ES6",
24752475
ES2015 = "ES2015",
2476+
ESNext = "ESNext"
24762477
}
24772478

24782479
export const enum ModuleResolutionKind {
@@ -2490,5 +2491,8 @@ namespace ts.server.protocol {
24902491
ES5 = "ES5",
24912492
ES6 = "ES6",
24922493
ES2015 = "ES2015",
2494+
ES2016 = "ES2016",
2495+
ES2017 = "ES2017",
2496+
ESNext = "ESNext"
24932497
}
24942498
}

0 commit comments

Comments
 (0)