From 2f2117c0eee8bcbb9ac076f89f6207e647e89f3f Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Wed, 12 Oct 2016 08:38:26 -0700 Subject: [PATCH 1/2] Port #11290 and #11358 to release-2.0.5 --- Gulpfile.ts | 37 +++++++++++----------- src/server/cancellationToken/tsconfig.json | 1 - src/server/tsconfig.json | 2 +- src/server/tsconfig.library.json | 2 +- src/server/typingsInstaller/tsconfig.json | 2 +- 5 files changed, 21 insertions(+), 23 deletions(-) diff --git a/Gulpfile.ts b/Gulpfile.ts index 28a465c47d4..82d38f3c7d5 100644 --- a/Gulpfile.ts +++ b/Gulpfile.ts @@ -17,7 +17,6 @@ declare module "gulp-typescript" { stripInternal?: boolean; types?: string[]; } - interface CompileStream extends NodeJS.ReadWriteStream { } // Either gulp or gulp-typescript has some odd typings which don't reflect reality, making this required } import * as insert from "gulp-insert"; import * as sourcemaps from "gulp-sourcemaps"; @@ -378,10 +377,10 @@ gulp.task(builtLocalCompiler, false, [servicesFile], () => { return localCompilerProject.src() .pipe(newer(builtLocalCompiler)) .pipe(sourcemaps.init()) - .pipe(tsc(localCompilerProject)) + .pipe(localCompilerProject()) .pipe(prependCopyright()) .pipe(sourcemaps.write(".")) - .pipe(gulp.dest(builtLocalDirectory)); + .pipe(gulp.dest(".")); }); gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => { @@ -389,7 +388,7 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => { const {js, dts} = servicesProject.src() .pipe(newer(servicesFile)) .pipe(sourcemaps.init()) - .pipe(tsc(servicesProject)); + .pipe(servicesProject()); const completedJs = js.pipe(prependCopyright()) .pipe(sourcemaps.write(".")); const completedDts = dts.pipe(prependCopyright(/*outputCopyright*/true)) @@ -407,13 +406,13 @@ gulp.task(servicesFile, false, ["lib", "generate-diagnostics"], () => { file.path = nodeDefinitionsFile; return content + "\r\nexport = ts;"; })) - .pipe(gulp.dest(builtLocalDirectory)), + .pipe(gulp.dest(".")), completedDts.pipe(clone()) .pipe(insert.transform((content, file) => { file.path = nodeStandaloneDefinitionsFile; return content.replace(/declare (namespace|module) ts/g, 'declare module "typescript"'); })) - ]).pipe(gulp.dest(builtLocalDirectory)); + ]).pipe(gulp.dest(".")); }); // cancellationToken.js @@ -423,7 +422,7 @@ gulp.task(cancellationTokenJs, false, [servicesFile], () => { return cancellationTokenProject.src() .pipe(newer(cancellationTokenJs)) .pipe(sourcemaps.init()) - .pipe(tsc(cancellationTokenProject)) + .pipe(cancellationTokenProject()) .pipe(prependCopyright()) .pipe(sourcemaps.write(".")) .pipe(gulp.dest(builtLocalDirectory)); @@ -436,10 +435,10 @@ gulp.task(typingsInstallerJs, false, [servicesFile], () => { return cancellationTokenProject.src() .pipe(newer(typingsInstallerJs)) .pipe(sourcemaps.init()) - .pipe(tsc(cancellationTokenProject)) + .pipe(cancellationTokenProject()) .pipe(prependCopyright()) .pipe(sourcemaps.write(".")) - .pipe(gulp.dest(builtLocalDirectory)); + .pipe(gulp.dest(".")); }); const serverFile = path.join(builtLocalDirectory, "tsserver.js"); @@ -449,10 +448,10 @@ gulp.task(serverFile, false, [servicesFile, typingsInstallerJs, cancellationToke return serverProject.src() .pipe(newer(serverFile)) .pipe(sourcemaps.init()) - .pipe(tsc(serverProject)) + .pipe(serverProject()) .pipe(prependCopyright()) .pipe(sourcemaps.write(".")) - .pipe(gulp.dest(builtLocalDirectory)); + .pipe(gulp.dest(".")); }); const tsserverLibraryFile = path.join(builtLocalDirectory, "tsserverlibrary.js"); @@ -463,14 +462,14 @@ gulp.task(tsserverLibraryFile, false, [servicesFile], (done) => { const {js, dts}: { js: NodeJS.ReadableStream, dts: NodeJS.ReadableStream } = serverLibraryProject.src() .pipe(sourcemaps.init()) .pipe(newer(tsserverLibraryFile)) - .pipe(tsc(serverLibraryProject)); + .pipe(serverLibraryProject()); return merge2([ js.pipe(prependCopyright()) .pipe(sourcemaps.write(".")) - .pipe(gulp.dest(builtLocalDirectory)), + .pipe(gulp.dest(".")), dts.pipe(prependCopyright()) - .pipe(gulp.dest(builtLocalDirectory)) + .pipe(gulp.dest(".")) ]); }); @@ -542,9 +541,9 @@ gulp.task(run, false, [servicesFile], () => { return testProject.src() .pipe(newer(run)) .pipe(sourcemaps.init()) - .pipe(tsc(testProject)) + .pipe(testProject()) .pipe(sourcemaps.write(".", { includeContent: false, sourceRoot: "../../" })) - .pipe(gulp.dest(builtLocalDirectory)); + .pipe(gulp.dest(".")); }); const internalTests = "internal/"; @@ -723,16 +722,16 @@ declare module "convert-source-map" { } gulp.task("browserify", "Runs browserify on run.js to produce a file suitable for running tests in the browser", [servicesFile], (done) => { - const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "built/local/bundle.js" }, /*useBuiltCompiler*/ true)); + const testProject = tsc.createProject("src/harness/tsconfig.json", getCompilerSettings({ outFile: "../../built/local/bundle.js" }, /*useBuiltCompiler*/ true)); return testProject.src() .pipe(newer("built/local/bundle.js")) .pipe(sourcemaps.init()) - .pipe(tsc(testProject)) + .pipe(testProject()) .pipe(through2.obj((file, enc, next) => { const originalMap = file.sourceMap; const prebundledContent = file.contents.toString(); // Make paths absolute to help sorcery deal with all the terrible paths being thrown around - originalMap.sources = originalMap.sources.map(s => path.resolve("src", s)); + originalMap.sources = originalMap.sources.map(s => path.resolve(s)); // intoStream (below) makes browserify think the input file is named this, so this is what it puts in the sourcemap originalMap.file = "built/local/_stream_0.js"; diff --git a/src/server/cancellationToken/tsconfig.json b/src/server/cancellationToken/tsconfig.json index 94c81aa644f..1245fc34fd5 100644 --- a/src/server/cancellationToken/tsconfig.json +++ b/src/server/cancellationToken/tsconfig.json @@ -5,7 +5,6 @@ "removeComments": true, "preserveConstEnums": true, "pretty": true, - "outDir": "../../../built/local", "module": "commonjs", "sourceMap": true, "stripInternal": true, diff --git a/src/server/tsconfig.json b/src/server/tsconfig.json index bd9bb14ba41..9e65eb2b8bc 100644 --- a/src/server/tsconfig.json +++ b/src/server/tsconfig.json @@ -5,7 +5,7 @@ "removeComments": true, "preserveConstEnums": true, "pretty": true, - "out": "../../built/local/tsserver.js", + "outFile": "../../built/local/tsserver.js", "sourceMap": true, "stripInternal": true, "types": [ diff --git a/src/server/tsconfig.library.json b/src/server/tsconfig.library.json index 5d4656a318b..a450b591a7e 100644 --- a/src/server/tsconfig.library.json +++ b/src/server/tsconfig.library.json @@ -3,7 +3,7 @@ "noImplicitAny": true, "removeComments": true, "preserveConstEnums": true, - "out": "../../built/local/tsserverlibrary.js", + "outFile": "../../built/local/tsserverlibrary.js", "sourceMap": true, "stripInternal": true, "declaration": true, diff --git a/src/server/typingsInstaller/tsconfig.json b/src/server/typingsInstaller/tsconfig.json index 20b3f5e266c..fc4b896f267 100644 --- a/src/server/typingsInstaller/tsconfig.json +++ b/src/server/typingsInstaller/tsconfig.json @@ -5,7 +5,7 @@ "removeComments": true, "preserveConstEnums": true, "pretty": true, - "out": "../../built/local/typingsInstaller.js", + "outFile": "../../../built/local/typingsInstaller.js", "sourceMap": true, "stripInternal": true, "types": [ From 2333eb31a15800940b8053c39776285a8cc7131a Mon Sep 17 00:00:00 2001 From: Andy Hanson Date: Tue, 11 Oct 2016 07:48:28 -0700 Subject: [PATCH 2/2] Add "navtree" and "navtree-full" server commands --- src/harness/fourslash.ts | 15 + src/harness/harnessLanguageService.ts | 4 + src/server/client.ts | 37 +- src/server/protocol.d.ts | 32 +- src/server/scriptInfo.ts | 2 +- src/server/session.ts | 95 +- src/server/utilities.ts | 79 +- src/services/navigationBar.ts | 31 +- src/services/services.ts | 34 +- src/services/shims.ts | 10 + src/services/types.ts | 814 ++++++++++++++++++ .../fourslash/deleteClassWithEnumPresent.ts | 26 + tests/cases/fourslash/fourslash.ts | 1 + .../cases/fourslash/getNavigationBarItems.ts | 23 +- tests/cases/fourslash/navbar_const.ts | 11 + .../navbar_contains-no-duplicates.ts | 77 ++ tests/cases/fourslash/navbar_exportDefault.ts | 44 + tests/cases/fourslash/navbar_let.ts | 11 + ...BarAnonymousClassAndFunctionExpressions.ts | 79 ++ ...arAnonymousClassAndFunctionExpressions2.ts | 33 + .../fourslash/navigationBarGetterAndSetter.ts | 27 + tests/cases/fourslash/navigationBarImports.ts | 23 + .../navigationBarItemsBindingPatterns.ts | 51 ++ ...ionBarItemsBindingPatternsInConstructor.ts | 35 + .../navigationBarItemsEmptyConstructors.ts | 17 + .../fourslash/navigationBarItemsExports.ts | 20 + .../fourslash/navigationBarItemsFunctions.ts | 47 + .../navigationBarItemsFunctionsBroken.ts | 17 + .../navigationBarItemsFunctionsBroken2.ts | 21 + .../fourslash/navigationBarItemsImports.ts | 38 + ...ionBarItemsInsideMethodsAndConstructors.ts | 71 ++ .../fourslash/navigationBarItemsItems.ts | 108 +++ .../fourslash/navigationBarItemsItems2.ts | 16 + .../navigationBarItemsItemsExternalModules.ts | 19 + ...navigationBarItemsItemsExternalModules2.ts | 24 + ...navigationBarItemsItemsExternalModules3.ts | 24 + .../navigationBarItemsItemsModuleVariables.ts | 34 + .../navigationBarItemsMissingName1.ts | 22 + .../navigationBarItemsMissingName2.ts | 17 + .../fourslash/navigationBarItemsModules.ts | 67 ++ ...ationBarItemsMultilineStringIdentifiers.ts | 50 ++ ...BarItemsPropertiesDefinedInConstructors.ts | 37 + .../fourslash/navigationBarItemsSymbols1.ts | 25 + .../fourslash/navigationBarItemsSymbols2.ts | 21 + .../fourslash/navigationBarItemsSymbols3.ts | 11 + .../fourslash/navigationBarItemsTypeAlias.ts | 11 + tests/cases/fourslash/navigationBarJsDoc.ts | 19 + .../navigationBarJsDocCommentWithNoTags.ts | 30 + tests/cases/fourslash/navigationBarMerging.ts | 105 +++ .../navigationBarNamespaceImportWithNoName.ts | 12 + .../cases/fourslash/navigationBarVariables.ts | 39 + .../server/jsdocTypedefTagNavigateTo.ts | 23 + tests/cases/fourslash/server/navbar01.ts | 108 +++ .../shims-pp/getNavigationBarItems.ts | 11 + .../fourslash/shims/getNavigationBarItems.ts | 11 + 55 files changed, 2560 insertions(+), 109 deletions(-) create mode 100644 src/services/types.ts create mode 100644 tests/cases/fourslash/navigationBarJsDocCommentWithNoTags.ts diff --git a/src/harness/fourslash.ts b/src/harness/fourslash.ts index f898709442c..39a7a142c6b 100644 --- a/src/harness/fourslash.ts +++ b/src/harness/fourslash.ts @@ -2067,6 +2067,18 @@ namespace FourSlash { } } + public verifyNavigationTree(json: any) { + const tree = this.languageService.getNavigationTree(this.activeFile.fileName); + if (JSON.stringify(tree, replacer) !== JSON.stringify(json)) { + this.raiseError(`verifyNavigationTree failed - expected: ${stringify(json)}, got: ${stringify(tree, replacer)}`); + } + + function replacer(key: string, value: any) { + // Don't check "spans", and omit falsy values. + return key === "spans" ? undefined : (value || undefined); + } + } + public printNavigationItems(searchValue: string) { const items = this.languageService.getNavigateToItems(searchValue); const length = items && items.length; @@ -3103,6 +3115,9 @@ namespace FourSlashInterface { public navigationBar(json: any) { this.state.verifyNavigationBar(json); } + public navigationTree(json: any) { + this.state.verifyNavigationTree(json); + } public navigationItemsListCount(count: number, searchValue: string, matchKind?: string) { this.state.verifyNavigationItemsCount(count, searchValue, matchKind); diff --git a/src/harness/harnessLanguageService.ts b/src/harness/harnessLanguageService.ts index 6e34c80a3cf..20d8aa0522d 100644 --- a/src/harness/harnessLanguageService.ts +++ b/src/harness/harnessLanguageService.ts @@ -453,6 +453,10 @@ namespace Harness.LanguageService { getNavigationBarItems(fileName: string): ts.NavigationBarItem[] { return unwrapJSONCallResult(this.shim.getNavigationBarItems(fileName)); } + getNavigationTree(fileName: string): ts.NavigationTree { + return unwrapJSONCallResult(this.shim.getNavigationTree(fileName)); + } + getOutliningSpans(fileName: string): ts.OutliningSpan[] { return unwrapJSONCallResult(this.shim.getOutliningSpans(fileName)); } diff --git a/src/server/client.ts b/src/server/client.ts index ca2d517701f..3cf77fa7547 100644 --- a/src/server/client.ts +++ b/src/server/client.ts @@ -461,7 +461,7 @@ namespace ts.server { return this.lastRenameEntry.locations; } - decodeNavigationBarItems(items: protocol.NavigationBarItem[], fileName: string, lineMap: number[]): NavigationBarItem[] { + private decodeNavigationBarItems(items: protocol.NavigationBarItem[], fileName: string, lineMap: number[]): NavigationBarItem[] { if (!items) { return []; } @@ -470,10 +470,7 @@ namespace ts.server { text: item.text, kind: item.kind, kindModifiers: item.kindModifiers || "", - spans: item.spans.map(span => - createTextSpanFromBounds( - this.lineOffsetToPosition(fileName, span.start, lineMap), - this.lineOffsetToPosition(fileName, span.end, lineMap))), + spans: item.spans.map(span => this.decodeSpan(span, fileName, lineMap)), childItems: this.decodeNavigationBarItems(item.childItems, fileName, lineMap), indent: item.indent, bolded: false, @@ -482,17 +479,37 @@ namespace ts.server { } getNavigationBarItems(fileName: string): NavigationBarItem[] { - const args: protocol.FileRequestArgs = { - file: fileName - }; - - const request = this.processRequest(CommandNames.NavBar, args); + const request = this.processRequest(CommandNames.NavBar, { file: fileName }); const response = this.processResponse(request); const lineMap = this.getLineMap(fileName); return this.decodeNavigationBarItems(response.body, fileName, lineMap); } + private decodeNavigationTree(tree: protocol.NavigationTree, fileName: string, lineMap: number[]): NavigationTree { + return { + text: tree.text, + kind: tree.kind, + kindModifiers: tree.kindModifiers, + spans: tree.spans.map(span => this.decodeSpan(span, fileName, lineMap)), + childItems: map(tree.childItems, item => this.decodeNavigationTree(item, fileName, lineMap)) + }; + } + + getNavigationTree(fileName: string): NavigationTree { + const request = this.processRequest(CommandNames.NavTree, { file: fileName }); + const response = this.processResponse(request); + + const lineMap = this.getLineMap(fileName); + return this.decodeNavigationTree(response.body, fileName, lineMap); + } + + private decodeSpan(span: protocol.TextSpan, fileName: string, lineMap: number[]) { + return createTextSpanFromBounds( + this.lineOffsetToPosition(fileName, span.start, lineMap), + this.lineOffsetToPosition(fileName, span.end, lineMap)); + } + getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan { throw new Error("Not Implemented Yet."); } diff --git a/src/server/protocol.d.ts b/src/server/protocol.d.ts index a53d227f379..5550ff772aa 100644 --- a/src/server/protocol.d.ts +++ b/src/server/protocol.d.ts @@ -110,7 +110,7 @@ declare namespace ts.server.protocol { */ export interface TodoCommentRequestArgs extends FileRequestArgs { /** - * Array of target TodoCommentDescriptors that describes TODO comments to be found + * Array of target TodoCommentDescriptors that describes TODO comments to be found */ descriptors: TodoCommentDescriptor[]; } @@ -231,7 +231,7 @@ declare namespace ts.server.protocol { offset?: number; /** - * Position (can be specified instead of line/offset pair) + * Position (can be specified instead of line/offset pair) */ position?: number; } @@ -569,12 +569,12 @@ declare namespace ts.server.protocol { /** * Represents a file in external project. - * External project is project whose set of files, compilation options and open\close state + * External project is project whose set of files, compilation options and open\close state * is maintained by the client (i.e. if all this data come from .csproj file in Visual Studio). * External project will exist even if all files in it are closed and should be closed explicity. - * If external project includes one or more tsconfig.json/jsconfig.json files then tsserver will + * If external project includes one or more tsconfig.json/jsconfig.json files then tsserver will * create configured project for every config file but will maintain a link that these projects were created - * as a result of opening external project so they should be removed once external project is closed. + * as a result of opening external project so they should be removed once external project is closed. */ export interface ExternalFile { /** @@ -985,7 +985,7 @@ declare namespace ts.server.protocol { } /** - * Response for CompileOnSaveAffectedFileListRequest request; + * Response for CompileOnSaveAffectedFileListRequest request; */ export interface CompileOnSaveAffectedFileListResponse extends Response { body: CompileOnSaveAffectedFileListSingleProject[]; @@ -1725,6 +1725,13 @@ declare namespace ts.server.protocol { export interface NavBarRequest extends FileRequest { } + /** + * NavTree request; value of command field is "navtree". + * Return response giving the navigation tree of the requested file. + */ + export interface NavTreeRequest extends FileRequest { + } + export interface NavigationBarItem { /** * The item's display text. @@ -1757,7 +1764,20 @@ declare namespace ts.server.protocol { indent: number; } + /** protocol.NavigationTree is identical to ts.NavigationTree, except using protocol.TextSpan instead of ts.TextSpan */ + export interface NavigationTree { + text: string; + kind: string; + kindModifiers: string; + spans: TextSpan[]; + childItems?: NavigationTree[]; + } + export interface NavBarResponse extends Response { body?: NavigationBarItem[]; } + + export interface NavTreeResponse extends Response { + body?: NavigationTree; + } } diff --git a/src/server/scriptInfo.ts b/src/server/scriptInfo.ts index 410382a9ca4..ee5122ff4e1 100644 --- a/src/server/scriptInfo.ts +++ b/src/server/scriptInfo.ts @@ -4,7 +4,7 @@ namespace ts.server { export class ScriptInfo { /** - * All projects that include this file + * All projects that include this file */ readonly containingProjects: Project[] = []; private formatCodeSettings: ts.FormatCodeSettings; diff --git a/src/server/session.ts b/src/server/session.ts index 8ffd5e09601..469b595905d 100644 --- a/src/server/session.ts +++ b/src/server/session.ts @@ -96,6 +96,8 @@ namespace ts.server { export const SyntacticDiagnosticsSync = "syntacticDiagnosticsSync"; export const NavBar = "navbar"; export const NavBarFull = "navbar-full"; + export const NavTree = "navtree"; + export const NavTreeFull = "navtree-full"; export const Navto = "navto"; export const NavtoFull = "navto-full"; export const Occurrences = "occurrences"; @@ -525,7 +527,7 @@ namespace ts.server { const scriptInfo = this.projectService.getScriptInfo(args.file); projects = scriptInfo.containingProjects; } - // ts.filter handles case when 'projects' is undefined + // ts.filter handles case when 'projects' is undefined projects = filter(projects, p => p.languageServiceEnabled); if (!projects || !projects.length) { return Errors.ThrowNoProject(); @@ -919,15 +921,8 @@ namespace ts.server { return completions.entries.reduce((result: protocol.CompletionEntry[], entry: ts.CompletionEntry) => { if (completions.isMemberCompletion || (entry.name.toLowerCase().indexOf(prefix.toLowerCase()) === 0)) { const { name, kind, kindModifiers, sortText, replacementSpan } = entry; - - let convertedSpan: protocol.TextSpan = undefined; - if (replacementSpan) { - convertedSpan = { - start: scriptInfo.positionToLineOffset(replacementSpan.start), - end: scriptInfo.positionToLineOffset(replacementSpan.start + replacementSpan.length) - }; - } - + const convertedSpan: protocol.TextSpan = + replacementSpan ? this.decorateSpan(replacementSpan, scriptInfo) : undefined; result.push({ name, kind, kindModifiers, sortText, replacementSpan: convertedSpan }); } return result; @@ -1065,38 +1060,54 @@ namespace ts.server { this.projectService.closeClientFile(file); } - private decorateNavigationBarItem(project: Project, fileName: NormalizedPath, items: ts.NavigationBarItem[]): protocol.NavigationBarItem[] { - if (!items) { - return undefined; - } - - const scriptInfo = project.getScriptInfoForNormalizedPath(fileName); - - return items.map(item => ({ + private decorateNavigationBarItems(items: ts.NavigationBarItem[], scriptInfo: ScriptInfo): protocol.NavigationBarItem[] { + return map(items, item => ({ text: item.text, kind: item.kind, kindModifiers: item.kindModifiers, - spans: item.spans.map(span => ({ - start: scriptInfo.positionToLineOffset(span.start), - end: scriptInfo.positionToLineOffset(ts.textSpanEnd(span)) - })), - childItems: this.decorateNavigationBarItem(project, fileName, item.childItems), + spans: item.spans.map(span => this.decorateSpan(span, scriptInfo)), + childItems: this.decorateNavigationBarItems(item.childItems, scriptInfo), indent: item.indent })); } private getNavigationBarItems(args: protocol.FileRequestArgs, simplifiedResult: boolean): protocol.NavigationBarItem[] | NavigationBarItem[] { const { file, project } = this.getFileAndProject(args); - const items = project.getLanguageService().getNavigationBarItems(file); - if (!items) { - return undefined; - } - - return simplifiedResult - ? this.decorateNavigationBarItem(project, file, items) + const items = project.getLanguageService(/*ensureSynchronized*/ false).getNavigationBarItems(file); + return !items + ? undefined + : simplifiedResult + ? this.decorateNavigationBarItems(items, project.getScriptInfoForNormalizedPath(file)) : items; } + private decorateNavigationTree(tree: ts.NavigationTree, scriptInfo: ScriptInfo): protocol.NavigationTree { + return { + text: tree.text, + kind: tree.kind, + kindModifiers: tree.kindModifiers, + spans: tree.spans.map(span => this.decorateSpan(span, scriptInfo)), + childItems: map(tree.childItems, item => this.decorateNavigationTree(item, scriptInfo)) + }; + } + + private decorateSpan(span: TextSpan, scriptInfo: ScriptInfo): protocol.TextSpan { + return { + start: scriptInfo.positionToLineOffset(span.start), + end: scriptInfo.positionToLineOffset(ts.textSpanEnd(span)) + }; + } + + private getNavigationTree(args: protocol.FileRequestArgs, simplifiedResult: boolean): protocol.NavigationTree | NavigationTree { + const { file, project } = this.getFileAndProject(args); + const tree = project.getLanguageService(/*ensureSynchronized*/ false).getNavigationTree(file); + return !tree + ? undefined + : simplifiedResult + ? this.decorateNavigationTree(tree, project.getScriptInfoForNormalizedPath(file)) + : tree; + } + private getNavigateToItems(args: protocol.NavtoRequestArgs, simplifiedResult: boolean): protocol.NavtoItem[] | NavigateToItem[] { const projects = this.getProjects(args); @@ -1183,19 +1194,11 @@ namespace ts.server { const position = this.getPosition(args, scriptInfo); const spans = project.getLanguageService(/*ensureSynchronized*/ false).getBraceMatchingAtPosition(file, position); - if (!spans) { - return undefined; - } - if (simplifiedResult) { - - return spans.map(span => ({ - start: scriptInfo.positionToLineOffset(span.start), - end: scriptInfo.positionToLineOffset(span.start + span.length) - })); - } - else { - return spans; - } + return !spans + ? undefined + : simplifiedResult + ? spans.map(span => this.decorateSpan(span, scriptInfo)) + : spans; } getDiagnosticsForProject(delay: number, fileName: string) { @@ -1474,6 +1477,12 @@ namespace ts.server { [CommandNames.NavBarFull]: (request: protocol.FileRequest) => { return this.requiredResponse(this.getNavigationBarItems(request.arguments, /*simplifiedResult*/ false)); }, + [CommandNames.NavTree]: (request: protocol.FileRequest) => { + return this.requiredResponse(this.getNavigationTree(request.arguments, /*simplifiedResult*/ true)); + }, + [CommandNames.NavTreeFull]: (request: protocol.FileRequest) => { + return this.requiredResponse(this.getNavigationTree(request.arguments, /*simplifiedResult*/ false)); + }, [CommandNames.Occurrences]: (request: protocol.FileLocationRequest) => { return this.requiredResponse(this.getOccurrences(request.arguments)); }, diff --git a/src/server/utilities.ts b/src/server/utilities.ts index 69962fa186e..f75341b604e 100644 --- a/src/server/utilities.ts +++ b/src/server/utilities.ts @@ -157,48 +157,49 @@ namespace ts.server { } }; } - function throwLanguageServiceIsDisabledError() { + function throwLanguageServiceIsDisabledError(): never { throw new Error("LanguageService is disabled"); } export const nullLanguageService: LanguageService = { - cleanupSemanticCache: (): any => throwLanguageServiceIsDisabledError(), - getSyntacticDiagnostics: (): any => throwLanguageServiceIsDisabledError(), - getSemanticDiagnostics: (): any => throwLanguageServiceIsDisabledError(), - getCompilerOptionsDiagnostics: (): any => throwLanguageServiceIsDisabledError(), - getSyntacticClassifications: (): any => throwLanguageServiceIsDisabledError(), - getEncodedSyntacticClassifications: (): any => throwLanguageServiceIsDisabledError(), - getSemanticClassifications: (): any => throwLanguageServiceIsDisabledError(), - getEncodedSemanticClassifications: (): any => throwLanguageServiceIsDisabledError(), - getCompletionsAtPosition: (): any => throwLanguageServiceIsDisabledError(), - findReferences: (): any => throwLanguageServiceIsDisabledError(), - getCompletionEntryDetails: (): any => throwLanguageServiceIsDisabledError(), - getQuickInfoAtPosition: (): any => throwLanguageServiceIsDisabledError(), - findRenameLocations: (): any => throwLanguageServiceIsDisabledError(), - getNameOrDottedNameSpan: (): any => throwLanguageServiceIsDisabledError(), - getBreakpointStatementAtPosition: (): any => throwLanguageServiceIsDisabledError(), - getBraceMatchingAtPosition: (): any => throwLanguageServiceIsDisabledError(), - getSignatureHelpItems: (): any => throwLanguageServiceIsDisabledError(), - getDefinitionAtPosition: (): any => throwLanguageServiceIsDisabledError(), - getRenameInfo: (): any => throwLanguageServiceIsDisabledError(), - getTypeDefinitionAtPosition: (): any => throwLanguageServiceIsDisabledError(), - getReferencesAtPosition: (): any => throwLanguageServiceIsDisabledError(), - getDocumentHighlights: (): any => throwLanguageServiceIsDisabledError(), - getOccurrencesAtPosition: (): any => throwLanguageServiceIsDisabledError(), - getNavigateToItems: (): any => throwLanguageServiceIsDisabledError(), - getNavigationBarItems: (): any => throwLanguageServiceIsDisabledError(), - getOutliningSpans: (): any => throwLanguageServiceIsDisabledError(), - getTodoComments: (): any => throwLanguageServiceIsDisabledError(), - getIndentationAtPosition: (): any => throwLanguageServiceIsDisabledError(), - getFormattingEditsForRange: (): any => throwLanguageServiceIsDisabledError(), - getFormattingEditsForDocument: (): any => throwLanguageServiceIsDisabledError(), - getFormattingEditsAfterKeystroke: (): any => throwLanguageServiceIsDisabledError(), - getDocCommentTemplateAtPosition: (): any => throwLanguageServiceIsDisabledError(), - isValidBraceCompletionAtPosition: (): any => throwLanguageServiceIsDisabledError(), - getEmitOutput: (): any => throwLanguageServiceIsDisabledError(), - getProgram: (): any => throwLanguageServiceIsDisabledError(), - getNonBoundSourceFile: (): any => throwLanguageServiceIsDisabledError(), - dispose: (): any => throwLanguageServiceIsDisabledError(), + cleanupSemanticCache: throwLanguageServiceIsDisabledError, + getSyntacticDiagnostics: throwLanguageServiceIsDisabledError, + getSemanticDiagnostics: throwLanguageServiceIsDisabledError, + getCompilerOptionsDiagnostics: throwLanguageServiceIsDisabledError, + getSyntacticClassifications: throwLanguageServiceIsDisabledError, + getEncodedSyntacticClassifications: throwLanguageServiceIsDisabledError, + getSemanticClassifications: throwLanguageServiceIsDisabledError, + getEncodedSemanticClassifications: throwLanguageServiceIsDisabledError, + getCompletionsAtPosition: throwLanguageServiceIsDisabledError, + findReferences: throwLanguageServiceIsDisabledError, + getCompletionEntryDetails: throwLanguageServiceIsDisabledError, + getQuickInfoAtPosition: throwLanguageServiceIsDisabledError, + findRenameLocations: throwLanguageServiceIsDisabledError, + getNameOrDottedNameSpan: throwLanguageServiceIsDisabledError, + getBreakpointStatementAtPosition: throwLanguageServiceIsDisabledError, + getBraceMatchingAtPosition: throwLanguageServiceIsDisabledError, + getSignatureHelpItems: throwLanguageServiceIsDisabledError, + getDefinitionAtPosition: throwLanguageServiceIsDisabledError, + getRenameInfo: throwLanguageServiceIsDisabledError, + getTypeDefinitionAtPosition: throwLanguageServiceIsDisabledError, + getReferencesAtPosition: throwLanguageServiceIsDisabledError, + getDocumentHighlights: throwLanguageServiceIsDisabledError, + getOccurrencesAtPosition: throwLanguageServiceIsDisabledError, + getNavigateToItems: throwLanguageServiceIsDisabledError, + getNavigationBarItems: throwLanguageServiceIsDisabledError, + getNavigationTree: throwLanguageServiceIsDisabledError, + getOutliningSpans: throwLanguageServiceIsDisabledError, + getTodoComments: throwLanguageServiceIsDisabledError, + getIndentationAtPosition: throwLanguageServiceIsDisabledError, + getFormattingEditsForRange: throwLanguageServiceIsDisabledError, + getFormattingEditsForDocument: throwLanguageServiceIsDisabledError, + getFormattingEditsAfterKeystroke: throwLanguageServiceIsDisabledError, + getDocCommentTemplateAtPosition: throwLanguageServiceIsDisabledError, + isValidBraceCompletionAtPosition: throwLanguageServiceIsDisabledError, + getEmitOutput: throwLanguageServiceIsDisabledError, + getProgram: throwLanguageServiceIsDisabledError, + getNonBoundSourceFile: throwLanguageServiceIsDisabledError, + dispose: throwLanguageServiceIsDisabledError, }; export interface ServerLanguageServiceHost { @@ -245,7 +246,7 @@ namespace ts.server { // another operation was already scheduled for this id - cancel it this.host.clearTimeout(this.pendingTimeouts[operationId]); } - // schedule new operation, pass arguments + // schedule new operation, pass arguments this.pendingTimeouts[operationId] = this.host.setTimeout(ThrottledOperations.run, delay, this, operationId, cb); } diff --git a/src/services/navigationBar.ts b/src/services/navigationBar.ts index a4746f15691..46fcaf452dd 100644 --- a/src/services/navigationBar.ts +++ b/src/services/navigationBar.ts @@ -21,6 +21,13 @@ namespace ts.NavigationBar { return result; } + export function getNavigationTree(sourceFile: SourceFile): NavigationTree { + curSourceFile = sourceFile; + const result = convertToTree(rootNavigationBarNode(sourceFile)); + curSourceFile = undefined; + return result; + } + // Keep sourceFile handy so we don't have to search for it every time we need to call `getText`. let curSourceFile: SourceFile; function nodeText(node: Node): string { @@ -503,6 +510,16 @@ namespace ts.NavigationBar { // NavigationBarItem requires an array, but will not mutate it, so just give it this for performance. const emptyChildItemArray: NavigationBarItem[] = []; + function convertToTree(n: NavigationBarNode): NavigationTree { + return { + text: getItemName(n.node), + kind: getNodeKind(n.node), + kindModifiers: getNodeModifiers(n.node), + spans: getSpans(n), + childItems: map(n.children, convertToTree) + }; + } + function convertToTopLevelItem(n: NavigationBarNode): NavigationBarItem { return { text: getItemName(n.node), @@ -527,16 +544,16 @@ namespace ts.NavigationBar { grayed: false }; } + } - function getSpans(n: NavigationBarNode): TextSpan[] { - const spans = [getNodeSpan(n.node)]; - if (n.additionalNodes) { - for (const node of n.additionalNodes) { - spans.push(getNodeSpan(node)); - } + function getSpans(n: NavigationBarNode): TextSpan[] { + const spans = [getNodeSpan(n.node)]; + if (n.additionalNodes) { + for (const node of n.additionalNodes) { + spans.push(getNodeSpan(node)); } - return spans; } + return spans; } function getModuleName(moduleDeclaration: ModuleDeclaration): string { diff --git a/src/services/services.ts b/src/services/services.ts index bcd2f3d5c9b..1f3366763e8 100644 --- a/src/services/services.ts +++ b/src/services/services.ts @@ -1260,6 +1260,7 @@ namespace ts { getNavigateToItems(searchValue: string, maxResultCount?: number, excludeDts?: boolean): NavigateToItem[]; getNavigationBarItems(fileName: string): NavigationBarItem[]; + getNavigationTree(fileName: string): NavigationTree; getOutliningSpans(fileName: string): OutliningSpan[]; getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; @@ -1293,6 +1294,12 @@ namespace ts { classificationType: string; // ClassificationTypeNames } + /** + * Navigation bar interface designed for visual studio's dual-column layout. + * This does not form a proper tree. + * The navbar is returned as a list of top-level items, each of which has a list of child items. + * Child items always have an empty array for their `childItems`. + */ export interface NavigationBarItem { text: string; kind: string; @@ -1304,6 +1311,26 @@ namespace ts { grayed: boolean; } + /** + * Node in a tree of nested declarations in a file. + * The top node is always a script or module node. + */ + export interface NavigationTree { + /** Name of the declaration, or a short description, e.g. "". */ + text: string; + /** A ScriptElementKind */ + kind: string; + /** ScriptElementKindModifier separated by commas, e.g. "public,abstract" */ + kindModifiers: string; + /** + * Spans of the nodes that generated this declaration. + * There will be more than one if this is the result of merging. + */ + spans: TextSpan[]; + /** Present if non-empty */ + childItems?: NavigationTree[]; + } + export interface TodoCommentDescriptor { text: string; priority: number; @@ -7875,9 +7902,11 @@ namespace ts { } function getNavigationBarItems(fileName: string): NavigationBarItem[] { - const sourceFile = syntaxTreeCache.getCurrentSourceFile(fileName); + return NavigationBar.getNavigationBarItems(syntaxTreeCache.getCurrentSourceFile(fileName)); + } - return NavigationBar.getNavigationBarItems(sourceFile); + function getNavigationTree(fileName: string): NavigationTree { + return NavigationBar.getNavigationTree(syntaxTreeCache.getCurrentSourceFile(fileName)); } function getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[] { @@ -8967,6 +8996,7 @@ namespace ts { getRenameInfo, findRenameLocations, getNavigationBarItems, + getNavigationTree, getOutliningSpans, getTodoComments, getBraceMatchingAtPosition, diff --git a/src/services/shims.ts b/src/services/shims.ts index f2ee5b44090..ffdb53ef43f 100644 --- a/src/services/shims.ts +++ b/src/services/shims.ts @@ -218,6 +218,9 @@ namespace ts { */ getNavigationBarItems(fileName: string): string; + /** Returns a JSON-encoded value of the type ts.NavigationTree. */ + getNavigationTree(fileName: string): string; + /** * Returns a JSON-encoded value of the type: * { textSpan: { start: number, length: number }; hintSpan: { start: number, length: number }; bannerText: string; autoCollapse: boolean } [] = []; @@ -937,6 +940,13 @@ namespace ts { ); } + public getNavigationTree(fileName: string): string { + return this.forwardJSONCall( + `getNavigationTree('${fileName}')`, + () => this.languageService.getNavigationTree(fileName) + ); + } + public getOutliningSpans(fileName: string): string { return this.forwardJSONCall( `getOutliningSpans('${fileName}')`, diff --git a/src/services/types.ts b/src/services/types.ts new file mode 100644 index 00000000000..bcb87774901 --- /dev/null +++ b/src/services/types.ts @@ -0,0 +1,814 @@ +namespace ts { + export interface Node { + getSourceFile(): SourceFile; + getChildCount(sourceFile?: SourceFile): number; + getChildAt(index: number, sourceFile?: SourceFile): Node; + getChildren(sourceFile?: SourceFile): Node[]; + getStart(sourceFile?: SourceFile, includeJsDocComment?: boolean): number; + getFullStart(): number; + getEnd(): number; + getWidth(sourceFile?: SourceFile): number; + getFullWidth(): number; + getLeadingTriviaWidth(sourceFile?: SourceFile): number; + getFullText(sourceFile?: SourceFile): string; + getText(sourceFile?: SourceFile): string; + getFirstToken(sourceFile?: SourceFile): Node; + getLastToken(sourceFile?: SourceFile): Node; + } + + export interface Symbol { + getFlags(): SymbolFlags; + getName(): string; + getDeclarations(): Declaration[]; + getDocumentationComment(): SymbolDisplayPart[]; + } + + export interface Type { + getFlags(): TypeFlags; + getSymbol(): Symbol; + getProperties(): Symbol[]; + getProperty(propertyName: string): Symbol; + getApparentProperties(): Symbol[]; + getCallSignatures(): Signature[]; + getConstructSignatures(): Signature[]; + getStringIndexType(): Type; + getNumberIndexType(): Type; + getBaseTypes(): ObjectType[]; + getNonNullableType(): Type; + } + + export interface Signature { + getDeclaration(): SignatureDeclaration; + getTypeParameters(): Type[]; + getParameters(): Symbol[]; + getReturnType(): Type; + getDocumentationComment(): SymbolDisplayPart[]; + } + + export interface SourceFile { + /* @internal */ version: string; + /* @internal */ scriptSnapshot: IScriptSnapshot; + /* @internal */ nameTable: Map; + + /* @internal */ getNamedDeclarations(): Map; + + getLineAndCharacterOfPosition(pos: number): LineAndCharacter; + getLineStarts(): number[]; + getPositionOfLineAndCharacter(line: number, character: number): number; + update(newText: string, textChangeRange: TextChangeRange): SourceFile; + } + + /** + * Represents an immutable snapshot of a script at a specified time.Once acquired, the + * snapshot is observably immutable. i.e. the same calls with the same parameters will return + * the same values. + */ + export interface IScriptSnapshot { + /** Gets a portion of the script snapshot specified by [start, end). */ + getText(start: number, end: number): string; + + /** Gets the length of this script snapshot. */ + getLength(): number; + + /** + * Gets the TextChangeRange that describe how the text changed between this text and + * an older version. This information is used by the incremental parser to determine + * what sections of the script need to be re-parsed. 'undefined' can be returned if the + * change range cannot be determined. However, in that case, incremental parsing will + * not happen and the entire document will be re - parsed. + */ + getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange | undefined; + + /** Releases all resources held by this script snapshot */ + dispose?(): void; + } + + export namespace ScriptSnapshot { + class StringScriptSnapshot implements IScriptSnapshot { + + constructor(private text: string) { + } + + public getText(start: number, end: number): string { + return this.text.substring(start, end); + } + + public getLength(): number { + return this.text.length; + } + + public getChangeRange(oldSnapshot: IScriptSnapshot): TextChangeRange { + // Text-based snapshots do not support incremental parsing. Return undefined + // to signal that to the caller. + return undefined; + } + } + + export function fromString(text: string): IScriptSnapshot { + return new StringScriptSnapshot(text); + } + } + export interface PreProcessedFileInfo { + referencedFiles: FileReference[]; + typeReferenceDirectives: FileReference[]; + importedFiles: FileReference[]; + ambientExternalModules: string[]; + isLibFile: boolean; + } + + export interface HostCancellationToken { + isCancellationRequested(): boolean; + } + + // + // Public interface of the host of a language service instance. + // + export interface LanguageServiceHost { + getCompilationSettings(): CompilerOptions; + getNewLine?(): string; + getProjectVersion?(): string; + getScriptFileNames(): string[]; + getScriptKind?(fileName: string): ScriptKind; + getScriptVersion(fileName: string): string; + getScriptSnapshot(fileName: string): IScriptSnapshot | undefined; + getLocalizedDiagnosticMessages?(): any; + getCancellationToken?(): HostCancellationToken; + getCurrentDirectory(): string; + getDefaultLibFileName(options: CompilerOptions): string; + log?(s: string): void; + trace?(s: string): void; + error?(s: string): void; + useCaseSensitiveFileNames?(): boolean; + + /* + * LS host can optionally implement these methods to support completions for module specifiers. + * Without these methods, only completions for ambient modules will be provided. + */ + readDirectory?(path: string, extensions?: string[], exclude?: string[], include?: string[]): string[]; + readFile?(path: string, encoding?: string): string; + fileExists?(path: string): boolean; + + /* + * LS host can optionally implement these methods to support automatic updating when new type libraries are installed + */ + getTypeRootsVersion?(): number; + + /* + * LS host can optionally implement this method if it wants to be completely in charge of module name resolution. + * if implementation is omitted then language service will use built-in module resolution logic and get answers to + * host specific questions using 'getScriptSnapshot'. + */ + resolveModuleNames?(moduleNames: string[], containingFile: string): ResolvedModule[]; + resolveTypeReferenceDirectives?(typeDirectiveNames: string[], containingFile: string): ResolvedTypeReferenceDirective[]; + directoryExists?(directoryName: string): boolean; + + /* + * getDirectories is also required for full import and type reference completions. Without it defined, certain + * completions will not be provided + */ + getDirectories?(directoryName: string): string[]; + } + + // + // Public services of a language service instance associated + // with a language service host instance + // + export interface LanguageService { + cleanupSemanticCache(): void; + + getSyntacticDiagnostics(fileName: string): Diagnostic[]; + getSemanticDiagnostics(fileName: string): Diagnostic[]; + + // TODO: Rename this to getProgramDiagnostics to better indicate that these are any + // diagnostics present for the program level, and not just 'options' diagnostics. + getCompilerOptionsDiagnostics(): Diagnostic[]; + + /** + * @deprecated Use getEncodedSyntacticClassifications instead. + */ + getSyntacticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[]; + + /** + * @deprecated Use getEncodedSemanticClassifications instead. + */ + getSemanticClassifications(fileName: string, span: TextSpan): ClassifiedSpan[]; + + // Encoded as triples of [start, length, ClassificationType]. + getEncodedSyntacticClassifications(fileName: string, span: TextSpan): Classifications; + getEncodedSemanticClassifications(fileName: string, span: TextSpan): Classifications; + + getCompletionsAtPosition(fileName: string, position: number): CompletionInfo; + getCompletionEntryDetails(fileName: string, position: number, entryName: string): CompletionEntryDetails; + getCompletionEntrySymbol(fileName: string, position: number, entryName: string): Symbol; + + getQuickInfoAtPosition(fileName: string, position: number): QuickInfo; + + getNameOrDottedNameSpan(fileName: string, startPos: number, endPos: number): TextSpan; + + getBreakpointStatementAtPosition(fileName: string, position: number): TextSpan; + + getSignatureHelpItems(fileName: string, position: number): SignatureHelpItems; + + getRenameInfo(fileName: string, position: number): RenameInfo; + findRenameLocations(fileName: string, position: number, findInStrings: boolean, findInComments: boolean): RenameLocation[]; + + getDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; + getTypeDefinitionAtPosition(fileName: string, position: number): DefinitionInfo[]; + getImplementationAtPosition(fileName: string, position: number): ImplementationLocation[]; + + getReferencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + findReferences(fileName: string, position: number): ReferencedSymbol[]; + getDocumentHighlights(fileName: string, position: number, filesToSearch: string[]): DocumentHighlights[]; + + /** @deprecated */ + getOccurrencesAtPosition(fileName: string, position: number): ReferenceEntry[]; + + getNavigateToItems(searchValue: string, maxResultCount?: number, fileName?: string, excludeDtsFiles?: boolean): NavigateToItem[]; + getNavigationBarItems(fileName: string): NavigationBarItem[]; + getNavigationTree(fileName: string): NavigationTree; + + getOutliningSpans(fileName: string): OutliningSpan[]; + getTodoComments(fileName: string, descriptors: TodoCommentDescriptor[]): TodoComment[]; + getBraceMatchingAtPosition(fileName: string, position: number): TextSpan[]; + getIndentationAtPosition(fileName: string, position: number, options: EditorOptions | EditorSettings): number; + + getFormattingEditsForRange(fileName: string, start: number, end: number, options: FormatCodeOptions | FormatCodeSettings): TextChange[]; + getFormattingEditsForDocument(fileName: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[]; + getFormattingEditsAfterKeystroke(fileName: string, position: number, key: string, options: FormatCodeOptions | FormatCodeSettings): TextChange[]; + + getDocCommentTemplateAtPosition(fileName: string, position: number): TextInsertion; + + isValidBraceCompletionAtPosition(fileName: string, position: number, openingBrace: number): boolean; + + getEmitOutput(fileName: string, emitOnlyDtsFiles?: boolean): EmitOutput; + + getProgram(): Program; + + /* @internal */ getNonBoundSourceFile(fileName: string): SourceFile; + + /** + * @internal + * @deprecated Use ts.createSourceFile instead. + */ + getSourceFile(fileName: string): SourceFile; + + dispose(): void; + } + + export interface Classifications { + spans: number[]; + endOfLineState: EndOfLineState; + } + + export interface ClassifiedSpan { + textSpan: TextSpan; + classificationType: string; // ClassificationTypeNames + } + + /** + * Navigation bar interface designed for visual studio's dual-column layout. + * This does not form a proper tree. + * The navbar is returned as a list of top-level items, each of which has a list of child items. + * Child items always have an empty array for their `childItems`. + */ + export interface NavigationBarItem { + text: string; + kind: string; + kindModifiers: string; + spans: TextSpan[]; + childItems: NavigationBarItem[]; + indent: number; + bolded: boolean; + grayed: boolean; + } + + /** + * Node in a tree of nested declarations in a file. + * The top node is always a script or module node. + */ + export interface NavigationTree { + /** Name of the declaration, or a short description, e.g. "". */ + text: string; + /** A ScriptElementKind */ + kind: string; + /** ScriptElementKindModifier separated by commas, e.g. "public,abstract" */ + kindModifiers: string; + /** + * Spans of the nodes that generated this declaration. + * There will be more than one if this is the result of merging. + */ + spans: TextSpan[]; + /** Present if non-empty */ + childItems?: NavigationTree[]; + } + + export interface TodoCommentDescriptor { + text: string; + priority: number; + } + + export interface TodoComment { + descriptor: TodoCommentDescriptor; + message: string; + position: number; + } + + export class TextChange { + span: TextSpan; + newText: string; + } + + export interface TextInsertion { + newText: string; + /** The position in newText the caret should point to after the insertion. */ + caretOffset: number; + } + + export interface RenameLocation { + textSpan: TextSpan; + fileName: string; + } + + export interface ReferenceEntry { + textSpan: TextSpan; + fileName: string; + isWriteAccess: boolean; + isDefinition: boolean; + } + + export interface ImplementationLocation { + textSpan: TextSpan; + fileName: string; + } + + export interface DocumentHighlights { + fileName: string; + highlightSpans: HighlightSpan[]; + } + + export namespace HighlightSpanKind { + export const none = "none"; + export const definition = "definition"; + export const reference = "reference"; + export const writtenReference = "writtenReference"; + } + + export interface HighlightSpan { + fileName?: string; + textSpan: TextSpan; + kind: string; + } + + export interface NavigateToItem { + name: string; + kind: string; + kindModifiers: string; + matchKind: string; + isCaseSensitive: boolean; + fileName: string; + textSpan: TextSpan; + containerName: string; + containerKind: string; + } + + export enum IndentStyle { + None = 0, + Block = 1, + Smart = 2, + } + + /* @deprecated - consider using EditorSettings instead */ + export interface EditorOptions { + BaseIndentSize?: number; + IndentSize: number; + TabSize: number; + NewLineCharacter: string; + ConvertTabsToSpaces: boolean; + IndentStyle: IndentStyle; + } + + export interface EditorSettings { + baseIndentSize?: number; + indentSize: number; + tabSize: number; + newLineCharacter: string; + convertTabsToSpaces: boolean; + indentStyle: IndentStyle; + } + + /* @deprecated - consider using FormatCodeSettings instead */ + export interface FormatCodeOptions extends EditorOptions { + InsertSpaceAfterCommaDelimiter: boolean; + InsertSpaceAfterSemicolonInForStatements: boolean; + InsertSpaceBeforeAndAfterBinaryOperators: boolean; + InsertSpaceAfterKeywordsInControlFlowStatements: boolean; + InsertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean; + InsertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; + InsertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean; + InsertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean; + InsertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; + InsertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces?: boolean; + InsertSpaceAfterTypeAssertion?: boolean; + PlaceOpenBraceOnNewLineForFunctions: boolean; + PlaceOpenBraceOnNewLineForControlBlocks: boolean; + } + + export interface FormatCodeSettings extends EditorSettings { + insertSpaceAfterCommaDelimiter: boolean; + insertSpaceAfterSemicolonInForStatements: boolean; + insertSpaceBeforeAndAfterBinaryOperators: boolean; + insertSpaceAfterKeywordsInControlFlowStatements: boolean; + insertSpaceAfterFunctionKeywordForAnonymousFunctions: boolean; + insertSpaceAfterOpeningAndBeforeClosingNonemptyParenthesis: boolean; + insertSpaceAfterOpeningAndBeforeClosingNonemptyBrackets: boolean; + insertSpaceAfterOpeningAndBeforeClosingNonemptyBraces?: boolean; + insertSpaceAfterOpeningAndBeforeClosingTemplateStringBraces: boolean; + insertSpaceAfterOpeningAndBeforeClosingJsxExpressionBraces: boolean; + insertSpaceAfterTypeAssertion?: boolean; + placeOpenBraceOnNewLineForFunctions: boolean; + placeOpenBraceOnNewLineForControlBlocks: boolean; + } + + export interface DefinitionInfo { + fileName: string; + textSpan: TextSpan; + kind: string; + name: string; + containerKind: string; + containerName: string; + } + + export interface ReferencedSymbolDefinitionInfo extends DefinitionInfo { + displayParts: SymbolDisplayPart[]; + } + + export interface ReferencedSymbol { + definition: ReferencedSymbolDefinitionInfo; + references: ReferenceEntry[]; + } + + export enum SymbolDisplayPartKind { + aliasName, + className, + enumName, + fieldName, + interfaceName, + keyword, + lineBreak, + numericLiteral, + stringLiteral, + localName, + methodName, + moduleName, + operator, + parameterName, + propertyName, + punctuation, + space, + text, + typeParameterName, + enumMemberName, + functionName, + regularExpressionLiteral, + } + + export interface SymbolDisplayPart { + text: string; + kind: string; + } + + export interface QuickInfo { + kind: string; + kindModifiers: string; + textSpan: TextSpan; + displayParts: SymbolDisplayPart[]; + documentation: SymbolDisplayPart[]; + } + + export interface RenameInfo { + canRename: boolean; + localizedErrorMessage: string; + displayName: string; + fullDisplayName: string; + kind: string; + kindModifiers: string; + triggerSpan: TextSpan; + } + + export interface SignatureHelpParameter { + name: string; + documentation: SymbolDisplayPart[]; + displayParts: SymbolDisplayPart[]; + isOptional: boolean; + } + + /** + * Represents a single signature to show in signature help. + * The id is used for subsequent calls into the language service to ask questions about the + * signature help item in the context of any documents that have been updated. i.e. after + * an edit has happened, while signature help is still active, the host can ask important + * questions like 'what parameter is the user currently contained within?'. + */ + export interface SignatureHelpItem { + isVariadic: boolean; + prefixDisplayParts: SymbolDisplayPart[]; + suffixDisplayParts: SymbolDisplayPart[]; + separatorDisplayParts: SymbolDisplayPart[]; + parameters: SignatureHelpParameter[]; + documentation: SymbolDisplayPart[]; + } + + /** + * Represents a set of signature help items, and the preferred item that should be selected. + */ + export interface SignatureHelpItems { + items: SignatureHelpItem[]; + applicableSpan: TextSpan; + selectedItemIndex: number; + argumentIndex: number; + argumentCount: number; + } + + export interface CompletionInfo { + isGlobalCompletion: boolean; + isMemberCompletion: boolean; + + /** + * true when the current location also allows for a new identifier + */ + isNewIdentifierLocation: boolean; + entries: CompletionEntry[]; + } + + export interface CompletionEntry { + name: string; + kind: string; // see ScriptElementKind + kindModifiers: string; // see ScriptElementKindModifier, comma separated + sortText: string; + /** + * An optional span that indicates the text to be replaced by this completion item. It will be + * set if the required span differs from the one generated by the default replacement behavior and should + * be used in that case + */ + replacementSpan?: TextSpan; + } + + export interface CompletionEntryDetails { + name: string; + kind: string; // see ScriptElementKind + kindModifiers: string; // see ScriptElementKindModifier, comma separated + displayParts: SymbolDisplayPart[]; + documentation: SymbolDisplayPart[]; + } + + export interface OutliningSpan { + /** The span of the document to actually collapse. */ + textSpan: TextSpan; + + /** The span of the document to display when the user hovers over the collapsed span. */ + hintSpan: TextSpan; + + /** The text to display in the editor for the collapsed region. */ + bannerText: string; + + /** + * Whether or not this region should be automatically collapsed when + * the 'Collapse to Definitions' command is invoked. + */ + autoCollapse: boolean; + } + + export interface EmitOutput { + outputFiles: OutputFile[]; + emitSkipped: boolean; + } + + export const enum OutputFileType { + JavaScript, + SourceMap, + Declaration + } + + export interface OutputFile { + name: string; + writeByteOrderMark: boolean; + text: string; + } + + export const enum EndOfLineState { + None, + InMultiLineCommentTrivia, + InSingleQuoteStringLiteral, + InDoubleQuoteStringLiteral, + InTemplateHeadOrNoSubstitutionTemplate, + InTemplateMiddleOrTail, + InTemplateSubstitutionPosition, + } + + export enum TokenClass { + Punctuation, + Keyword, + Operator, + Comment, + Whitespace, + Identifier, + NumberLiteral, + StringLiteral, + RegExpLiteral, + } + + export interface ClassificationResult { + finalLexState: EndOfLineState; + entries: ClassificationInfo[]; + } + + export interface ClassificationInfo { + length: number; + classification: TokenClass; + } + + export interface Classifier { + /** + * Gives lexical classifications of tokens on a line without any syntactic context. + * For instance, a token consisting of the text 'string' can be either an identifier + * named 'string' or the keyword 'string', however, because this classifier is not aware, + * it relies on certain heuristics to give acceptable results. For classifications where + * speed trumps accuracy, this function is preferable; however, for true accuracy, the + * syntactic classifier is ideal. In fact, in certain editing scenarios, combining the + * lexical, syntactic, and semantic classifiers may issue the best user experience. + * + * @param text The text of a line to classify. + * @param lexState The state of the lexical classifier at the end of the previous line. + * @param syntacticClassifierAbsent Whether the client is *not* using a syntactic classifier. + * If there is no syntactic classifier (syntacticClassifierAbsent=true), + * certain heuristics may be used in its place; however, if there is a + * syntactic classifier (syntacticClassifierAbsent=false), certain + * classifications which may be incorrectly categorized will be given + * back as Identifiers in order to allow the syntactic classifier to + * subsume the classification. + * @deprecated Use getLexicalClassifications instead. + */ + getClassificationsForLine(text: string, lexState: EndOfLineState, syntacticClassifierAbsent: boolean): ClassificationResult; + getEncodedLexicalClassifications(text: string, endOfLineState: EndOfLineState, syntacticClassifierAbsent: boolean): Classifications; + } + + // TODO: move these to enums + export namespace ScriptElementKind { + export const unknown = ""; + export const warning = "warning"; + + /** predefined type (void) or keyword (class) */ + export const keyword = "keyword"; + + /** top level script node */ + export const scriptElement = "script"; + + /** module foo {} */ + export const moduleElement = "module"; + + /** class X {} */ + export const classElement = "class"; + + /** var x = class X {} */ + export const localClassElement = "local class"; + + /** interface Y {} */ + export const interfaceElement = "interface"; + + /** type T = ... */ + export const typeElement = "type"; + + /** enum E */ + export const enumElement = "enum"; + // TODO: GH#9983 + export const enumMemberElement = "const"; + + /** + * Inside module and script only + * const v = .. + */ + export const variableElement = "var"; + + /** Inside function */ + export const localVariableElement = "local var"; + + /** + * Inside module and script only + * function f() { } + */ + export const functionElement = "function"; + + /** Inside function */ + export const localFunctionElement = "local function"; + + /** class X { [public|private]* foo() {} } */ + export const memberFunctionElement = "method"; + + /** class X { [public|private]* [get|set] foo:number; } */ + export const memberGetAccessorElement = "getter"; + export const memberSetAccessorElement = "setter"; + + /** + * class X { [public|private]* foo:number; } + * interface Y { foo:number; } + */ + export const memberVariableElement = "property"; + + /** class X { constructor() { } } */ + export const constructorImplementationElement = "constructor"; + + /** interface Y { ():number; } */ + export const callSignatureElement = "call"; + + /** interface Y { []:number; } */ + export const indexSignatureElement = "index"; + + /** interface Y { new():Y; } */ + export const constructSignatureElement = "construct"; + + /** function foo(*Y*: string) */ + export const parameterElement = "parameter"; + + export const typeParameterElement = "type parameter"; + + export const primitiveType = "primitive type"; + + export const label = "label"; + + export const alias = "alias"; + + export const constElement = "const"; + + export const letElement = "let"; + + export const directory = "directory"; + + export const externalModuleName = "external module name"; + } + + export namespace ScriptElementKindModifier { + export const none = ""; + export const publicMemberModifier = "public"; + export const privateMemberModifier = "private"; + export const protectedMemberModifier = "protected"; + export const exportedModifier = "export"; + export const ambientModifier = "declare"; + export const staticModifier = "static"; + export const abstractModifier = "abstract"; + } + + export class ClassificationTypeNames { + public static comment = "comment"; + public static identifier = "identifier"; + public static keyword = "keyword"; + public static numericLiteral = "number"; + public static operator = "operator"; + public static stringLiteral = "string"; + public static whiteSpace = "whitespace"; + public static text = "text"; + + public static punctuation = "punctuation"; + + public static className = "class name"; + public static enumName = "enum name"; + public static interfaceName = "interface name"; + public static moduleName = "module name"; + public static typeParameterName = "type parameter name"; + public static typeAliasName = "type alias name"; + public static parameterName = "parameter name"; + public static docCommentTagName = "doc comment tag name"; + public static jsxOpenTagName = "jsx open tag name"; + public static jsxCloseTagName = "jsx close tag name"; + public static jsxSelfClosingTagName = "jsx self closing tag name"; + public static jsxAttribute = "jsx attribute"; + public static jsxText = "jsx text"; + public static jsxAttributeStringLiteralValue = "jsx attribute string literal value"; + } + + export const enum ClassificationType { + comment = 1, + identifier = 2, + keyword = 3, + numericLiteral = 4, + operator = 5, + stringLiteral = 6, + regularExpressionLiteral = 7, + whiteSpace = 8, + text = 9, + punctuation = 10, + className = 11, + enumName = 12, + interfaceName = 13, + moduleName = 14, + typeParameterName = 15, + typeAliasName = 16, + parameterName = 17, + docCommentTagName = 18, + jsxOpenTagName = 19, + jsxCloseTagName = 20, + jsxSelfClosingTagName = 21, + jsxAttribute = 22, + jsxText = 23, + jsxAttributeStringLiteralValue = 24, + } +} diff --git a/tests/cases/fourslash/deleteClassWithEnumPresent.ts b/tests/cases/fourslash/deleteClassWithEnumPresent.ts index eb40a27bcd7..8914e0020a0 100644 --- a/tests/cases/fourslash/deleteClassWithEnumPresent.ts +++ b/tests/cases/fourslash/deleteClassWithEnumPresent.ts @@ -5,6 +5,32 @@ goTo.marker(); edit.deleteAtCaret('class Bar { }'.length); + +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "Foo", + "kind": "enum", + "childItems": [ + { + "text": "a", + "kind": "const" + }, + { + "text": "b", + "kind": "const" + }, + { + "text": "c", + "kind": "const" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/fourslash.ts b/tests/cases/fourslash/fourslash.ts index 825b943e7a8..381cf192cce 100644 --- a/tests/cases/fourslash/fourslash.ts +++ b/tests/cases/fourslash/fourslash.ts @@ -195,6 +195,7 @@ declare namespace FourSlashInterface { noDocCommentTemplate(): void; navigationBar(json: any): void; + navigationTree(json: any): void; navigationItemsListCount(count: number, searchValue: string, matchKind?: string): void; navigationItemsListContains(name: string, kind: string, searchValue: string, matchKind: string, fileName?: string, parentName?: string): void; occurrencesAtPositionContains(range: Range, isWriteAccess?: boolean): void; diff --git a/tests/cases/fourslash/getNavigationBarItems.ts b/tests/cases/fourslash/getNavigationBarItems.ts index 8041ba3b464..4bcfc3e18aa 100644 --- a/tests/cases/fourslash/getNavigationBarItems.ts +++ b/tests/cases/fourslash/getNavigationBarItems.ts @@ -5,6 +5,27 @@ //// ["bar"]: string; ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "C", + "kind": "class", + "childItems": [ + { + "text": "[\"bar\"]", + "kind": "property" + }, + { + "text": "foo", + "kind": "property" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", @@ -31,4 +52,4 @@ verify.navigationBar([ ], "indent": 1 } -]) +]); diff --git a/tests/cases/fourslash/navbar_const.ts b/tests/cases/fourslash/navbar_const.ts index faaedb54482..2d3e3b919d0 100644 --- a/tests/cases/fourslash/navbar_const.ts +++ b/tests/cases/fourslash/navbar_const.ts @@ -2,6 +2,17 @@ //// const c = 0; +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "c", + "kind": "const" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navbar_contains-no-duplicates.ts b/tests/cases/fourslash/navbar_contains-no-duplicates.ts index ba48c4a93dd..f4b52bb09a1 100644 --- a/tests/cases/fourslash/navbar_contains-no-duplicates.ts +++ b/tests/cases/fourslash/navbar_contains-no-duplicates.ts @@ -27,6 +27,83 @@ //// export var x = 3; //// } +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "ABC", + "kind": "class", + "childItems": [ + { + "text": "foo", + "kind": "method", + "kindModifiers": "public" + } + ] + }, + { + "text": "ABC", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ] + }, + { + "text": "Windows", + "kind": "module", + "kindModifiers": "declare", + "childItems": [ + { + "text": "Foundation", + "kind": "module", + "kindModifiers": "export,declare", + "childItems": [ + { + "text": "A", + "kind": "var", + "kindModifiers": "export,declare" + }, + { + "text": "B", + "kind": "var", + "kindModifiers": "export,declare" + }, + { + "text": "Test", + "kind": "class", + "kindModifiers": "export,declare", + "childItems": [ + { + "text": "wow", + "kind": "method", + "kindModifiers": "public,declare" + } + ] + }, + { + "text": "Test", + "kind": "module", + "kindModifiers": "export,declare", + "childItems": [ + { + "text": "Boom", + "kind": "function", + "kindModifiers": "export,declare" + } + ] + } + ] + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navbar_exportDefault.ts b/tests/cases/fourslash/navbar_exportDefault.ts index e547c9129a6..84f50610e6b 100644 --- a/tests/cases/fourslash/navbar_exportDefault.ts +++ b/tests/cases/fourslash/navbar_exportDefault.ts @@ -13,6 +13,17 @@ ////export default function Func { } goTo.file("a.ts"); +verify.navigationTree({ + "text": "\"a\"", + "kind": "module", + "childItems": [ + { + "text": "default", + "kind": "class", + "kindModifiers": "export" + } + ] +}); verify.navigationBar([ { "text": "\"a\"", @@ -34,6 +45,17 @@ verify.navigationBar([ ]); goTo.file("b.ts"); +verify.navigationTree({ + "text": "\"b\"", + "kind": "module", + "childItems": [ + { + "text": "C", + "kind": "class", + "kindModifiers": "export" + } + ] +}); verify.navigationBar([ { "text": "\"b\"", @@ -55,6 +77,17 @@ verify.navigationBar([ ]); goTo.file("c.ts"); +verify.navigationTree({ + "text": "\"c\"", + "kind": "module", + "childItems": [ + { + "text": "default", + "kind": "function", + "kindModifiers": "export" + } + ] +}); verify.navigationBar([ { "text": "\"c\"", @@ -76,6 +109,17 @@ verify.navigationBar([ ]); goTo.file("d.ts"); +verify.navigationTree({ + "text": "\"d\"", + "kind": "module", + "childItems": [ + { + "text": "Func", + "kind": "function", + "kindModifiers": "export" + } + ] +}); verify.navigationBar([ { "text": "\"d\"", diff --git a/tests/cases/fourslash/navbar_let.ts b/tests/cases/fourslash/navbar_let.ts index bd0e702bbf9..77e00ad7300 100644 --- a/tests/cases/fourslash/navbar_let.ts +++ b/tests/cases/fourslash/navbar_let.ts @@ -2,6 +2,17 @@ ////let c = 0; +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "c", + "kind": "let" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions.ts b/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions.ts index 8ede0f07ea0..7c238aa1e26 100644 --- a/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions.ts +++ b/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions.ts @@ -26,6 +26,85 @@ //// (class { }); ////}) +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "", + "kind": "function", + "childItems": [ + { + "text": "nest", + "kind": "function", + "childItems": [ + { + "text": "moreNest", + "kind": "function" + } + ] + }, + { + "text": "x", + "kind": "function", + "childItems": [ + { + "text": "xx", + "kind": "function" + } + ] + }, + { + "text": "y", + "kind": "const", + "childItems": [ + { + "text": "foo", + "kind": "function" + } + ] + } + ] + }, + { + "text": "", + "kind": "function", + "childItems": [ + { + "text": "", + "kind": "function" + }, + { + "text": "z", + "kind": "function" + } + ] + }, + { + "text": "classes", + "kind": "function", + "childItems": [ + { + "text": "", + "kind": "class" + }, + { + "text": "cls2", + "kind": "class" + }, + { + "text": "cls3", + "kind": "class" + } + ] + }, + { + "text": "global.cls", + "kind": "class" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions2.ts b/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions2.ts index 36b1e07cd8a..f6ce02e0dd0 100644 --- a/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions2.ts +++ b/tests/cases/fourslash/navigationBarAnonymousClassAndFunctionExpressions2.ts @@ -3,6 +3,39 @@ ////console.log(console.log(class Y {}, class X {}), console.log(class B {}, class A {})); ////console.log(class Cls { meth() {} }); +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "A", + "kind": "class" + }, + { + "text": "B", + "kind": "class" + }, + { + "text": "Cls", + "kind": "class", + "childItems": [ + { + "text": "meth", + "kind": "method" + } + ] + }, + { + "text": "X", + "kind": "class" + }, + { + "text": "Y", + "kind": "class" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarGetterAndSetter.ts b/tests/cases/fourslash/navigationBarGetterAndSetter.ts index 3ae2e0f60ac..ccf9e7c472e 100644 --- a/tests/cases/fourslash/navigationBarGetterAndSetter.ts +++ b/tests/cases/fourslash/navigationBarGetterAndSetter.ts @@ -8,6 +8,33 @@ //// } ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "X", + "kind": "class", + "childItems": [ + { + "text": "x", + "kind": "getter" + }, + { + "text": "x", + "kind": "setter", + "childItems": [ + { + "text": "f", + "kind": "function" + } + ] + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarImports.ts b/tests/cases/fourslash/navigationBarImports.ts index 43cb99c556a..44f0d46b401 100644 --- a/tests/cases/fourslash/navigationBarImports.ts +++ b/tests/cases/fourslash/navigationBarImports.ts @@ -4,6 +4,29 @@ ////import c = require("m"); ////import * as d from "m"; +verify.navigationTree({ + "text": "\"navigationBarImports\"", + "kind": "module", + "childItems": [ + { + "text": "a", + "kind": "alias" + }, + { + "text": "b", + "kind": "alias" + }, + { + "text": "c", + "kind": "alias" + }, + { + "text": "d", + "kind": "alias" + } + ] +}); + verify.navigationBar([ { "text": "\"navigationBarImports\"", diff --git a/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts b/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts index ff1de04c07e..d2b8b24bcbf 100644 --- a/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts +++ b/tests/cases/fourslash/navigationBarItemsBindingPatterns.ts @@ -6,6 +6,57 @@ ////const bar1, [c, d] ////var {e, x: [f, g]} = {a:1, x:[]}; +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "a", + "kind": "let" + }, + { + "text": "b", + "kind": "let" + }, + { + "text": "bar", + "kind": "var" + }, + { + "text": "bar1", + "kind": "const" + }, + { + "text": "c", + "kind": "const" + }, + { + "text": "d", + "kind": "const" + }, + { + "text": "e", + "kind": "var" + }, + { + "text": "f", + "kind": "var" + }, + { + "text": "foo", + "kind": "var" + }, + { + "text": "foo1", + "kind": "let" + }, + { + "text": "g", + "kind": "var" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts index 61e34d0f30e..f1250d530d3 100644 --- a/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts +++ b/tests/cases/fourslash/navigationBarItemsBindingPatternsInConstructor.ts @@ -11,6 +11,41 @@ //// } ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "A", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "x", + "kind": "property" + } + ] + }, + { + "text": "B", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "x", + "kind": "property" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts index 2e37f69b456..c300a1207d5 100644 --- a/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsEmptyConstructors.ts @@ -5,6 +5,23 @@ //// } ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "Test", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsExports.ts b/tests/cases/fourslash/navigationBarItemsExports.ts index 3ec9b0a7138..1f29ae5af5b 100644 --- a/tests/cases/fourslash/navigationBarItemsExports.ts +++ b/tests/cases/fourslash/navigationBarItemsExports.ts @@ -9,6 +9,26 @@ //// ////export * from "a"; // no bindings here +verify.navigationTree({ + "text": "\"navigationBarItemsExports\"", + "kind": "module", + "childItems": [ + { + "text": "a", + "kind": "alias" + }, + { + "text": "B", + "kind": "alias" + }, + { + "text": "e", + "kind": "alias", + "kindModifiers": "export" + } + ] +}); + verify.navigationBar([ { "text": "\"navigationBarItemsExports\"", diff --git a/tests/cases/fourslash/navigationBarItemsFunctions.ts b/tests/cases/fourslash/navigationBarItemsFunctions.ts index b85e898065c..f43cd3effaf 100644 --- a/tests/cases/fourslash/navigationBarItemsFunctions.ts +++ b/tests/cases/fourslash/navigationBarItemsFunctions.ts @@ -14,6 +14,53 @@ //// var v = 10; ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "baz", + "kind": "function", + "childItems": [ + { + "text": "v", + "kind": "var" + } + ] + }, + { + "text": "foo", + "kind": "function", + "childItems": [ + { + "text": "bar", + "kind": "function", + "childItems": [ + { + "text": "biz", + "kind": "function", + "childItems": [ + { + "text": "z", + "kind": "var" + } + ] + }, + { + "text": "y", + "kind": "var" + } + ] + }, + { + "text": "x", + "kind": "var" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts index b0238a1ef06..49ca40841d7 100644 --- a/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts +++ b/tests/cases/fourslash/navigationBarItemsFunctionsBroken.ts @@ -4,6 +4,23 @@ //// function; ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "f", + "kind": "function", + "childItems": [ + { + "text": "", + "kind": "function" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts b/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts index 4f279446100..8ebfab8519b 100644 --- a/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts +++ b/tests/cases/fourslash/navigationBarItemsFunctionsBroken2.ts @@ -5,6 +5,27 @@ //// function; ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "", + "kind": "function" + }, + { + "text": "f", + "kind": "function", + "childItems": [ + { + "text": "", + "kind": "function" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsImports.ts b/tests/cases/fourslash/navigationBarItemsImports.ts index ed398ec7f1d..b0ce515a56c 100644 --- a/tests/cases/fourslash/navigationBarItemsImports.ts +++ b/tests/cases/fourslash/navigationBarItemsImports.ts @@ -13,6 +13,44 @@ //// ////import * as ns from "a"; +verify.navigationTree({ + "text": "\"navigationBarItemsImports\"", + "kind": "module", + "childItems": [ + { + "text": "a", + "kind": "alias" + }, + { + "text": "B", + "kind": "alias" + }, + { + "text": "c", + "kind": "alias" + }, + { + "text": "D", + "kind": "alias" + }, + { + "text": "d1", + "kind": "alias" + }, + { + "text": "d2", + "kind": "alias" + }, + { + "text": "e", + "kind": "alias" + }, + { + "text": "ns", + "kind": "alias" + } + ] +}); verify.navigationBar([ { diff --git a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts index a49f32d960e..35dff3af14c 100644 --- a/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsInsideMethodsAndConstructors.ts @@ -18,6 +18,77 @@ //// emptyMethod() { } // Non child functions method should not be duplicated ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "Class", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor", + "childItems": [ + { + "text": "LocalEnumInConstructor", + "kind": "enum", + "childItems": [ + { + "text": "LocalEnumMemberInConstructor", + "kind": "const" + } + ] + }, + { + "text": "LocalFunctionInConstructor", + "kind": "function" + }, + { + "text": "LocalInterfaceInConstrcutor", + "kind": "interface" + } + ] + }, + { + "text": "emptyMethod", + "kind": "method" + }, + { + "text": "method", + "kind": "method", + "childItems": [ + { + "text": "LocalEnumInMethod", + "kind": "enum", + "childItems": [ + { + "text": "LocalEnumMemberInMethod", + "kind": "const" + } + ] + }, + { + "text": "LocalFunctionInMethod", + "kind": "function", + "childItems": [ + { + "text": "LocalFunctionInLocalFunctionInMethod", + "kind": "function" + } + ] + }, + { + "text": "LocalInterfaceInMethod", + "kind": "interface" + } + ] + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsItems.ts b/tests/cases/fourslash/navigationBarItemsItems.ts index e3d8f0e633c..69422dd0cc2 100644 --- a/tests/cases/fourslash/navigationBarItemsItems.ts +++ b/tests/cases/fourslash/navigationBarItemsItems.ts @@ -39,6 +39,114 @@ ////var p: IPoint = new Shapes.Point(3, 4); ////var dist = p.getDist(); +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "dist", + "kind": "var" + }, + { + "text": "IPoint", + "kind": "interface", + "childItems": [ + { + "text": "()", + "kind": "call" + }, + { + "text": "new()", + "kind": "construct" + }, + { + "text": "[]", + "kind": "index" + }, + { + "text": "getDist", + "kind": "method" + }, + { + "text": "prop", + "kind": "property" + } + ] + }, + { + "text": "p", + "kind": "var" + }, + { + "text": "Shapes", + "kind": "module", + "childItems": [ + { + "text": "Point", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "getDist", + "kind": "method" + }, + { + "text": "getOrigin", + "kind": "method", + "kindModifiers": "private,static" + }, + { + "text": "origin", + "kind": "property", + "kindModifiers": "static" + }, + { + "text": "value", + "kind": "getter" + }, + { + "text": "value", + "kind": "setter" + }, + { + "text": "x", + "kind": "property", + "kindModifiers": "public" + }, + { + "text": "y", + "kind": "property", + "kindModifiers": "public" + } + ] + }, + { + "text": "Values", + "kind": "enum", + "childItems": [ + { + "text": "value1", + "kind": "const" + }, + { + "text": "value2", + "kind": "const" + }, + { + "text": "value3", + "kind": "const" + } + ] + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsItems2.ts b/tests/cases/fourslash/navigationBarItemsItems2.ts index 6ab0827e8f9..fa5a5b09fac 100644 --- a/tests/cases/fourslash/navigationBarItemsItems2.ts +++ b/tests/cases/fourslash/navigationBarItemsItems2.ts @@ -6,6 +6,22 @@ goTo.marker(); edit.insertLine("module A"); edit.insert("export class "); +verify.navigationTree({ + "text": "\"navigationBarItemsItems2\"", + "kind": "module", + "childItems": [ + { + "text": "", + "kind": "class", + "kindModifiers": "export" + }, + { + "text": "A", + "kind": "module" + } + ] +}); + // should not crash verify.navigationBar([ { diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts index 04091185dd0..705dc2227b3 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules.ts @@ -4,6 +4,25 @@ //// public s: string; ////} +verify.navigationTree({ + "text": "\"navigationBarItemsItemsExternalModules\"", + "kind": "module", + "childItems": [ + { + "text": "Bar", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "s", + "kind": "property", + "kindModifiers": "public" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "\"navigationBarItemsItemsExternalModules\"", diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts index 4939091d944..c271050bc52 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules2.ts @@ -6,6 +6,30 @@ ////} ////export var x: number; +verify.navigationTree({ + "text": "\"file\"", + "kind": "module", + "childItems": [ + { + "text": "Bar", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "s", + "kind": "property", + "kindModifiers": "public" + } + ] + }, + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ] +}); + verify.navigationBar([ { "text": "\"file\"", diff --git a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts index 5ee760fabc6..91ac533d75c 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsExternalModules3.ts @@ -6,6 +6,30 @@ ////} ////export var x: number; +verify.navigationTree({ + "text": "\"my fil\\\"e\"", + "kind": "module", + "childItems": [ + { + "text": "Bar", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "s", + "kind": "property", + "kindModifiers": "public" + } + ] + }, + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ] +}); + verify.navigationBar([ { "text": "\"my fil\\\"e\"", diff --git a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts index 9b8a65d0430..1beeffddb21 100644 --- a/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts +++ b/tests/cases/fourslash/navigationBarItemsItemsModuleVariables.ts @@ -20,6 +20,23 @@ ////} goTo.marker("file1"); // nothing else should show up +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "Module1", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ] + } + ] +}); verify.navigationBar([ { "text": "", @@ -46,6 +63,23 @@ verify.navigationBar([ ]); goTo.marker("file2"); +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "Module1.SubModule", + "kind": "module", + "childItems": [ + { + "text": "y", + "kind": "var", + "kindModifiers": "export" + } + ] + } + ] +}); verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsMissingName1.ts b/tests/cases/fourslash/navigationBarItemsMissingName1.ts index 2a445a5e1ed..60123d92e71 100644 --- a/tests/cases/fourslash/navigationBarItemsMissingName1.ts +++ b/tests/cases/fourslash/navigationBarItemsMissingName1.ts @@ -3,6 +3,28 @@ //// foo() {} ////} +verify.navigationTree({ + "text": "\"navigationBarItemsMissingName1\"", + "kind": "module", + "childItems": [ + { + "text": "", + "kind": "function", + "kindModifiers": "export" + }, + { + "text": "C", + "kind": "class", + "childItems": [ + { + "text": "foo", + "kind": "method" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "\"navigationBarItemsMissingName1\"", diff --git a/tests/cases/fourslash/navigationBarItemsMissingName2.ts b/tests/cases/fourslash/navigationBarItemsMissingName2.ts index 9faeb6de902..ce92128c825 100644 --- a/tests/cases/fourslash/navigationBarItemsMissingName2.ts +++ b/tests/cases/fourslash/navigationBarItemsMissingName2.ts @@ -6,6 +6,23 @@ ////} // Anonymous classes are still included. +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "", + "kind": "class", + "childItems": [ + { + "text": "foo", + "kind": "method" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsModules.ts b/tests/cases/fourslash/navigationBarItemsModules.ts index a41c75de550..fd5907e2bc7 100644 --- a/tests/cases/fourslash/navigationBarItemsModules.ts +++ b/tests/cases/fourslash/navigationBarItemsModules.ts @@ -27,6 +27,73 @@ //We have 8 module keywords, and 4 var keywords. //The declarations of A.B.C.x do not get merged, so the 4 vars are independent. //The two 'A' modules, however, do get merged, so in reality we have 7 modules. +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "'X2.Y2.Z2'", + "kind": "module", + "kindModifiers": "declare" + }, + { + "text": "\"X.Y.Z\"", + "kind": "module", + "kindModifiers": "declare" + }, + { + "text": "A", + "kind": "module", + "childItems": [ + { + "text": "B", + "kind": "module", + "childItems": [ + { + "text": "C", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var", + "kindModifiers": "declare" + } + ] + } + ] + }, + { + "text": "z", + "kind": "var", + "kindModifiers": "export" + } + ] + }, + { + "text": "A.B", + "kind": "module", + "childItems": [ + { + "text": "y", + "kind": "var", + "kindModifiers": "export" + } + ] + }, + { + "text": "A.B.C", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts index dcf8894bb61..793844ac970 100644 --- a/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts +++ b/tests/cases/fourslash/navigationBarItemsMultilineStringIdentifiers.ts @@ -24,6 +24,56 @@ //// } ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "\"Multiline\\\nMadness\"", + "kind": "module", + "kindModifiers": "declare" + }, + { + "text": "\"Multiline\\r\\nMadness\"", + "kind": "module", + "kindModifiers": "declare" + }, + { + "text": "\"MultilineMadness\"", + "kind": "module", + "kindModifiers": "declare" + }, + { + "text": "Bar", + "kind": "class", + "childItems": [ + { + "text": "'a1\\\\\\r\\nb'", + "kind": "property" + }, + { + "text": "'a2\\\n \\\n b'", + "kind": "method" + } + ] + }, + { + "text": "Foo", + "kind": "interface", + "childItems": [ + { + "text": "\"a1\\\\\\r\\nb\"", + "kind": "property" + }, + { + "text": "\"a2\\\n \\\n b\"", + "kind": "method" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts index b741084dab5..6e8e0ea350c 100644 --- a/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts +++ b/tests/cases/fourslash/navigationBarItemsPropertiesDefinedInConstructors.ts @@ -6,6 +6,43 @@ //// } ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "List", + "kind": "class", + "childItems": [ + { + "text": "constructor", + "kind": "constructor", + "childItems": [ + { + "text": "local", + "kind": "var" + } + ] + }, + { + "text": "a", + "kind": "property", + "kindModifiers": "public" + }, + { + "text": "b", + "kind": "property", + "kindModifiers": "private" + }, + { + "text": "c", + "kind": "property" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsSymbols1.ts b/tests/cases/fourslash/navigationBarItemsSymbols1.ts index ba57916028b..4326d7b4deb 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols1.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols1.ts @@ -6,6 +6,31 @@ //// get [Symbol.isConcatSpreadable]() { } ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "C", + "kind": "class", + "childItems": [ + { + "text": "[Symbol.isConcatSpreadable]", + "kind": "getter" + }, + { + "text": "[Symbol.isRegExp]", + "kind": "property" + }, + { + "text": "[Symbol.iterator]", + "kind": "method" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsSymbols2.ts b/tests/cases/fourslash/navigationBarItemsSymbols2.ts index 6812c88c150..64b076aaf0c 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols2.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols2.ts @@ -5,6 +5,27 @@ //// [Symbol.iterator](): string; ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "I", + "kind": "interface", + "childItems": [ + { + "text": "[Symbol.isRegExp]", + "kind": "property" + }, + { + "text": "[Symbol.iterator]", + "kind": "method" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsSymbols3.ts b/tests/cases/fourslash/navigationBarItemsSymbols3.ts index 661005b86d9..be001c75e0b 100644 --- a/tests/cases/fourslash/navigationBarItemsSymbols3.ts +++ b/tests/cases/fourslash/navigationBarItemsSymbols3.ts @@ -5,6 +5,17 @@ //// [Symbol.isRegExp] = 0 ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "E", + "kind": "enum" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarItemsTypeAlias.ts b/tests/cases/fourslash/navigationBarItemsTypeAlias.ts index cba3fb8789c..387a9925d82 100644 --- a/tests/cases/fourslash/navigationBarItemsTypeAlias.ts +++ b/tests/cases/fourslash/navigationBarItemsTypeAlias.ts @@ -2,6 +2,17 @@ ////type T = number | string; +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "T", + "kind": "type" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarJsDoc.ts b/tests/cases/fourslash/navigationBarJsDoc.ts index 89049e6011a..8efce74d111 100644 --- a/tests/cases/fourslash/navigationBarJsDoc.ts +++ b/tests/cases/fourslash/navigationBarJsDoc.ts @@ -5,6 +5,25 @@ /////** @typedef {(string|number)} */ ////const x = 0; +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "NumberLike", + "kind": "type" + }, + { + "text": "x", + "kind": "const" + }, + { + "text": "x", + "kind": "type" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarJsDocCommentWithNoTags.ts b/tests/cases/fourslash/navigationBarJsDocCommentWithNoTags.ts new file mode 100644 index 00000000000..561bdf4a056 --- /dev/null +++ b/tests/cases/fourslash/navigationBarJsDocCommentWithNoTags.ts @@ -0,0 +1,30 @@ +/// + +/////** Test */ +////export const Test = {} + +verify.navigationTree({ + "text": "\"navigationBarJsDocCommentWithNoTags\"", + "kind": "module", + "childItems": [ + { + "text": "Test", + "kind": "const", + "kindModifiers": "export" + } + ] +}); + +verify.navigationBar([ + { + "text": "\"navigationBarJsDocCommentWithNoTags\"", + "kind": "module", + "childItems": [ + { + "text": "Test", + "kind": "const", + "kindModifiers": "export" + } + ] + } +]); diff --git a/tests/cases/fourslash/navigationBarMerging.ts b/tests/cases/fourslash/navigationBarMerging.ts index 2798d186c96..ebf02c94466 100644 --- a/tests/cases/fourslash/navigationBarMerging.ts +++ b/tests/cases/fourslash/navigationBarMerging.ts @@ -11,6 +11,37 @@ //// function bar() {} ////} +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "a", + "kind": "module", + "childItems": [ + { + "text": "bar", + "kind": "function" + }, + { + "text": "foo", + "kind": "function" + } + ] + }, + { + "text": "b", + "kind": "module", + "childItems": [ + { + "text": "foo", + "kind": "function" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", @@ -60,6 +91,22 @@ verify.navigationBar([ ////function a() {} goTo.file("file2.ts"); + +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "a", + "kind": "function" + }, + { + "text": "a", + "kind": "module" + } + ] +}); + verify.navigationBar([ { "text": "", @@ -101,6 +148,34 @@ verify.navigationBar([ ////} goTo.file("file3.ts"); + +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "a", + "kind": "module", + "childItems": [ + { + "text": "A", + "kind": "interface", + "childItems": [ + { + "text": "bar", + "kind": "property" + }, + { + "text": "foo", + "kind": "property" + } + ] + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", @@ -147,6 +222,36 @@ verify.navigationBar([ ////module A.B { export var y; } goTo.file("file4.ts"); + +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "A", + "kind": "module", + "childItems": [ + { + "text": "x", + "kind": "var", + "kindModifiers": "export" + } + ] + }, + { + "text": "A.B", + "kind": "module", + "childItems": [ + { + "text": "y", + "kind": "var", + "kindModifiers": "export" + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/navigationBarNamespaceImportWithNoName.ts b/tests/cases/fourslash/navigationBarNamespaceImportWithNoName.ts index 732e2deb1dd..4c441728fdf 100644 --- a/tests/cases/fourslash/navigationBarNamespaceImportWithNoName.ts +++ b/tests/cases/fourslash/navigationBarNamespaceImportWithNoName.ts @@ -1,4 +1,16 @@ ////import *{} from 'foo'; + +verify.navigationTree({ + "text": "\"navigationBarNamespaceImportWithNoName\"", + "kind": "module", + "childItems": [ + { + "text": "", + "kind": "alias" + } + ] +}); + verify.navigationBar([ { "text": "\"navigationBarNamespaceImportWithNoName\"", diff --git a/tests/cases/fourslash/navigationBarVariables.ts b/tests/cases/fourslash/navigationBarVariables.ts index 93093df1306..98d5e816e8e 100644 --- a/tests/cases/fourslash/navigationBarVariables.ts +++ b/tests/cases/fourslash/navigationBarVariables.ts @@ -4,6 +4,25 @@ ////let y = 1; ////const z = 2; +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "x", + "kind": "var" + }, + { + "text": "y", + "kind": "let" + }, + { + "text": "z", + "kind": "const" + } + ] +}); + verify.navigationBar([ { "text": "", @@ -31,6 +50,26 @@ verify.navigationBar([ ////const [c] = 0; goTo.file("file2.ts"); + +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "a", + "kind": "var" + }, + { + "text": "b", + "kind": "let" + }, + { + "text": "c", + "kind": "const" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts b/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts index 978db18ab3b..212394159a8 100644 --- a/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts +++ b/tests/cases/fourslash/server/jsdocTypedefTagNavigateTo.ts @@ -10,6 +10,29 @@ //// /** @type {/*1*/NumberLike} */ //// var numberLike; +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "numberLike", + "kind": "var" + }, + { + "text": "NumberLike", + "kind": "type" + }, + { + "text": "NumberLike2", + "kind": "var" + }, + { + "text": "NumberLike2", + "kind": "type" + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/server/navbar01.ts b/tests/cases/fourslash/server/navbar01.ts index a5b22ee1fa9..4a4f59bcf78 100644 --- a/tests/cases/fourslash/server/navbar01.ts +++ b/tests/cases/fourslash/server/navbar01.ts @@ -38,6 +38,114 @@ ////var p: IPoint = new Shapes.Point(3, 4); ////var dist = p.getDist(); +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "dist", + "kind": "var" + }, + { + "text": "IPoint", + "kind": "interface", + "childItems": [ + { + "text": "()", + "kind": "call" + }, + { + "text": "new()", + "kind": "construct" + }, + { + "text": "[]", + "kind": "index" + }, + { + "text": "getDist", + "kind": "method" + }, + { + "text": "prop", + "kind": "property" + } + ] + }, + { + "text": "p", + "kind": "var" + }, + { + "text": "Shapes", + "kind": "module", + "childItems": [ + { + "text": "Point", + "kind": "class", + "kindModifiers": "export", + "childItems": [ + { + "text": "constructor", + "kind": "constructor" + }, + { + "text": "getDist", + "kind": "method" + }, + { + "text": "getOrigin", + "kind": "method", + "kindModifiers": "private,static" + }, + { + "text": "origin", + "kind": "property", + "kindModifiers": "static" + }, + { + "text": "value", + "kind": "getter" + }, + { + "text": "value", + "kind": "setter" + }, + { + "text": "x", + "kind": "property", + "kindModifiers": "public" + }, + { + "text": "y", + "kind": "property", + "kindModifiers": "public" + } + ] + }, + { + "text": "Values", + "kind": "enum", + "childItems": [ + { + "text": "value1", + "kind": "const" + }, + { + "text": "value2", + "kind": "const" + }, + { + "text": "value3", + "kind": "const" + } + ] + } + ] + } + ] +}); + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts b/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts index fba24bdcf77..627d4dac178 100644 --- a/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts +++ b/tests/cases/fourslash/shims-pp/getNavigationBarItems.ts @@ -2,6 +2,17 @@ //// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0; +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "c", + "kind": "const" + } + ] +}) + verify.navigationBar([ { "text": "", diff --git a/tests/cases/fourslash/shims/getNavigationBarItems.ts b/tests/cases/fourslash/shims/getNavigationBarItems.ts index fba24bdcf77..627d4dac178 100644 --- a/tests/cases/fourslash/shims/getNavigationBarItems.ts +++ b/tests/cases/fourslash/shims/getNavigationBarItems.ts @@ -2,6 +2,17 @@ //// {| "itemName": "c", "kind": "const", "parentName": "" |}const c = 0; +verify.navigationTree({ + "text": "", + "kind": "script", + "childItems": [ + { + "text": "c", + "kind": "const" + } + ] +}) + verify.navigationBar([ { "text": "",