Skip to content

Commit f19619e

Browse files
author
steveluc
committed
Add maxResultCount optional field to NavtoRequestArgs. Change
session.ts to use this field. Remove sort of nav items from getNavigateToItems in sesion.ts because LS now does the sort. Removed no content throw in quick info as this happens frequently with Sublime (every cursor move calls quick info, and quick info is only available on symbols). Added mechanism for other commands to avoid throwing and instead return a specific error message, so that we don't make the log unreadable (as it was with hundreds of quick info stack traces).
1 parent 60a6b28 commit f19619e

3 files changed

Lines changed: 18 additions & 31 deletions

File tree

src/server/client.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -208,9 +208,9 @@ module ts.server {
208208
return response.body[0];
209209
}
210210

211-
getNavigateToItems(searchTerm: string): NavigateToItem[] {
211+
getNavigateToItems(searchValue: string): NavigateToItem[] {
212212
var args: protocol.NavtoRequestArgs = {
213-
searchTerm,
213+
searchValue,
214214
file: this.host.getScriptFileNames()[0]
215215
};
216216

src/server/protocol.d.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,11 @@ declare module ts.server.protocol {
676676
* Search term to navigate to from current location; term can
677677
* be '.*' or an identifier prefix.
678678
*/
679-
searchTerm: string;
679+
searchValue: string;
680+
/**
681+
* Optional limit on the number of items to return.
682+
*/
683+
maxResultCount?: number;
680684
}
681685

682686
/**

src/server/session.ts

Lines changed: 11 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -52,30 +52,6 @@ module ts.server {
5252
return 1;
5353
}
5454
}
55-
56-
function sortNavItems(items: ts.NavigateToItem[]) {
57-
return items.sort((a, b) => {
58-
if (a.matchKind < b.matchKind) {
59-
return -1;
60-
}
61-
else if (a.matchKind == b.matchKind) {
62-
var lowa = a.name.toLowerCase();
63-
var lowb = b.name.toLowerCase();
64-
if (lowa < lowb) {
65-
return -1;
66-
}
67-
else if (lowa == lowb) {
68-
return 0;
69-
}
70-
else {
71-
return 1;
72-
}
73-
}
74-
else {
75-
return 1;
76-
}
77-
})
78-
}
7955

8056
function formatDiag(fileName: string, project: Project, diag: ts.Diagnostic) {
8157
return {
@@ -404,7 +380,7 @@ module ts.server {
404380
var position = compilerService.host.lineColToPosition(file, line, col);
405381
var quickInfo = compilerService.languageService.getQuickInfoAtPosition(file, position);
406382
if (!quickInfo) {
407-
throw Errors.NoContent;
383+
return undefined;
408384
}
409385

410386
var displayString = ts.displayPartsToString(quickInfo.displayParts);
@@ -625,15 +601,15 @@ module ts.server {
625601
return this.decorateNavigationBarItem(project, fileName, items);
626602
}
627603

628-
getNavigateToItems(searchTerm: string, fileName: string): protocol.NavtoItem[] {
604+
getNavigateToItems(searchValue: string, fileName: string, maxResultCount?: number): protocol.NavtoItem[] {
629605
var file = ts.normalizePath(fileName);
630606
var project = this.projectService.getProjectForFile(file);
631607
if (!project) {
632608
throw Errors.NoProject;
633609
}
634610

635611
var compilerService = project.compilerService;
636-
var navItems = sortNavItems(compilerService.languageService.getNavigateToItems(searchTerm));
612+
var navItems = compilerService.languageService.getNavigateToItems(searchValue, maxResultCount);
637613
if (!navItems) {
638614
throw Errors.NoContent;
639615
}
@@ -690,6 +666,7 @@ module ts.server {
690666
try {
691667
var request = <protocol.Request>JSON.parse(message);
692668
var response: any;
669+
var errorMessage: string;
693670
switch (request.command) {
694671
case CommandNames.Definition: {
695672
var defArgs = <protocol.FileLocationRequestArgs>request.arguments;
@@ -714,6 +691,9 @@ module ts.server {
714691
case CommandNames.Quickinfo: {
715692
var quickinfoArgs = <protocol.FileLocationRequestArgs>request.arguments;
716693
response = this.getQuickInfo(quickinfoArgs.line, quickinfoArgs.col, quickinfoArgs.file);
694+
if (!response) {
695+
errorMessage = "No info at this location";
696+
}
717697
break;
718698
}
719699
case CommandNames.Format: {
@@ -765,7 +745,7 @@ module ts.server {
765745
}
766746
case CommandNames.Navto: {
767747
var navtoArgs = <protocol.NavtoRequestArgs>request.arguments;
768-
response = this.getNavigateToItems(navtoArgs.searchTerm, navtoArgs.file);
748+
response = this.getNavigateToItems(navtoArgs.searchValue, navtoArgs.file, navtoArgs.maxResultCount);
769749
break;
770750
}
771751
case CommandNames.Brace: {
@@ -788,6 +768,9 @@ module ts.server {
788768
if (response) {
789769
this.output(response, request.command, request.seq);
790770
}
771+
else if (errorMessage) {
772+
this.output(undefined, request.command, request.seq, errorMessage);
773+
}
791774

792775
} catch (err) {
793776
if (err instanceof OperationCanceledException) {

0 commit comments

Comments
 (0)