You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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)
Before pasting the text in the clipboard into the file, maintain a string of the pasted text in the memory
Compile the new code in this memory
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
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)
Repeat 2 to 5 until there is no such error, or there is no completely matching text
Overwrite the text string in the memory into the file to be pasted
Thanks for your help.
Yes I also post that in volar's discord, but I'm working on a different language server. I just wanted to ask someone who knows how to do this, so I use discord and GitHub
imbant (@imbant) you're idea looks good to me. That's mostly how we do it too. Just to give you some more details:
You would want to have the string of the copied text and if you want, the location of where it was copied from, from the editor.
To make it easy for us to see which symbols(in the copied text) need to be resolved, we add the text to the targeted file and update files for that project and check which symbols can be resolved and which cannot. This is done because it's not possible to get diagnostics only from a string of copied text.
For the symbols that cannot be resolved, we add imports for them.
Then the changes in the targeted file are reverted and tsserver returns the copied text, along with the imports to the editor.
Hope this help and please feel free to ask more questions if you'd like!
Activity
DanielRosenwasser commentedon Oct 10, 2024
navya9singh implemented #50187 at #57262, and I think she can give some details on how the current heuristics work.
DanielRosenwasser commentedon Oct 10, 2024
Also, are you asking in the context of Vue on Volar?
imbant commentedon Oct 11, 2024
Thanks for your help.
Yes I also post that in volar's discord, but I'm working on a different language server. I just wanted to ask someone who knows how to do this, so I use discord and GitHub
navya9singh commentedon Oct 11, 2024
imbant (@imbant) you're idea looks good to me. That's mostly how we do it too. Just to give you some more details:
Hope this help and please feel free to ask more questions if you'd like!
imbant commentedon Oct 12, 2024
Wow thank you very much for your support and help. I am glad that my idea is correct. This's very inspiring for my own language server.
Look forward to using import-on-paste in VS Code!
typescript-bot commentedon Oct 15, 2024
This issue has been marked as "Question" and has seen no recent activity. It has been automatically closed for house-keeping purposes.