Skip to content

Commit ab10b86

Browse files
committed
Almost working?
1 parent 19fe86a commit ab10b86

74 files changed

Lines changed: 377 additions & 273 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

Jakefile.js

Lines changed: 140 additions & 114 deletions
Large diffs are not rendered by default.

scripts/buildProtocol.ts

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ class DeclarationsWalker {
4646
if (!s) {
4747
return;
4848
}
49-
if (s.name === "Array") {
49+
if (s.name === "Array" || s.name === "ReadOnlyArray") {
5050
// we should process type argument instead
5151
return this.processType((<any>type).typeArguments[0]);
5252
}
@@ -55,7 +55,7 @@ class DeclarationsWalker {
5555
if (declarations) {
5656
for (const decl of declarations) {
5757
const sourceFile = decl.getSourceFile();
58-
if (sourceFile === this.protocolFile || path.basename(sourceFile.fileName) === "lib.d.ts") {
58+
if (sourceFile === this.protocolFile || /lib\.(.*)\.d.ts/.test(path.basename(sourceFile.fileName))) {
5959
return;
6060
}
6161
if (decl.kind === ts.SyntaxKind.EnumDeclaration && !isStringEnum(decl as ts.EnumDeclaration)) {
@@ -131,13 +131,20 @@ function writeProtocolFile(outputFile: string, protocolTs: string, typeScriptSer
131131
const program = ts.createProgram([protocolTs, typeScriptServicesDts], options);
132132

133133
let protocolDts: string | undefined;
134-
program.emit(program.getSourceFile(protocolTs), (file, content) => {
134+
const emitResult = program.emit(program.getSourceFile(protocolTs), (file, content) => {
135135
if (endsWith(file, ".d.ts")) {
136136
protocolDts = content;
137137
}
138138
});
139+
139140
if (protocolDts === undefined) {
140-
throw new Error(`Declaration file for protocol.ts is not generated`)
141+
const diagHost: ts.FormatDiagnosticsHost = {
142+
getCanonicalFileName: function (f) { return f; },
143+
getCurrentDirectory: function() { return '.'; },
144+
getNewLine: function() { return "\r\n"; }
145+
}
146+
const diags = emitResult.diagnostics.map(d => ts.formatDiagnostic(d, diagHost)).join("\r\n");
147+
throw new Error(`Declaration file for protocol.ts is not generated:\r\n${diags}`);
141148
}
142149
return protocolDts;
143150
}

src/compiler/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"files": [
77
"binder.ts",
88
"symbolWalker.ts",
9-
"moduleNameResolver.ts",
109
"checker.ts",
1110
"factory.ts",
1211
"visitor.ts",

src/harness/tsconfig.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
{ "path": "../parser" },
1616
{ "path": "../compiler" },
1717
{ "path": "../services" },
18+
{ "path": "../jsTyping" },
1819
{ "path": "../server" },
1920
{ "path": "../typingsInstallerCore" }
2021
],

src/jsTyping/tsconfig.json

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"extends": "../tsconfig-base",
3+
"compilerOptions": {
4+
"outFile": "../../built/local/jsTyping.js",
5+
"types": [
6+
"node"
7+
],
8+
"lib": [
9+
"es6",
10+
"scripthost"
11+
]
12+
},
13+
"references": [
14+
{ "path": "../core" },
15+
{ "path": "../parser" }
16+
],
17+
"files": [
18+
"shared.ts",
19+
"types.ts",
20+
"jsTyping.ts",
21+
"semver.ts"
22+
]
23+
}

src/jsTyping/types.ts

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
declare namespace ts.server {
2+
export type ActionSet = "action::set";
3+
export type ActionInvalidate = "action::invalidate";
4+
export type ActionPackageInstalled = "action::packageInstalled";
5+
export type EventTypesRegistry = "event::typesRegistry";
6+
export type EventBeginInstallTypes = "event::beginInstallTypes";
7+
export type EventEndInstallTypes = "event::endInstallTypes";
8+
export type EventInitializationFailed = "event::initializationFailed";
9+
10+
export interface SortedReadonlyArray<T> extends ReadonlyArray<T> {
11+
" __sortedArrayBrand": any;
12+
}
13+
14+
export interface TypingInstallerResponse {
15+
readonly kind: ActionSet | ActionInvalidate | EventTypesRegistry | ActionPackageInstalled | EventBeginInstallTypes | EventEndInstallTypes | EventInitializationFailed;
16+
}
17+
18+
export interface TypingInstallerRequestWithProjectName {
19+
readonly projectName: string;
20+
}
21+
22+
/* @internal */
23+
export type TypingInstallerRequestUnion = DiscoverTypings | CloseProject | TypesRegistryRequest | InstallPackageRequest;
24+
25+
export interface DiscoverTypings extends TypingInstallerRequestWithProjectName {
26+
readonly fileNames: string[];
27+
readonly projectRootPath: Path;
28+
readonly compilerOptions: CompilerOptions;
29+
readonly typeAcquisition: TypeAcquisition;
30+
readonly unresolvedImports: SortedReadonlyArray<string>;
31+
readonly cachePath?: string;
32+
readonly kind: "discover";
33+
}
34+
35+
export interface CloseProject extends TypingInstallerRequestWithProjectName {
36+
readonly kind: "closeProject";
37+
}
38+
39+
export interface TypesRegistryRequest {
40+
readonly kind: "typesRegistry";
41+
}
42+
43+
export interface InstallPackageRequest extends TypingInstallerRequestWithProjectName {
44+
readonly kind: "installPackage";
45+
readonly fileName: Path;
46+
readonly packageName: string;
47+
readonly projectRootPath: Path;
48+
}
49+
50+
/* @internal */
51+
export interface TypesRegistryResponse extends TypingInstallerResponse {
52+
readonly kind: EventTypesRegistry;
53+
readonly typesRegistry: MapLike<MapLike<string>>;
54+
}
55+
56+
export interface PackageInstalledResponse extends ProjectResponse {
57+
readonly kind: ActionPackageInstalled;
58+
readonly success: boolean;
59+
readonly message: string;
60+
}
61+
62+
export interface InitializationFailedResponse extends TypingInstallerResponse {
63+
readonly kind: EventInitializationFailed;
64+
readonly message: string;
65+
}
66+
67+
export interface ProjectResponse extends TypingInstallerResponse {
68+
readonly projectName: string;
69+
}
70+
71+
export interface InvalidateCachedTypings extends ProjectResponse {
72+
readonly kind: ActionInvalidate;
73+
}
74+
75+
export interface InstallTypes extends ProjectResponse {
76+
readonly kind: EventBeginInstallTypes | EventEndInstallTypes;
77+
readonly eventId: number;
78+
readonly typingsInstallerVersion: string;
79+
readonly packagesToInstall: ReadonlyArray<string>;
80+
}
81+
82+
export interface BeginInstallTypes extends InstallTypes {
83+
readonly kind: EventBeginInstallTypes;
84+
}
85+
86+
export interface EndInstallTypes extends InstallTypes {
87+
readonly kind: EventEndInstallTypes;
88+
readonly installSuccess: boolean;
89+
}
90+
91+
/* @internal */
92+
export interface InstallTypingHost extends JsTyping.TypingResolutionHost {
93+
useCaseSensitiveFileNames: boolean;
94+
writeFile(path: string, content: string): void;
95+
createDirectory(path: string): void;
96+
watchFile?(path: string, callback: FileWatcherCallback, pollingInterval?: number): FileWatcher;
97+
watchDirectory?(path: string, callback: DirectoryWatcherCallback, recursive?: boolean): FileWatcher;
98+
}
99+
100+
export interface SetTypings extends ProjectResponse {
101+
readonly typeAcquisition: TypeAcquisition;
102+
readonly compilerOptions: CompilerOptions;
103+
readonly typings: string[];
104+
readonly unresolvedImports: SortedReadonlyArray<string>;
105+
readonly kind: ActionSet;
106+
}
107+
108+
/* @internal */
109+
export type TypingInstallerResponseUnion = SetTypings | InvalidateCachedTypings | TypesRegistryResponse | PackageInstalledResponse | InstallTypes | InitializationFailedResponse;
110+
}

0 commit comments

Comments
 (0)