jose-elias-alvarez / nvim-lsp-ts-utils

Utilities to improve the TypeScript development experience for Neovim's built-in LSP client.
The Unlicense
438 stars 18 forks source link

TSLspImportAll: implement priority #42

Closed jose-elias-alvarez closed 3 years ago

jose-elias-alvarez commented 3 years ago

The idea came up in #39 to prioritize importing from open buffers. Potential implementations, in order of increasing complexity:

The last option is the best but might not be worth the effort, since I don't know how many users would be interested in that level of control.

non25 commented 3 years ago

The only thing I'd like to add is that it should look for existing imports too in the open buffers.

I think prioritizing project files is really useful. If you don't have buffers opened, e.g. when you just opened one file, but you have third party abstractions wrapped in yours, or you are using exports with the same name across the project, then I imagine you would want to autoimport yours 100% of time.

Don't know if configurability is needed though.

Also would be cool to do this interactively. Like if you have >2 options to import it would prompt you in that case.

jose-elias-alvarez commented 3 years ago

Could you clarify what you mean by "existing imports" from open buffers?

Interactive choice would be great, and it shouldn't be too hard to implement, either. For priority, I'm leaning towards open buffers > project files > external modules, with a simple config option to disable priority for maximum speed.

non25 commented 3 years ago

Sure,

// other opened buffer
// react material has this too, prefer auto-importing this EditIcon because it is imported in the other buffer
import { EditIcon } from 'common/icons';

function someFunction () {
  // some code
}

export { someFunction };
jose-elias-alvarez commented 3 years ago

Ah, okay, I see. That's a good idea – it's a simple heuristic but I imagine it would be very accurate in predicting the import the user wants. As far as implementation, it's definitely possible but I'd want to test performance, especially with a large number of buffers open (though we could put in a limit).