Giter VIP home page Giter VIP logo

intellij-wgsl's Introduction

intellij-wgsl

Build Version Downloads

This plugin adds syntax highlighting support for WGSL - the WebGPU Shading Language.

Open a wgsl file in your IntelliJ based IDE and marvel at the pretty colours.

Installation

  • Using IDE built-in plugin system:

    Settings/Preferences > Plugins > Marketplace > Search for "WGSL Support" > Install Plugin

  • Manually:

    Download the latest release and install it manually using Settings/Preferences > Plugins > โš™๏ธ > Install plugin from disk...

intellij-wgsl's People

Contributors

actions-user avatar arc-blroth avatar arthomnix avatar chuk-uzowihe avatar dparnell avatar holgergottchristensen avatar rosingrind avatar simonbuchan avatar uriopass avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

intellij-wgsl's Issues

Support preprocessor #ifdef, #define, ...

Thanks a lot for this plugin! I was wondering if you could support syntax highlighting preprocessor directives, as some WGSL variants use them, for example WGSL in Bevy:

image

Allow more navigation and refactoring actions?

I just realized that I can actually Rename local variables, which is really cool. That made me wonder how many other IDE features could easily be done. On the very top of my wish list would be

  • Rename structs
  • Go to Declaration

as I use them all the time. Just making them work in the local file would be helpful already. If "Go to Declaration" could even work across all files that would be absolutely fantastic. For my purposes I think this could even be done without needing to understand #import and friends; just scanning all .wgsl files and providing a selection popup like below would allow me to 1) discover and 2) pick the right one by hand.

image

Fix matrix trailing space issues

Writing something like:
let model_matrix = mat4x4<f32>( instance.model_matrix_0, instance.model_matrix_1, instance.model_matrix_2, instance.model_matrix_3, );
causes red thingies to pop up and formatting to get messed up, removing the trailing semicolon fixes these issues

Auto-format

Thanks for your work on the plugin so far. I'd love to be able to run the format shortcut in the IDE and have my WGSL shaders formatted. Is this functionality on your roadmap?

[BUG] ">>" - Syntax error that isn't an error

struct ModelUniform {
    model: array<mat4x4<f32>>,
};

It outputs WGSLTokenType.GREATER_THAN expected, got '>>' at the >>

Inserting a space in-between the 2 > characters, the error disappears.

Add support for `const` keyword

Currently writing const looks like an other invalid expression, fix this by adding support for the const keyword and thus const expressions

Nested array issue

First of all, awesome plugin!

I'm noticing some odd behaviour with nested arrays:
image

Adding a space between the brackets solves the issue.

Icon placeholder(?) in "Quick Documentation"

Being able to invoke "Quick Documentation" (F1 in my key binding) on attributes is great, and I like that I can read the specification text. The only nit is there is a small weird icon placeholder showing up too:

image

Argument for @NotNull parameter 'lookupString' of LookupElementBuilder.create must not be null

Summary

This particular bug is not easy to reproduce continuously as I'm doing fix for it, so pardon me if my sample shader is a bit huge. I've encountered it as I'm working with bevy samples, this was the first one I'm experiencing bug with as I'm editing it

  • reproducible on IC-2022.3 and higher
  • take an example shader listed below and place any character on marked position
fn oklab_to_linear_srgb(c: vec3<f32>) -> vec3<f32> {
    let L = c.x;
    let a = c.y;
    let b = c.z;
    let b = ; // <- place any character here

    let l_ = L + 0.3963377774 * a + 0.2158037573 * b;
    let m_ = L - 0.1055613458 * a - 0.0638541728 * b;
    let s_ = L - 0.0894841775 * a - 1.2914855480 * b;

    let l = l_ * l_ * l_;
    let m = m_ * m_ * m_;
    let s = s_ * s_ * s_;

    return vec3<f32>(
        4.0767416621 * l - 3.3077115913 * m + 0.2309699292 * s,
        -1.2684380046 * l + 2.6097574011 * m - 0.3413193965 * s,
        -0.0041960863 * l - 0.7034186147 * m + 1.7076147010 * s,
    );
}

