friendly-snippets icon indicating copy to clipboard operation
friendly-snippets copied to clipboard

Extend typescript snippets due to #88 changes

Open timsofteng opened this issue 2 years ago • 11 comments

Hello. I've notices you drop mixing sources for some complex filetypes (ts and tsx in my case). https://github.com/rafamadriz/friendly-snippets/issues/88

So now I should invoke additional command to mix js and ts snippets. But i guess typescript still js. It's not a framework or something like that. And js snippets still totally relevant. May you please copy js snippets into typescript's json to make it consistent? E.g in js snippets console.log is cl and in ts snippets its log. And so on.

timsofteng avatar Dec 15 '21 16:12 timsofteng

Hey, thanks for reporting this.

Is typescript the exact same as JavaScript ? I don't work with typescript so I'm not sure, I know they are almost the same but I thought there were some minor differences in the syntax. I can make all the typescript snippets be the same as javascript but I need to be sure that it's not going to bring some problems where some snippets are not proper typescript syntax, or maybe some typescript exclusive snippets are deleted.

rafamadriz avatar Dec 29 '21 11:12 rafamadriz

I've run into a similar thing where I want to use the javascript snippets in typescript. All javascript is valid typescript. There are some situations where a type needs to be added, but it should be fine to have the javascript snippets available in typescript. The snippets in react.json and react-ts.json also seem to be identical.

What's the best way to make the javascript snippets available when filetype is typescript?

koengommers avatar Jan 30 '22 21:01 koengommers

@rafamadriz any news about it? can you please extande typescript.json with javascript.json?

timsofteng avatar Apr 18 '22 10:04 timsofteng

@rafamadriz any news about it? I've can you please extande typescript.json with javascript.json?

So, you want js snippets in ts? Or ts snippets in js file?

bryant-the-coder avatar Apr 24 '22 00:04 bryant-the-coder

@bryant-the-coder We need js snippets in ts. The main idea is to have same js base snippets for all js-like files (ts, tsx, jsx) with their own snippets additionally. Take a look at tsx and js snippets. There are a lot of differents in names in same snippets. Like console.log is cl in js but it's log in tsx. And many snippets missed in tsx comparing to js.

timsofteng avatar Apr 24 '22 08:04 timsofteng

You can make a pr to fix that :))

bryant-the-coder avatar Apr 24 '22 09:04 bryant-the-coder

I actually think I have a fix for this

Edit: PR soon (hopefully) :sunglasses:

Second edit: Taking a bit longer than planned due to some life stuff. But should be up for review this week

OkelleyDevelopment avatar May 09 '22 03:05 OkelleyDevelopment

nice nice

bryant-the-coder avatar May 09 '22 06:05 bryant-the-coder

@OkelleyDevelopment Hello! Any updates around this issue?

timsofteng avatar May 27 '22 21:05 timsofteng

@timsofteng @bryant-the-coder

Heyo !

After several weeks of trying to figure out the best approach to this issue (while ensuring we don't break other users experiences), I arrived at the solution below for getting JS snippets in TS:

image

Though I agree we could probably streamline some of these snippets, but it is a much larger endeavor than I was realizing and I do not wish to cause issues with compatibility for other users (at least not without a solid plan of what we are doing :sweat_smile: )

OkelleyDevelopment avatar Jun 01 '22 01:06 OkelleyDevelopment

Maybe I'm over thinking it, but the issue I'm running into is that JS snippets are useful in TS though some people might only want the TS specific snippets which brings me back to the "just extend it with your snippet engine" answer :thinking:

Edit: For those who do want both types of snippets loaded

Edit 2 on Oct. 18, 2022: I'm thinking about the best way to handle this issue. Might start a draft PR and just get input as we go.

Edit 3: If anyone has ideas, go ahead and try them. My free time seems to be fleeting at best the last few weeks :sweat:

OkelleyDevelopment avatar Jun 01 '22 01:06 OkelleyDevelopment

This is what I did too: https://github.com/rafamadriz/friendly-snippets#add-snippets-from-a-framework-to-a-filetype

For those who want to copy and paste:

require'luasnip'.filetype_extend("typescript", { "javascript" })

mauroporras avatar Dec 18 '22 22:12 mauroporras