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

Improve "suggestions show path" for "node_modules" #42005

Closed
5 tasks done
heroboy opened this issue Dec 17, 2020 · 7 comments · Fixed by #44713
Closed
5 tasks done

Improve "suggestions show path" for "node_modules" #42005

heroboy opened this issue Dec 17, 2020 · 7 comments · Fixed by #44713
Assignees
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Fix Available A PR has been opened for this issue In Discussion Not yet reached consensus Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript

Comments

@heroboy
Copy link

heroboy commented Dec 17, 2020

Search Terms

TypeScript suggestions show path
TypeScript can provide completions that also add an import statement. However, when there are multiple symbols with the same name, it is hard to pick the right completion. This release makes this simpler because paths of auto-import completions are shown with the label.

Suggestion

As description above. I think the path should be show as import form, not show path like 'node_modules/xxx/index' but 'xxx'
And sort it as the "show fixes" menu I post below.

Use Cases

Here is the current result

图片
It is not very easy to choose which one to import Table, because the path is too long and very same. (Actually I want the 3rd one, it is 'antd')


Here is the "show fixes" menu
图片
It is much more clear.


Here is the "show fixes" menu, when I already import something from 'antd'
图片

Examples

no example.

Checklist

My suggestion meets these guidelines:

  • This wouldn't be a breaking change in existing TypeScript/JavaScript code
  • This wouldn't change the runtime behavior of existing JavaScript code
  • This could be implemented without emitting different JS based on the types of the expressions
  • This isn't a runtime feature (e.g. library functionality, non-ECMAScript syntax with JavaScript output, etc.)
  • This feature would agree with the rest of TypeScript's Design Goals.
@andrewbranch
Copy link
Member

That string was never meant to be shown to humans—at this stage, we don’t know that node_modules/antd/lib/index is resolvable as antd. Doing that takes a good bit more work than we’re able to do for every item in a completion list, which is why we can give you a definite answer in the codefix menu (because we only have to compute possible module specifiers for one symbol, not potentially hundreds). It looks like VS Code decided to show it here: microsoft/vscode#98228.

I think it would be an easy win to drop the leading node_modules/, because I do think this is better than showing nothing. Doing something more sophisticated is sort of tracked #36265, but it covers a lot more than just auto-imports.

But, TypeScript needs that string to contain node_modules/, so I think this is a VS Code issue. Assigning to @mjbvz for input on what to do with it after the holidays.

@andrewbranch andrewbranch added the External Relates to another program, environment, or user action which we cannot control. label Dec 22, 2020
@typescript-bot
Copy link
Collaborator

This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@typescript-bot
Copy link
Collaborator

This issue has been marked as 'External' and has seen no recent activity. It has been automatically closed for house-keeping purposes.

@andrewbranch andrewbranch removed the External Relates to another program, environment, or user action which we cannot control. label Dec 31, 2020
@andrewbranch andrewbranch reopened this Dec 31, 2020
@DanielRosenwasser DanielRosenwasser added Domain: Completion Lists The issue relates to showing completion lists in an editor In Discussion Not yet reached consensus Suggestion An idea for TypeScript labels Feb 3, 2021
@DanielRosenwasser DanielRosenwasser added this to the TypeScript 4.3.1 milestone Mar 26, 2021
@andrewbranch andrewbranch added the Rescheduled This issue was previously scheduled to an earlier milestone label May 28, 2021
@andrewbranch
Copy link
Member

andrewbranch commented Jun 15, 2021

I’ve been experimenting with different ways we can do this while minimizing the interactive response time for completions. The options we have can be broadly divided into two buckets: ones where the response is complete and ones where it is incomplete.

Complete

A complete response means that, like today, we generate the full list of completions when they’re requested, that list is filtered down by the client, and the client never asks for an update to that list; it only asks for additional details for single items as they’re focused. The only way we can significantly improve (uncached) performance for complete responses is to limit the number of auto-imports that show module specifiers (most simply by limiting the number of auto-imports even included in the list).

Note: all response times reported are with completely cold caches. Subsequent requests, especially in the same file, are faster.

  • Without changing how many auto-imports are offered or limiting how many get resolved module specifiers, the time penalty for the CompletionInfo command is +50–100%. (It’s highly dependent upon project structure.)
  • By changing the filter to the same thing that import statement completions (and now Python auto-imports) use (first character typed must be the first character of the symbol name, then fuzzy match), the penalty drops to about +0–25%.
  • By changing the filter to be a looser variation on the above (first character typed must be the first character of a “word” of the symbol, split into snake/camel case words), the penalty is about +13–50%.

These strategies are extremely easy to implement and minimize number of requests and message size of requests, which could be something to think about for remote scenarios, but is usually not one of our biggest considerations. They also feel the snappiest after the response comes back since additional typing only results in client-side filtering.

Incomplete

Incomplete responses, by contrast, result in the client re-requesting completions after more typing occurs. The idea is that we could resolve module specifiers only for the top N auto-imports, and if there are more without resolved module specifiers, we mark the response as incomplete. Then, when the user continues typing, we get another request. At this point, we have more identifier characters to filter by, and we can pull the previous response out of a short-term MRU cache, so we could fill in another N module specifiers for items that match the typed identifier until the response is fully filled in with module specifiers.

I tried a very quick, simple demo of this, and it seemed to work pretty well. The advantage of this general approach is that we would be able to offer all auto-imports that are offered today, and show module specifiers for them once enough characters have been typed that the list is sufficiently small, and we could do this for near-zero performance impact on the time it takes for the list to appear. The disadvantages are higher complexity, much higher cumulative TS Server traffic and response time, and the fact that someone simply scrolling the initial list with incomplete items would see an inconsistency between the ones at the top that have resolved module specifiers and the ones at the bottom that don’t.

@mjbvz
Copy link
Contributor

mjbvz commented Jun 16, 2021

Adding @jrieken since this is related to #36265 and the VS Code label2 api proposal

@andrewbranch
Copy link
Member

I should also clarify that I outlined only the options that are available to us now with minimal or no API/client changes. The third way would be to request pages of label2 entries based on what’s visible in the list UI at a given time, so it would update both while typing and while scrolling. But based on the earlier discussion in #36265, my impression was that’s not feasible, which is why I’ve been looking into solutions that can be implemented on the TS side. We also want any solution to be doable in LSP.

@jrieken
Copy link
Member

jrieken commented Jun 21, 2021

But based on the earlier discussion in #36265, my impression was that’s not feasible, which is why I’ve been looking into solutions that can be implemented on the TS side. We also want any solution to be doable in LSP.

Yes - we have currently no plans to lazy load labels of completion items.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Domain: Completion Lists The issue relates to showing completion lists in an editor Fix Available A PR has been opened for this issue In Discussion Not yet reached consensus Rescheduled This issue was previously scheduled to an earlier milestone Suggestion An idea for TypeScript
Projects
None yet
6 participants