Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Navto covers all projects #38027

Merged
merged 6 commits into from
Apr 21, 2020
Merged

Navto covers all projects #38027

merged 6 commits into from
Apr 21, 2020

Conversation

sandersn
Copy link
Member

With this PR, when navto is called without a file, it returns matches from all projects. Currently it only returns matches from the current project and its dependencies.

I had to change the protocol interface for this, and I'm not sure I did that in the right way. I'm also not sure what tests to write for this feature, beyond the basic one I have.

Fixes #2530

Just pass multiple arguments! Sheesh!
1. Add test
2. Change protocol. navto-all only happens when filename is undefined or
missing.
3. Change location to earlier code path. This change was largely
type-guided and resulted in some duplicated code, but I think it's less
fault-prone.
@typescript-bot
Copy link
Collaborator

Thanks for the PR! It looks like you've changed the TSServer protocol in some way. Please ensure that any changes here don't break consumers of the current TSServer API. For some extra review, we'll ping @sheetalkamat, @amcasey, @mjbvz, @minestarks for you. Feel free to loop in other consumers/maintainers if necessary

@@ -1895,14 +1900,27 @@ namespace ts.server {

private getFullNavigateToItems(args: protocol.NavtoRequestArgs): readonly NavigateToItem[] {
const { currentFileOnly, searchValue, maxResultCount } = args;
if (!args.file) {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is the only substantive change. Everything else is a removal of a frankly ridiculous amount of destructuring/allocation to pass around a project+location pair.

Copy link
Contributor

@mjbvz mjbvz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Server API change look good to me

@minestarks
Copy link
Member

@uniqueiniquity to review protocol. I think VS passes a project so removing that may be problematic

Copy link
Contributor

@uniqueiniquity uniqueiniquity left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In general, this change is desired by VS, so definitely on board with the new functionality 👍

src/server/session.ts Outdated Show resolved Hide resolved
@amcasey
Copy link
Member

amcasey commented Apr 17, 2020

    projectFileName?: string;

Did this used to be redundant?


Refers to: src/server/protocol.ts:2807 in fc8bc8b. [](commit_id = fc8bc8b, deletion_comment = False)

@@ -1895,14 +1900,27 @@ namespace ts.server {

private getFullNavigateToItems(args: protocol.NavtoRequestArgs): readonly NavigateToItem[] {
const { currentFileOnly, searchValue, maxResultCount } = args;
if (!args.file) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

file [](start = 22, length = 4)

Seems like it's now possible to specify a project and no file. If some caller were to do that, I'd expect it to get back project.getLanguageService().getNavigateToItems.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, With no file and just project, the result should be only from that project.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The original case handles basically this case, but includes hits from all dependencies as well. Any ideas for how to reduce it to just the current project?

(It's probably OK to keep the original behaviour, since it won't at least surprise anyone.)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For example, in the test cases, the 'user' project that depends on 'a' and 'b' projects returns [user.ts, a.ts, b.ts] for program.getSourceFiles()

Copy link
Member

@amcasey amcasey left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM, unless there's some project loading subtlety I don't understand.

src/server/session.ts Outdated Show resolved Hide resolved
@@ -1895,14 +1900,27 @@ namespace ts.server {

private getFullNavigateToItems(args: protocol.NavtoRequestArgs): readonly NavigateToItem[] {
const { currentFileOnly, searchValue, maxResultCount } = args;
if (!args.file) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agree, With no file and just project, the result should be only from that project.

@@ -322,6 +324,46 @@ namespace ts.projectSystem {
verifyATsConfigOriginalProject(session);
});

it("navigateToAll", () => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need test when file is not specified and project is...

if (!args.file) {
if (args.projectFileName) {
const project = this.projectService.findProject(args.projectFileName);
if (project) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Throw No Project here as it should be error to send project that does not exist

return combineProjectOutputFromEveryProject(
this.projectService,
project => project.getLanguageService().getNavigateToItems(searchValue, maxResultCount, /*filename*/ undefined, /*excludeDts*/ project.isNonTsProject()),
(a, b) => a.fileName === b.fileName);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not navigateToItemIsEqualTo

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TSServer: navto command should be supported without a file
7 participants