Stacktrace

java.lang.IllegalArgumentException: Argument for @NotNull parameter 'lookupString' of com/intellij/codeInsight/lookup/LookupElementBuilder.create must not be null
	at com.intellij.codeInsight.lookup.LookupElementBuilder.$$$reportNull$$$0(LookupElementBuilder.java)
	at com.intellij.codeInsight.lookup.LookupElementBuilder.create(LookupElementBuilder.java)
	at wgslplugin.language.WGSLBuiltInCompletionContributor.createStaticMethod(WGSLBuiltInCompletionContributor.java:54)
	at wgslplugin.language.WGSLBuiltInCompletionContributor.lambda$getKeywords$1(WGSLBuiltInCompletionContributor.java:47)
	at java.base/java.util.stream.ReferencePipeline$3$1.accept(ReferencePipeline.java:197)
	at java.base/java.util.HashMap$ValueSpliterator.forEachRemaining(HashMap.java:1779)
	at java.base/java.util.stream.AbstractPipeline.copyInto(AbstractPipeline.java:509)
	at java.base/java.util.stream.AbstractPipeline.wrapAndCopyInto(AbstractPipeline.java:499)
	at java.base/java.util.stream.ReduceOps$ReduceOp.evaluateSequential(ReduceOps.java:921)
	at java.base/java.util.stream.AbstractPipeline.evaluate(AbstractPipeline.java:234)
	at java.base/java.util.stream.ReferencePipeline.collect(ReferencePipeline.java:682)
	at wgslplugin.language.WGSLBuiltInCompletionContributor.getKeywords(WGSLBuiltInCompletionContributor.java:49)
	at wgslplugin.language.WGSLBuiltInCompletionContributor.fillCompletionVariants(WGSLBuiltInCompletionContributor.java:30)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributor(CompletionService.java:81)
	at com.intellij.codeInsight.completion.impl.CompletionServiceImpl.lambda$getVariantsFromContributor$1(CompletionServiceImpl.java:321)
	at com.intellij.diagnostic.telemetry.TraceKt.runWithSpan(trace.kt:74)
	at com.intellij.codeInsight.completion.impl.CompletionServiceImpl.getVariantsFromContributor(CompletionServiceImpl.java:320)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:73)
	at com.intellij.codeInsight.completion.CompletionResultSet.runRemainingContributors(CompletionResultSet.java:152)
	at com.intellij.codeInsight.completion.CompletionResultSet.runRemainingContributors(CompletionResultSet.java:144)
	at com.intellij.codeInsight.completion.CompletionResultSet.runRemainingContributors(CompletionResultSet.java:140)
	at com.intellij.codeInsight.template.impl.LiveTemplateCompletionContributor$1.addCompletions(LiveTemplateCompletionContributor.java:88)
	at com.intellij.codeInsight.completion.CompletionProvider.addCompletionVariants(CompletionProvider.java:23)
	at com.intellij.codeInsight.completion.CompletionContributor.fillCompletionVariants(CompletionContributor.java:155)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributor(CompletionService.java:81)
	at com.intellij.codeInsight.completion.impl.CompletionServiceImpl.lambda$getVariantsFromContributor$1(CompletionServiceImpl.java:321)
	at com.intellij.diagnostic.telemetry.TraceKt.runWithSpan(trace.kt:74)
	at com.intellij.codeInsight.completion.impl.CompletionServiceImpl.getVariantsFromContributor(CompletionServiceImpl.java:320)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:73)
	at com.intellij.codeInsight.completion.CompletionService.getVariantsFromContributors(CompletionService.java:56)
	at com.intellij.codeInsight.completion.CompletionService.performCompletion(CompletionService.java:132)
	at com.intellij.codeInsight.completion.BaseCompletionService.performCompletion(BaseCompletionService.java:40)
	at com.intellij.codeInsight.completion.impl.CompletionServiceImpl.lambda$performCompletion$2(CompletionServiceImpl.java:338)
	at com.intellij.diagnostic.telemetry.TraceKt.runWithSpan(trace.kt:74)
	at com.intellij.codeInsight.completion.impl.CompletionServiceImpl.performCompletion(CompletionServiceImpl.java:327)
	at com.intellij.codeInsight.completion.CompletionProgressIndicator.lambda$calculateItems$11(CompletionProgressIndicator.java:870)
	at com.intellij.util.indexing.FileBasedIndex.lambda$ignoreDumbMode$0(FileBasedIndex.java:202)
	at com.intellij.openapi.util.RecursionManager$1.computePreventingRecursion(RecursionManager.java:112)
	at com.intellij.util.indexing.FileBasedIndexEx.ignoreDumbMode(FileBasedIndexEx.java:723)
	at com.intellij.util.indexing.FileBasedIndex.ignoreDumbMode(FileBasedIndex.java:201)
	at com.intellij.util.indexing.DumbModeAccessType.ignoreDumbMode(DumbModeAccessType.java:43)
	at com.intellij.codeInsight.completion.CompletionProgressIndicator.calculateItems(CompletionProgressIndicator.java:866)
	at com.intellij.codeInsight.completion.CompletionProgressIndicator.runContributors(CompletionProgressIndicator.java:854)
	at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$startContributorThread$7(CodeCompletionHandlerBase.java:371)
	at com.intellij.codeInsight.completion.AsyncCompletion.lambda$tryReadOrCancel$5(CompletionThreading.java:169)
	at com.intellij.openapi.application.impl.ApplicationImpl.tryRunReadAction(ApplicationImpl.java:1086)
	at com.intellij.codeInsight.completion.AsyncCompletion.tryReadOrCancel(CompletionThreading.java:167)
	at com.intellij.codeInsight.completion.CodeCompletionHandlerBase.lambda$startContributorThread$8(CodeCompletionHandlerBase.java:363)
	at com.intellij.codeInsight.completion.AsyncCompletion.lambda$startThread$0(CompletionThreading.java:92)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$runProcess$2(CoreProgressManager.java:190)
	at com.intellij.openapi.progress.impl.CoreProgressManager.lambda$executeProcessUnderProgress$13(CoreProgressManager.java:591)
	at com.intellij.openapi.progress.impl.CoreProgressManager.registerIndicatorAndRun(CoreProgressManager.java:666)
	at com.intellij.openapi.progress.impl.CoreProgressManager.computeUnderProgress(CoreProgressManager.java:622)
	at com.intellij.openapi.progress.impl.CoreProgressManager.executeProcessUnderProgress(CoreProgressManager.java:590)
	at com.intellij.openapi.progress.impl.ProgressManagerImpl.executeProcessUnderProgress(ProgressManagerImpl.java:60)
	at com.intellij.openapi.progress.impl.CoreProgressManager.runProcess(CoreProgressManager.java:177)
	at com.intellij.codeInsight.completion.AsyncCompletion.lambda$startThread$1(CompletionThreading.java:88)
	at com.intellij.openapi.application.impl.ApplicationImpl$1.run(ApplicationImpl.java:246)
	at java.base/java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:539)
	at java.base/java.util.concurrent.FutureTask.run(FutureTask.java:264)
	at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
	at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:702)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1$1.run(Executors.java:699)
	at java.base/java.security.AccessController.doPrivileged(AccessController.java:399)
	at java.base/java.util.concurrent.Executors$PrivilegedThreadFactory$1.run(Executors.java:699)
	at java.base/java.lang.Thread.run(Thread.java:833)

