Skip to content

Commit a1b9416

Browse files
committed
Merge remote-tracking branch 'origin/release-2.0.5' into vladima/generate-protocol
2 parents 9a70773 + d6eab36 commit a1b9416

File tree

60 files changed

+2587
-132
lines changed

Some content is hidden

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

60 files changed

+2587
-132
lines changed

Gulpfile.ts

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@ declare module "gulp-typescript" {
1717
stripInternal?: boolean;
1818
types?: string[];
1919
}
20-
interface CompileStream extends NodeJS.ReadWriteStream { } // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required
2120
}
2221
import * as insert from "gulp-insert";
2322
import * as sourcemaps from "gulp-sourcemaps";
@@ -378,18 +377,18 @@ gulp.task(builtLocalCompiler, false, [servicesFile], () => {
378377
return localCompilerProject.src()
379378
.pipe(newer(builtLocalCompiler))
380379
.pipe(sourcemaps.init())
381-
.pipe(tsc(localCompilerProject))
380+
.pipe(localCompilerProject())
382381
.pipe(prependCopyright())
383382
.pipe(sourcemaps.write("."))
384-
.pipe(gulp.dest(builtLocalDirectory));
383+
.pipe(gulp.dest("."));
385384
});
386385

387386
gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
388387
const servicesProject = tsc.createProject("src/services/tsconfig.json", getCompilerSettings({ removeComments: false }, /*useBuiltCompiler*/false));
389388
const {js, dts} = servicesProject.src()
390389
.pipe(newer(servicesFile))
391390
.pipe(sourcemaps.init())
392-
.pipe(tsc(servicesProject));
391+
.pipe(servicesProject());
393392
const completedJs = js.pipe(prependCopyright())
394393
.pipe(sourcemaps.write("."));
395394
const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true))
@@ -407,13 +406,13 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => {
407406
file.path = nodeDefinitionsFile;
408407
return content + "\r\nexport = ts;";
409408
}))
410-
.pipe(gulp.dest(builtLocalDirectory)),
409+
.pipe(gulp.dest(".")),
411410
completedDts.pipe(clone())
412411
.pipe(insert.transform((content, file) => {
413412
file.path = nodeStandaloneDefinitionsFile;
414413
return content.replace(/declare (namespace|module) ts/g, 'declare module "typescript"');
415414
}))
416-
]).pipe(gulp.dest(builtLocalDirectory));
415+
]).pipe(gulp.dest("."));
417416
});
418417

