durkiewicz / elm-plugin

Elm language support plugin for IntelliJ IDEA.
MIT License
136 stars 15 forks source link

Excluding webgl shader code #57

Closed francisdb closed 7 years ago

francisdb commented 7 years ago

First of all thanks for this great plugin!

It seems that the plugin can't handle shader code between [glsl| and |]. Marking everything with errors.

image

I guess it would not be too much work to ignore those blocks. Even better would be to enable https://plugins.jetbrains.com/idea/plugin/6993-glsl-support if installed? But I guess that will not be a simple undertaking?

durkiewicz commented 7 years ago

Thanks for feedback. Can you give me more information about this syntax? Is embedding external language code a standard feature of Elm compiler? What languages can you embed into Elm? Where can I find some documentation about it?

francisdb commented 7 years ago

No idea, all I know is that code between [glsl| and |] should be excluded. Maybe @w0rm can shed some light on this?

w0rm commented 7 years ago

[glsl| |] is a valid Elm code, that is supported by the Elm compiler, it should be syntax highlighted as the glsl language.

Is it possible to embed one language into another? I've opened a similar issue for the atom plugin here.

francisdb commented 7 years ago

@w0rm is this a generic thing where [javascript| ... |] could also be implemented by some library?

w0rm commented 7 years ago

@francisdb no, it's not generic. The Elm compiler has the glsl parser baked in for the WebGL stuff.

francisdb commented 7 years ago

thanks @w0rm , @durkiewicz do you know enough with this answer?

durkiewicz commented 7 years ago

Ok, so now I know that I can use GLSL code as expressions in Elm code. Are there some restrictions to that? Can I, for example, write:

f x =
    case x of
        A -> 1
        B -> [glsl| ... |] + 5

Or is it limited to defining the whole body of a function? Can I use GLSL code as a non-expression code? If so, can you give me a complete list of allowed usages?

durkiewicz commented 7 years ago

IntelliJ has a feature of language injection: https://www.jetbrains.com/help/idea/2016.3/using-language-injections.html So if I make sure that the content of [glsl| ... |] is parsed as a string in Elm plugin then you should probably be able to use the feature of language injection in order to use GLSL tooling.

francisdb commented 7 years ago

Just tried some things:

    let
        foo =
            [glsl|
             attribute vec3 position;
             |]

        bar =
            foo + 1

defining foo works, of course adding 1 fails

The left argument of (+) is causing a type mismatch.

149|             foo + 1
                 ^^^
(+) is expecting the left argument to be a:

    number

But the left argument is:

    Shader { a | position : Vec3 } b {}
francisdb commented 7 years ago

Thanks for taking care of this @durkiewicz ! 🙌