microsoft / TypeScript

TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
https://www.typescriptlang.org
Apache License 2.0
100.59k stars 12.44k forks source link

Import-on-paste implementation question #60194

Open DanielRosenwasser opened 5 hours ago

DanielRosenwasser commented 5 hours ago

Hi, I'm a language server developer. I am very curious about how to implement the Import-on-Paste function you mentioned above? Here is my idea, is it feasible? (sorry but reading ts source code is a bit difficult for me)

  1. Before pasting the text in the clipboard into the file, maintain a string of the pasted text in the memory
  2. Compile the new code in this memory
  3. If there is no syntax error, if an undefined symbol error is encountered in the line where the paste is located, try to do automatic completion at the location of the symbol
  4. If there is an automatic completion item that completely matches the text of the symbol, complete the import statement corresponding to this item (the same as the behavior of the user manually selecting this completion item)
  5. Repeat 2 to 5 until there is no such error, or there is no completely matching text
  6. Overwrite the text string in the memory into the file to be pasted

Originally posted by @imbant in #59905

DanielRosenwasser commented 5 hours ago

@navya9singh implemented #50187 at #57262, and I think she can give some details on how the current heuristics work.

DanielRosenwasser commented 5 hours ago

Also, are you asking in the context of Vue on Volar?