419418
// cancellationToken.js
@@ -423,7 +422,7 @@ gulp.task(cancellationTokenJs, false, [servicesFile], () => {
423422
return cancellationTokenProject.src()
424423
.pipe(newer(cancellationTokenJs))
425424
.pipe(sourcemaps.init())
426-
.pipe(tsc(cancellationTokenProject))
425+
.pipe(cancellationTokenProject())
427426
.pipe(prependCopyright())
428427
.pipe(sourcemaps.write("."))
429428
.pipe(gulp.dest(builtLocalDirectory));
@@ -436,10 +435,10 @@ gulp.task(typingsInstallerJs, false, [servicesFile], () => {
436435
return cancellationTokenProject.src()
437436
.pipe(newer(typingsInstallerJs))
438437
.pipe(sourcemaps.init())
439-
.pipe(tsc(cancellationTokenProject))
438+
.pipe(cancellationTokenProject())
440439
.pipe(prependCopyright())
441440
.pipe(sourcemaps.write("."))
442-
.pipe(gulp.dest(builtLocalDirectory));
441+
.pipe(gulp.dest("."));
443442
});
444443

445444
const serverFile = path.join(builtLocalDirectory, "tsserver.js");
@@ -449,10 +448,10 @@ gulp.task(serverFile, false, [servicesFile, typingsInstallerJs, cancellationToke
449448
return serverProject.src()
450449
.pipe(newer(serverFile))
451450
.pipe(sourcemaps.init())
452-
.pipe(tsc(serverProject))
451+
.pipe(serverProject())
453452
.pipe(prependCopyright())
454453
.pipe(sourcemaps.write("."))
455-
.pipe(gulp.dest(builtLocalDirectory));
454+
.pipe(gulp.dest("."));
456455
});
457456

458457
const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js");
@@ -463,14 +462,14 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => {
463462
const {js, dts}: { js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream } = serverLibraryProject.src()
464463
.pipe(sourcemaps.init())
465464
.pipe(newer(tsserverLibraryFile))
466-
.pipe(tsc(serverLibraryProject));
465+
.pipe(serverLibraryProject());
467466

468467
return merge2([
469468
js.pipe(prependCopyright())
470469
.pipe(sourcemaps.write("."))
471-
.pipe(gulp.dest(builtLocalDirectory)),
470+
.pipe(gulp.dest(".")),
472471
dts.pipe(prependCopyright())
473-
.pipe(gulp.dest(builtLocalDirectory))
472+
.pipe(gulp.dest("."))
474473
]);
475474
});
476475

@@ -542,9 +541,9 @@ gulp.task(run, false, [servicesFile], () => {
542541
return testProject.src()
543542
.pipe(newer(run))
544543
.pipe(sourcemaps.init())
545-
.pipe(tsc(testProject))
544+
.pipe(testProject())
546545
.pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../" }))
547-
.pipe(gulp.dest(builtLocalDirectory));
546+
.pipe(gulp.dest("."));
548547
});
549548

550549
const internalTests = "internal/";
@@ -723,16 +722,16 @@ declare module "convert-source-map" {
723722
}
724723

725724
gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile], (done) => {
726-
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "built/local/bundle.js" }, /*useBuiltCompiler*/ true));
725+
const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "../../built/local/bundle.js" }, /*useBuiltCompiler*/ true));
727726
return testProject.src()
728727
.pipe(newer("built/local/bundle.js"))
729728
.pipe(sourcemaps.init())
730-
.pipe(tsc(testProject))
729+
.pipe(testProject())
731730
.pipe(through2.obj((file, enc, next) => {
732731
const originalMap = file.sourceMap;
733732
const prebundledContent = file.contents.toString();
734733
// Make paths absolute to help sorcery deal with all the terrible paths being thrown around
735-
originalMap.sources = originalMap.sources.map(s => path.resolve("src", s));
734+
originalMap.sources = originalMap.sources.map(s => path.resolve(s));
736735
// intoStream (below) makes browserify think the input file is named this, so this is what it puts in the sourcemap
737736
originalMap.file = "built/local/_stream_0.js";
738737

src/harness/fourslash.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2067,6 +2067,18 @@ namespace FourSlash {
20672067
}
20682068
}
20692069

2070+
public verifyNavigationTree(json: any) {
2071+
const tree = this.languageService.getNavigationTree(this.activeFile.fileName);
2072+
if (JSON.stringify(tree, replacer) !== JSON.stringify(json)) {
2073+
this.raiseError(`verifyNavigationTree failed - expected: ${stringify(json)}, got: ${stringify(tree, replacer)}`);
2074+
}
2075+
2076+
function replacer(key: string, value: any) {
2077+
// Don't check "spans", and omit falsy values.
2078+
return key === "spans" ? undefined : (value || undefined);
2079+
}
2080+
}
2081+
20702082
public printNavigationItems(searchValue: string) {
20712083
const items = this.languageService.getNavigateToItems(searchValue);
20722084
const length = items && items.length;
@@ -3103,6 +3115,9 @@ namespace FourSlashInterface {
31033115
public navigationBar(json: any) {
31043116
this.state.verifyNavigationBar(json);
31053117
}
3118+
public navigationTree(json: any) {
3119+
this.state.verifyNavigationTree(json);
3120+
}
31063121

31073122
public navigationItemsListCount(count: number, searchValue: string, matchKind?: string) {
31083123
this.state.verifyNavigationItemsCount(count, searchValue, matchKind);

src/harness/harnessLanguageService.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,10 @@ namespace Harness.LanguageService {
453453
getNavigationBarItems(fileName: string): ts.NavigationBarItem[] {
454454
return unwrapJSONCallResult(this.shim.getNavigationBarItems(fileName));
455455
}
456+
getNavigationTree(fileName: string): ts.NavigationTree {
457+
return unwrapJSONCallResult(this.shim.getNavigationTree(fileName));
458+
}
459+
456460
getOutliningSpans(fileName: string): ts.OutliningSpan[] {
457461
return unwrapJSONCallResult(this.shim.getOutliningSpans(fileName));
458462
}

src/server/cancellationToken/tsconfig.json

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
"removeComments": true,
66
"preserveConstEnums": true,
77
"pretty": true,
8-
"outDir": "../../../built/local",
98
"module": "commonjs",
109
"sourceMap": true,
1110
"stripInternal": true,

src/server/client.ts

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -460,7 +460,7 @@ namespace ts.server {
460460
return this.lastRenameEntry.locations;
461461
}
462462

463-
decodeNavigationBarItems(items: protocol.NavigationBarItem[], fileName: string, lineMap: number[]): NavigationBarItem[] {
463+
private decodeNavigationBarItems(items: protocol.NavigationBarItem[], fileName: string, lineMap: number[]): NavigationBarItem[] {
464464
if (!items) {
465465
return [];
466466
}
@@ -469,10 +469,7 @@ namespace ts.server {
469469
text: item.text,
470470
kind: item.kind,
471471
kindModifiers: item.kindModifiers || "",
472-
spans: item.spans.map(span =>
473-
createTextSpanFromBounds(
474-
this.lineOffsetToPosition(fileName, span.start, lineMap),
475-
this.lineOffsetToPosition(fileName, span.end, lineMap))),
472+
spans: item.spans.map(span => this.decodeSpan(span, fileName, lineMap)),
476473
childItems: this.decodeNavigationBarItems(item.childItems, fileName, lineMap),
477474
indent: item.indent,
478475
bolded: false,
@@ -481,17 +478,37 @@ namespace ts.server {
481478
}
482479

483480
getNavigationBarItems(fileName: string): NavigationBarItem[] {
484-
const args: protocol.FileRequestArgs = {
485-
file: fileName
486-
};
487-
488-
const request = this.processRequest<protocol.NavBarRequest>(CommandNames.NavBar, args);
481+
const request = this.processRequest<protocol.NavBarRequest>(CommandNames.NavBar, { file: fileName });
489482
const response = this.processResponse<protocol.NavBarResponse>(request);
490483

491484
const lineMap = this.getLineMap(fileName);
492485
return this.decodeNavigationBarItems(response.body, fileName, lineMap);
493486
}
494487

488+
private decodeNavigationTree(tree: protocol.NavigationTree, fileName: string, lineMap: number[]): NavigationTree {
489+
return {
490+
text: tree.text,
491+
kind: tree.kind,
492+
kindModifiers: tree.kindModifiers,
493+
spans: tree.spans.map(span => this.decodeSpan(span, fileName, lineMap)),
494+
childItems: map(tree.childItems, item => this.decodeNavigationTree(item, fileName, lineMap))
495+
};
496+
}
497+
498+
getNavigationTree(fileName: string): NavigationTree {
499+
const request = this.processRequest<protocol.NavTreeRequest>(CommandNames.NavTree, { file: fileName });
500+
const response = this.processResponse<protocol.NavTreeResponse>(request);
501+
502+
const lineMap = this.getLineMap(fileName);
503+
return this.decodeNavigationTree(response.body, fileName, lineMap);
504+
}
505+
506+
private decodeSpan(span: protocol.TextSpan, fileName: string, lineMap: number[]) {
507+
return createTextSpanFromBounds(
508+
this.lineOffsetToPosition(fileName, span.start, lineMap),
509+
this.lineOffsetToPosition(fileName, span.end, lineMap));
510+
}
511+
495512
getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan {
496513
throw new Error("Not Implemented Yet.");
497514
}

src/server/protocol.ts

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,8 @@ namespace ts.server.protocol {
3838
export type Navto = "navto";
3939
/* @internal */
4040
export type NavtoFull = "navto-full";
41+
export type NavTree = "navtree";
42+
export type NavTreeFull = "navtree-full";
4143
export type Occurrences = "occurrences";
4244
export type DocumentHighlights = "documentHighlights";
4345
/* @internal */
@@ -74,6 +76,7 @@ namespace ts.server.protocol {
7476
export type EncodedSemanticClassificationsFull = "encodedSemanticClassifications-full";
7577
/* @internal */
7678
export type Cleanup = "cleanup";
79+
/* @internal */
7780
export type OutliningSpans = "outliningSpans";
7881
export type TodoComments = "todoComments";
7982
export type Indentation = "indentation";
@@ -211,7 +214,7 @@ namespace ts.server.protocol {
211214
*/
212215
export interface TodoCommentRequestArgs extends FileRequestArgs {
213216
/**
214-
* Array of target TodoCommentDescriptors that describes TODO comments to be found
217+
* Array of target TodoCommentDescriptors that describes TODO comments to be found
215218
*/
216219
descriptors: TodoCommentDescriptor[];
217220
}
@@ -226,13 +229,15 @@ namespace ts.server.protocol {
226229
/**
227230
* Request to obtain outlining spans in file.
228231
*/
232+
/* @internal */
229233
export interface OutliningSpansRequest extends FileRequest {
230234
command: CommandTypes.OutliningSpans;
231235
}
232236

233237
/**
234238
* Response to OutliningSpansRequest request.
235239
*/
240+
/* @internal */
236241
export interface OutliningSpansResponse extends Response {
237242
body?: OutliningSpan[];
238243
}
@@ -376,7 +381,7 @@ namespace ts.server.protocol {
376381
offset: number;
377382

378383
/**
379-
* Position (can be specified instead of line/offset pair)
384+
* Position (can be specified instead of line/offset pair)
380385
*/
381386
/* @internal */
382387
position?: number;
@@ -723,12 +728,12 @@ namespace ts.server.protocol {
723728

724729
/**
725730
* Represents a file in external project.
726-
* External project is project whose set of files, compilation options and open\close state
731+
* External project is project whose set of files, compilation options and open\close state
727732
* is maintained by the client (i.e. if all this data come from .csproj file in Visual Studio).
728733
* External project will exist even if all files in it are closed and should be closed explicity.
729-
* If external project includes one or more tsconfig.json/jsconfig.json files then tsserver will
734+
* If external project includes one or more tsconfig.json/jsconfig.json files then tsserver will
730735
* create configured project for every config file but will maintain a link that these projects were created
731-
* as a result of opening external project so they should be removed once external project is closed.
736+
* as a result of opening external project so they should be removed once external project is closed.
732737
*/
733738
export interface ExternalFile {
734739
/**
@@ -1121,7 +1126,7 @@ namespace ts.server.protocol {
11211126
}
11221127

11231128
/**
1124-
* Response for CompileOnSaveAffectedFileListRequest request;
1129+
* Response for CompileOnSaveAffectedFileListRequest request;
11251130
*/
11261131
export interface CompileOnSaveAffectedFileListResponse extends Response {
11271132
body: CompileOnSaveAffectedFileListSingleProject[];
@@ -1877,6 +1882,14 @@ namespace ts.server.protocol {
18771882
command: CommandTypes.NavBar;
18781883
}
18791884

1885+
/**
1886+
* NavTree request; value of command field is "navtree".
1887+
* Return response giving the navigation tree of the requested file.
1888+
*/
1889+
export interface NavTreeRequest extends FileRequest {
1890+
command: CommandTypes.NavTree;
1891+
}
1892+
18801893
export interface NavigationBarItem {
18811894
/**
18821895
* The item's display text.
@@ -1909,7 +1922,20 @@ namespace ts.server.protocol {
19091922
indent: number;
19101923
}
19111924

1925+
/** protocol.NavigationTree is identical to ts.NavigationTree, except using protocol.TextSpan instead of ts.TextSpan */
1926+
export interface NavigationTree {
1927+
text: string;
1928+
kind: string;
1929+
kindModifiers: string;
1930+
spans: TextSpan[];
1931+
childItems?: NavigationTree[];
1932+
}
1933+
19121934
export interface NavBarResponse extends Response {
19131935
body?: NavigationBarItem[];
19141936
}
1937+
1938+
export interface NavTreeResponse extends Response {
1939+
body?: NavigationTree;
1940+
}
19151941
}

src/server/scriptInfo.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ namespace ts.server {
44

55
export class ScriptInfo {
66
/**
7-
* All projects that include this file
7+
* All projects that include this file
88
*/
99
readonly containingProjects: Project[] = [];
1010
private formatCodeSettings: ts.FormatCodeSettings;

0 commit comments

Comments
 (0)