ipatalas / vscode-postfix-ts

Postfix notation for TypeScript/Javascript - extension for VS Code
MIT License
158 stars 43 forks source link

as typescript language service #13

Open cancerberoSgx opened 6 years ago

cancerberoSgx commented 6 years ago

sorry, this is not an issue but I want to share this idea with you. It would be interesting to implement this idea as a typescript language service plugin so it works on any editor supporting it (there are a lot now, vscode, atom, emacs, vim, webstorm, sublime, eclipse etc. ). I have experience with this technology, and for integrating with vscode, besides config contribution point is just a matter of using https://code.visualstudio.com/docs/extensionAPI/extension-points#_contributestypescriptserverplugins

well, just that, congrats, and keep it up! :)

ipatalas commented 6 years ago

The idea itself is great. However I don't have much time for this extension recently. I will consider it in future though. Unless you wanna help since you have experience in that like you said :)

cancerberoSgx commented 6 years ago

Hi! Nice you like it, I don't have much free time myself neither but taking notes for the future, thanks! could you please leave this open as a reminder? Thanks,

ipatalas commented 6 years ago

I will. Otherwise I would forget too :-)

ipatalas commented 6 years ago

Well. Had some thinking about it and I'm not sure if it can be achieved now. It's not a simple auto completion, it does more than that. It actually replaces whole expression with something else. Vscode API gives such possibility, not sure about language service plugin. I will have to check that first. Additionally the .not template is much more complicated as it allows you to dynamically select which part of the expression one wants to invert. This will need some additional research first, leaving the comment for future me so that I know where to dig.

cancerberoSgx commented 6 years ago

With TypeScript Language Service you have access to the code AST - you can transverse it and modify it make code completions, and refactor suggestions to the user according to wheree the cursor or selection currently is. What you don't have is interactive GUIs besides the autocomplete or refactor suggestions that the editor automatically implement. Aall the user input you can have is the user's cursor or selection. NeverthelessI don't think in your extension you never ask the user anything interactively right ? I can make an example of one of your's ideas (probably the console log which I think is awesome) so you better understand the concept.

Also besides TypeScript Language Service, there is another much standard technology (which I don't grasp yet) https://microsoft.github.io/language-server-protocol/ which supports autocomplete. If you can implement it with that then your extension would work universally, and not only for typescript could be for any language and IDEs that support it: https://microsoft.github.io/language-server-protocol/implementors/tools/ - I mean, you program once, and it will work on all those IDEs - packaging it for each should be trivial. Since you already make it kind of language agnostic because of template support I would also recommend we also consider that. :)

cancerberoSgx commented 6 years ago

I saw the .not thing... mmm .. I like this postfix-thing because is agile and you can wrap an expression intelligently without having to modify the cursor position, but in .not (as shown by the gif) an artificial vscode dialog appears . Why didn't you shown a autocomplete / refactor suggestion instead ?

That dialog you show artificially with vscode api cannot be done nor with typescript language service or language server protocol (is a vscode technology) but I think the implementation of asking the user which expression to choose should still be done using auto completion / refactor suggestions ! my point is - it can be done and would be much consistent.

(just my opinion) nice work BTW keep it up and thanks

cancerberoSgx commented 6 years ago

The ugly thing or something that will be not a nice experience as your actual extension experience will be template definition / configuration / settings. The only thing I could think of right know to make that work in an IDE agnostic extension using both typescript language service or language server protocol, is a text file - probably json, yaml or xml .

ipatalas commented 6 years ago

That's great. Your workaround for not template seems perfect. Traversing TypeScript AST is what I do right after breakfast so it shouldn't be a problem.

However if you can prepare or find an example for simple console log that would be great. It would allow me to judge the effort needed to implement this change. Thanks for feedback.

cancerberoSgx commented 6 years ago

I'm implementing .let . BTW with .let you also have the same problem as with .not in regard of deciding to which (sub) expression do you want to declare as variable. for example:

function f(a, b, c, foo) {
  if (a < b)
    return a > 3 * foo.bar.alf && b < c.let
}

.let could be applied to any sub expression or to the bigger one, for example:

In my example I'm assuming is the bigger one i don't want to complicate things right now... will let you know when I have something

ipatalas commented 6 years ago

You're right. I didn't think of that because I've been always using it in unambiguous scenarios. Same applies to const, var and probably some others as well. You're right though, no need to worry about that for now. Let's see how a simple scenario works first.

ipatalas commented 6 years ago

Hi, any progress on that?

cancerberoSgx commented 6 years ago

yes - i have a working example - with a couple of issues from POV of user experience - i'm recording screencast and sharing with you the code - give me coupe of minutes...

ipatalas commented 5 years ago

It's already been a couple of minutes, wasn't it? :) Can you share some of your work on that? I could try handling it myself but need something to start with.

cancerberoSgx commented 5 years ago

It's already been a couple of minutes, wasn't it? :)

already ? :)

sorry I stop working on typescript compiler related projects... but this was my progress - I remember that was basically working fine but there were some issues with the cursor position or something like that made me consider not ready

https://github.com/cancerberoSgx/typescript-plugins-of-mine/tree/master/typescript-plugin-postfix

in those days I learn a lot about ts compiler api and plugins and I really not sure If that project is useing the best techniques - ping me your are blocked try to reserve some time and make it work in vscode and atom - sorry for the delay man

cancerberoSgx commented 5 years ago

just remember that also I think I was too ambitious with configuration , templates for postfix and focused on that API and not on important things like solving the detail described in my previous comment.... I mean - how should users can define new postfix with templates ? how users can define names for postfix autocompletion. And most importantly - where this configuration should live ? My guess is at $HOME ? but could also be per project ? if you go this way you will need to design those experiences since there won't be an editor extension anymore ?Also I recommend to re-check the protocols API since they are adding features there like crazy - perhaps there is an api for preferences ?

ipatalas commented 5 years ago

All right. Thanks. I'll take a look on that soon and decide whether it makes sense to put my effort into that.

zardoy commented 2 years ago

Hey! I've recently added a web support to my extension that is powered by big TypeScript plugin and it seems to be working!

Benefits of moving extension code to TS plugin:

  1. Smaller extension size, probably faster startup times. This is because it would reuse typescript module from the TypeScript extension. However there is another approach to achieve it.
  2. Easily make it work in the web (IMO not a big deal)
  3. And the biggest one is deeper integration with TypeScript project context e.g. we can display templates only if imported variable meets some type requirements. I think this is the only a reason to do that.

Example: display moreArr only on identifiers that assignable to array type.

VSCode Context

As I mentioned above moving it to language service almost has no benefits for vscode extension. Also builtin TS support in VSCode doesn't allow to add custom postfix completions (they will not be displayed) https://github.com/microsoft/vscode/issues/152607#issue-1276215298:

Not sure for now how we can preserve support for custom languages (e.g. Vue, Svelte), I need to think about. It's definitely possible via adding them to project as vscode-typescript-vue-plugin does it.

Other IDE

It would be interesting to implement this idea as a typescript language service plugin so it works on any editor supporting it (there are a lot now, vscode, atom, emacs, vim, webstorm, sublime, eclipse etc. ).

I'm not sure for now how it can be done. For example I've found no way to do it WebStorm plugin for now.