Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal: Generic script with embedded language support in .NET #34821

Closed
VBAndCs opened this issue Apr 7, 2019 · 11 comments
Closed

Proposal: Generic script with embedded language support in .NET #34821

VBAndCs opened this issue Apr 7, 2019 · 11 comments
Labels
Area-Interactive Interactive-ScriptingLogic Resolution-External The behavior lies outside the functionality covered by this repository Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Milestone

Comments

@VBAndCs
Copy link

VBAndCs commented Apr 7, 2019

I saw many proposals to add XML literals or JSON support in C#, which are rejected. I have an idea to support any type of literals with embedded language code without altering the langue syntax!
Suppose we have a method named EmbeddedScript.Parse, used like this:

var es = new EmbeddedScript();
var n = 1;
var html =es.Parse(ScriptType.Html, 
                  "<p>test <%= n %></p>";

This should evaluated as:
<p>test 1</p>

Another suggestion for the syntax is:

Dim x = "test"
Dim s As string = $.JavaScript
"var I =5;
document.writeln({x});"

where $ is the interpolated string symbol, and JavaScript is the editor we want to use to format, color, validate and auto-complete the tokens inside the string. We can also use:
$.Html, $.CSS, $.JSON, $.CS, $.FS, $.Razor, $.XML (this one will makes the interpolated string literal acts as the XML literal)… etc.
XML literal can also benefit from this, by using and editor attr like this:

dim x = <zml editor="Html">

</zml>

These are the rules:

  1. embed language code in <%= n %>. But EmbeddedScript can have properties like StartQute and EndQuote to set the start and end embed quotes, so every one can use the scheme he like most.

  2. The ScriptType enum can have values for Html, XML, JSON, Js, String, and any other formula supported. It also can contain CSharp, VisualBasic, FSharp... etc, to allow use some pieces of another language with embedded expression with the current one. The Return Value of the Parse method should be an interface that have a Value property to return the evaluated expression.
    Another way, is to have EmbeddedScript.ParseHtml, EmbeddedScript.ParseXml, EmbeddedScript.ParseVB..... etc methodes, with syitable return types.
    Maybe it can have a UserDefined to use a new script but this needs setting rules on how to define it to Roslyn.

  3. The script is written as a string, and parsed to the desired type like XElement, HtmlElemnt, Json, String , etc. So, it is not a part oc C# ,VB or F# syntax.

  4. Roslyn is supposed to handle the script witten in the string quotes, to offer intellisnese and syntax check. Most of this work is already done in Html, xml, Json editors, So, put it in action ion this scope.

  5. C# or VB evaluates the embedded expressions only and the parsing process is done by the EmbeddedScript.Parse, which, I think, is a matter of calling some CoreFx methods.

  6. If the script depends on some other data like an xsd file for xml, we can point to its path in a EmbeddedScript.Resources property and reference its key in the xmln namespace.

  7. Embeded C# or VB inside a closed quotes should allow us to write any of these:
    a. an expression like <%= n %>
    b. implicit function like:

<%= var x = 10; 
          return n + x;%>

c. implicit enumerator like

<%= foreach (x in arr) 
             yield return <p>n + x</p>
%>

d. a block of code to define som vars used in other embedded expression, and return "" is assumed:

<div>
    <p>test <%=  n %></p>
    <%= n += 1; %>
    <p>test <%=  n %></p>
</div>

These are the basics, and you can refine these rules as desired.
I think this idea can offer powerful tools to .net languages, and will save many future efforts to embrace new kind of scripts.
In fact this idea came to me because I am suffering now to find away to add intellisense support for THML written inside xml literals in VB. VS.NET has all the tools but I don't find an easy way to apply them on xml literals without writing a new editor factory with C++! Why write a new useless editor while VS already has editors for nearly every thing?

@VBAndCs VBAndCs changed the title Proposal: Generic script with embeded language support in .NET Proposal: Generic script with embedded language support in .NET Apr 7, 2019
@CyrusNajmabadi
Copy link
Member

I saw many proposals to add XML literals or JSON support in C#, which are rejected. I have an idea to support any type of literals with embedded language code without altering the langue syntax!
Suppose we have a method named EmbeddedScript.Parse, used like this:

You can already do this today.

Just use FormattableStrings and template literals. Other languages/platforms environments (like JavaScript) already have libraries like this like so: https://wesbos.com/template-strings-html/

So there's no real need to introduce yet another way to do this when the language already shipped hte feature for this purpose.

These are the rules: embed language code in <%= n %>. But EmbeddedScript can have properties like StartQute and EndQuote to set the start and end embed quotes, so every one can use the scheme he like most.

Why? The language already has $" ... { } ... " to let you embed code in the middle of a literal. Just use that.

VS.NET has all the tools but I don't find an easy way to apply them on xml literals without writing a new editor factory with C++

The language shouldn't add redundant features just because you don't want to write a VS plugin.

@VBAndCs
Copy link
Author

VBAndCs commented Apr 7, 2019

You can already do this today.

No, I can't. There is no editor support to the script I am writing on the string. This proposal is about that: give us syntax check, coloring and auto complete for the script type we write in the string, as specified by the properties of the EmbeddedScript object.

when the language already shipped the feature for this purpose.

Where is that? Is there is an example to achieve what I mentioned above?

Why? The language already has $" ... { } ... " to let you embed code in the middle of a literal. Just use that.

Not enough. If I want to design a HTML page with xml literals it is impossible to remember all tag and attribute names without intellisense support. This is the major problem I am facing in Vazor now . Noting that I have some support for xml structure in VB, but it is not enough. So, what about plain text?

The language shouldn't add redundant features just because you don't want to write a VS plugin.

The language should fulfill the needs for its developers. This is a repeated request, and all the components to make it exists and just need to be put in place. Besides, this is not about one language. It is a core feature that should be built in Roslyn and VS.Net to make intellisnse truly (intelli)gent and (sens)ible to make the life of programmers easier.

@CyrusNajmabadi
Copy link
Member

No, I can't. There is no editor support to the script I am writing on the string. This proposal is about that: give us syntax check, coloring and auto complete for the script type we write in the string, as specified by the properties of the EmbeddedScript object.

How would that work?

Not enough. If I want to design a HTML page with xml literals it is impossible to remember all tag and attribute names without intellisense support. This is the major problem I am facing in Vazor now . Noting that I have some support for xml structure in VB, but it is not enough. So, what about plain text?

Then write a VS plugin. How would roslyn know all the tags and attribute names here?

Besides, this is not about one language. It is a core feature that should be built in Roslyn and VS.Net to make intellisnse truly (intelli)gent and (sens)ible to make the life of programmers easier.

This feature already exists. Roslyn Completion is extensible. So you can add your own completion providers.

This is desirable so that Roslyn itself doesn't have to be in the job of understanding every random language you want to plug into it. Instead, you can supply the VS and Roslyn plugins to do this. That's the idea. To make it so that you can put in the legwork here for the languages you care about, instead of expecting Roslyn (and the limited dev team it has) to do it for you.

The language should fulfill the needs for its developers.

Yes, and both the language and the tooling is extensible here so that the work can be distributed to provide these features. Otherwise, you're just saying "hey... roslyn needs to go implement and support all these languages". That's just not cost effective. If there's a language you care about, put in the legwork and effort to make it happen. If you think that's too costly for you, then ask yourself why the roslyn team would think it wasn't too costly for them.

@VBAndCs
Copy link
Author

VBAndCs commented Apr 8, 2019

This feature already exists. Roslyn Completion is extensible. So you can add your own completion providers.

You are asking for app developer to convert to a environment/language designer. This is a waste of time and resources . This is not the layer most developers work in. Besides, there is a limited resources about these topics. I wasted days searching in vain, and the extendvs room you told me about is nearly empty, and I got no answer. The worst thing is that editor factories are written in C++. Why should thousands of developers reinvent the wheel every time they face something like that?

How would that work?
How would Roslyn know all the tags and attribute names here?

Roslyn should know nothing about that.. All I want is to make Roslyn reuse the plugins it already has. This is how:

  • Roslyn sees EmbeddedScript.ParseHtml("<html></html>")
  • ParseHtml can have an HtmlParser attribute, so that Roslyn knows that this string should be delivered to the HTML editor. Suppose this string as if it is .html document and let the editor handle it. only the parts between <%= %> are treated as a part of the language as you do tin interpolated strings.
  • Same goes for ParseXml, ParseJSON, PaseVB... etc. All these editor already exist in VS.NET. All I am asking is to apply them on sub-documents. If this is not possible some how, there is a simple trick to use: crate a hidden file, copy the string to it (you can mask the embedded language parts somehow) and apply the editor on this file, and take the results back to apply on the original string.
    If you want to do it, you will find a way.

@CyrusNajmabadi
Copy link
Member

You are asking for app developer to convert to a environment/language designer. This is a waste of time and resources .

You are asking for roslyn devs to have to implement language support for all languages you want, regardless of their knowledge or experience of that language. You're also asking the roslyn team to take on the cost of implementing and maintaining all that work.

This is not the layer most developers work in.

This is not the layer Roslyn devs work in either. The layer roslyn devs work in is to make the extensible platform to make it possible for other to plug in like this.

That's why the Editor team, for example, doesn't implement the language support. They just make the extensibility system and core pieces.

I wasted days searching in vain, and the extendvs room you told me about is nearly empty, and I got no answer.

You got no answer because your questions were vague and open ended. No one is going to do your homework for you. You need to do a lot of legwork on your own. And when you run into problems, you'll need to dig a lot and provide a lot of information to help others so that they don't just have to vaguely guess in the dark as to what problem you were having.

The worst thing is that editor factories are written in C++. Why should thousands of developers reinvent the wheel every time they face something like that?

Roslyn isn't C++. You can implement a completion provider in managed code.

Roslyn should know nothing about that.. All I want is to make Roslyn reuse the plugins it already has.

Roslyn has no plugins for html editing.

This is how:

Roslyn sees EmbeddedScript.ParseHtml("<html></html>")
ParseHtml can have an HtmlParser attribute, so that Roslyn knows that this string should be delivered to the HTML editor.

Roslyn has nothing to do with the html editor.

Suppose this string as if it is .html document and let the editor handle it. only the parts between <%= %> are treated as a part of the language as you do tin interpolated strings.

Again, you can do that today with interpolated strings.

Same goes for ParseXml, ParseJSON, PaseVB... etc. All these editor already exist in VS.NET.

VS.net is not roslyn. You have the layering reversed.

All I am asking is to apply them on sub-documents. If this is not possible some how, there is a simple trick to use: crate a hidden file, copy the string to it (you can mask the embedded language parts somehow) and apply the editor on this file, and take the results back to apply on the original string.

If you want to do it, you will find a way.

Sounds like you know how to do it. I would recommend making a prototype demonstrating how this would work. If desirable, it might get picked up.

@CyrusNajmabadi
Copy link
Member

I wasted days searching in vain,

You searching in vain is not a reason for others to do work for you. I don't get how that's a valid argument at all.

and the extendvs room you told me about is nearly empty, and I got no answer.

There are around 20 people there. They commonly answer many questions every week. But you'll notice that a common aspect of questions is that they they are focused, specific, and solution-oriented. They're not questions like:

image

First, it's very unclear what you even want. Second, you haven't explained what you've even tried, or what existing APIs you've used. Third, you finish with a vague 'how can i do it?'.

You need to really explain to people what you're trying to accomplish. You need to show how far you've been able to get, but where you've reached a blocked point. You'll have to show what you've tried to do to address this, but why they haven't worked. Finally, you should offer some ideas on how you think you might be able to solve things, with specific questions looking for the help you need from the experts in this topic.

--

With your last github account, you would commonly open Roslyn issues asking people to just do work for you. IIRC, pretty much all of them went absolutely nowhere. You're now doing it again, but also doing it for VS plugins. This simply won't get anywhere. No one on the team is going to sign up for this work, and no one on the extensibility team will be able to help you without more details.

@VBAndCs
Copy link
Author

VBAndCs commented Apr 8, 2019

Thanks for your response.

@bjorn-ali-goransson
Copy link

Hi,

I commend your massive effort to research previous tickets related to this feature. I made one of those. But I think we have reached ways' end here.

Perhaps the best way for you would be to use razor as an xml generator?

Also, for the record, if we would stop to talk about jsx for a moment, then that's just a transpiling (?) step before js gets executed the normal way. It's not got anything to do with the javascript language engine(s) per se.

It seems that the best fit for your development style is not .NET Core and related technologies, but traditional ASP.NET WebForms in .NET
Framework.

Nothing wrong with that, but keep in mind that times have changed and people (to a large extent) have left many of those paradigms behind. Tight coupling of backend code with frontend logic is one of those paradigms, which seem to have had a large impact on you (as well as me).

All the best!

@VBAndCs
Copy link
Author

VBAndCs commented Apr 8, 2019

@bjorn-ali-goransson
The idea behind Vazor is to use existing tools to create ASP.MET Core apps with vb.net, both MVC and Razor pages. You can use cshtml views or use vbxml views instead or mix between them in the same project. You can find working samples here
https://github.com/VBAndCs/Vazor
I will publish project and item templates today.
I dont get what you mean by

Tight coupling of backend code with frontend logic

Razor Pages apps has brought this model back, claming that there is bo real separation betwwn model and view in practice. Anyway, this is not the concern of this proposal. I can get html intellisense in xal literals by using an xsd schema. It is supposed to work! I reported this in a previous issue and waiting for feeadback. Untill then, I am using the open with command from the solution explorer to open my vbxml files in html editor, and it does the purpose. So, I have many workarounds to go with.
The goal of this proposal is to be able to generate dynamic scripts within c# and vb.net, with full support of the editor. This can be done in a plain text. Or by writting tens of vs extensions, but I am seeking for a smart way to generalize the process to reuse the already existing editors (inspired by Vazor approach).

@vatsalyaagrawal vatsalyaagrawal added this to the Backlog milestone Apr 8, 2019
@vatsalyaagrawal vatsalyaagrawal added the Need Design Review The end user experience design needs to be reviewed and approved. label Apr 8, 2019
@VBAndCs
Copy link
Author

VBAndCs commented May 5, 2019

Another suggestion for the syntax is:

Dim x = "test"
Dim s As string = $.JavaScript
"var I =5;
document.writeln({x});"

where $ is the interpolated string symbol, and JavaScript is the editor we want to use to format, color, validate and auto-complete the tokens inside the string. We can also use:
$.Html, $.CSS, $.JSON, $.CS, $.FS, $.Razor, $.XML (this one will makes the interpolated string literal acts as the XML literal)… etc.
XML literal can also benefit from this, by using and editor attr like this:

dim x = <zml editor="Html">

</zml>

I will edit the original proposal to add this.

@CyrusNajmabadi
Copy link
Member

Not enough. If I want to design a HTML page with xml literals it is impossible to remember all tag and attribute names without intellisense support. This is the major problem I am facing in Vazor now .

Closing out. As mentiond in other conversations, completion/intellisense is something completely supported for third parties using the CompletionProvider API. So, as per the discussions above, this can be done by using template literals, embedding whatever you want in them, and then writing teh appropriate completion plugins to give you things like "tag and attribute names". This should be sufficient for your vazor effort.

@CyrusNajmabadi CyrusNajmabadi added Resolution-External The behavior lies outside the functionality covered by this repository and removed Feature Request labels Mar 26, 2020
@CyrusNajmabadi CyrusNajmabadi added Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented and removed Need Design Review The end user experience design needs to be reviewed and approved. labels Mar 26, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Interactive Interactive-ScriptingLogic Resolution-External The behavior lies outside the functionality covered by this repository Resolution-Fixed The bug has been fixed and/or the requested behavior has been implemented
Projects
None yet
Development

No branches or pull requests

4 participants