`WGSLTokenType.LESS_THAN expected, got '('`

This code:

struct Vertex {
	@builtin(position) pos: vec4<f32>
}

@vertex
fn vs_main(@builtin(vertex_index) in_vertex_index: u32) -> Vertex {
	let x = f32(1 - i32(in_vertex_index)) * 0.5;
	let y = f32(i32(in_vertex_index & 1u) * 2 - 1) * 0.5;
	return Vertex(vec4(x, y, 0.0, 1.0));
}

@fragment
fn fs_main(in: Vertex) -> @location(0) vec4<f32> {
	return vec4(1.0, 0.0, 0.0, 1.0);
}

validates fine, but the plugin throws an error at the first vec4 because it incorrectly assumes that it must be qualified with <f32>.

Struct member separators: comma vs semicolon

I get a Chrome Canary warning about how the semicolon is deprecated as a struct member separator:
warning: use of deprecated language feature: struct members should be separated with commas

The current WGSL spec also specifies commas for struct member separation.

However this awesome WGSL plugin will cause a red error mark in the gutter: SEMICOLON expected, got ','

In the bnf:

struct_member ::=
--
74 | attribute_list* field SEMICOLON

EAP Support

When using the latest CLion EAP (CL-221.4906.7), the plugin is not listed in the Marketplace, and when I attempt to install it from disk, I get:

Plugin 'WGSL Support' (version '0.0.5') is not compatible with the current version of the IDE, because it requires build 213.* or older but the current build is CL-221.4906.7

I don't know what all (if anything) has changed between the versions, but if it's something as simple as editing the plugin manifest, it'd be nice to have support for EAP builds.

"Comment" action should toggle comment

The IDEs have a "Comment with Line Comment" action, which is available as a keybinding:

image

It would be great if the plugin supported this by toggling a line prefix of // when invoked.

Invalid type suggestions

There are invalid types that are suggested
e.g: texture_2d_array
some other types are int32 and uint32

Plugin not working anymore in newer IDE builds 232 or higher

Updated my Webstorm to Version 2023.2 and got this error

Plugin 'WGSL Support' (version '0.0.26') is not compatible with the current version of the IDE,
because it requires build 231.* or older but the current build is WS-232.8660.143

And I would like to take this opportunity to thank you for this helpful plugin =)

Highlighting breaks on "binding_array" declaration

I'm facing some problems with binding_array declarations.

With this code:

@group(0) @binding(0)
var example_binding: binding_array<texture_2d<f32>>;

I get the following error: WGSLTokenType.EQUAL or WGSLTokenType.SEMICOLON expected, got '<' on the first open angled bracket, and highlighting for the rest of the file is broken.

Support multi line import statements

When using bevy and their wgsl support, the imports could be multi line. Bellow is an example of that shows multi line import failing but a single line import works fine.

singleline

image

multiline

image

For-loops cause incorrect error

If I create a simple for-loop like the one from the WGSL spec, like so:

for(var i: i32 = 0; i < 4; i++) {
  if (a == 0) {
    continue;
  }
  a = a + 2;
}

Then intellij-wgsl will emit an error at the first plus of i++:

<postfix expression>, WGSLTokenType.EQUAL or WGSLTokenType.PAREN_LEFT expected, got '+'

I notice that wgpu doesn't seem to accept this syntax either, even though it's in the spec, so I am assuming this is a fairly recent change. Changing i++ to i = i + 1 works fine.

Wrong types get suggested

The plugin suggests me types called "float32" and "float16" if i type "f" although it should suggest "f32" and "f16" instead!

I'd like the option to set the WSGL Version.

No every library is always on the latest version and you have to use older syntax. It would be awesome if it didn't show up as deprecated because I could set the version I'm writing for.

Thanks for this awesome plugin!

Structs use comma now

In IDE I keep getting: WGSLTokenType.SEMICOLON expected, got ',' at the end of a struct field.

WGSL standard now defines shader structs with a comma rather than a semicolon.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.