Open DanKaplanSES opened 1 year ago
Afraid that's not possible without vscode support for the feature - maybe a right click command might be possible, you'd have to look into the APIs
Clarifying question: are you saying that this can't be done with an InlayHintsProvider
?
What follows are assumptions built on top of assumptions:
Assuming that's what you meant, hypothetically, could an extension directly write the text in the editor instead of using a InlayHintsProvider? (I'm not trying to put the onus of this research on your plate, I just thought you might know off the top of your head.)
And assuming the answer to that question is yes, would you consider changing the extension to do that / adding a setting to do that?
Maybe the better option would be a code action to display the type of an identifier / to copy it to the clipboard?
@jasikpark When you say "it," do you mean the text of the InlayHintsProvider
? I could see that being useful. It's definitely better than typing out the content of the InlayHintsProvider
by hand.
So, with that feature, these are the steps to share some code that includes two slash on stack overflow or slack etc.
// ^?
// ^?
, repeat step 4.Am I understanding correctly?
moreso that you could highlight an identifier to interact with it to perform those actions, rather than copying text, which would not be viable
@jasikpark Apologies for my confusion. Assuming you could highlight an identifier to interact with it, what would be the steps to perform this use case:
I would like it to share a section of my code outside of VSCode (e.g., pasted into my browser to ask a stack overflow question) while allowing others to see the twoslash types.
It looks like this is possible with InlayHintsProvider
. The InlayHint
interface has an property label
which can be an string
(as in this extension), but it can also be an InlayHintLabelPart
interface, which provides again the label
property, but now also an optional command
of interface Command
, allowing you to execute your own command to copy whats inside your hint.
oooh https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/pull/47 from https://github.com/microsoft/TypeScript/issues/52839 seems like a good solution for your purposes @DanKaplanSES
@jasikpark https://github.com/microsoft/TypeScript/issues/52839 sounds perfect to me. Using https://github.com/JoshuaKGoldberg/eslint-plugin-expect-type/pull/47 is an interesting idea; are you suggesting I intentionally create invalid twoslash comment types and let the plug-in fill in the correct comment string? That'd work nicely, so thanks for letting me know.
Question: will I have to uninstall the "vscode twoslash queries" plug-in to use this? It seems like they would fight with each other.
Regardless, IMHO it would be even better if the twoslash comment type automatically kept up to date, but since the linter will catch errors, your idea is like 95% of the way there. eslint / vscode may even have an automated way of fixing these on file change, which is like 100% of the way there.
I'm not sure where this leaves this issue.
even with this solution i've found it annoying that I can't copy the inferred type for use in a satisfies clause
This is a feature request. Often, I'm using the query to document a code example so I can get help on it. But if I copy the code sample and paste it, it copies only
// ^?
. I would like it to copy the full expanded text with it, that way, when I share my code, other people can see the types.