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

Improve ShaderLab compilation error log and package build #2364

Open
wants to merge 82 commits into
base: dev/1.4
Choose a base branch
from

Conversation

Sway007
Copy link
Member

@Sway007 Sway007 commented Aug 27, 2024

Please check if the PR fulfills these requirements

  • The commit message follows our guidelines
  • Tests for the changes have been added (for bug fixes / features)
  • Docs have been added / updated (for bug fixes / features)

What kind of change does this PR introduce? (Bug fix, feature, docs update, ...)

change rollup config to produce 2 version ShaderLab package dist: Release and Editor.

// use release version
import { ShaderLab } from "@galacean/engine-shader-lab"

// use editor version

// umd
import { ShaderLab } from "@galacean/engine-shader-lab/dist/browser.editor";
// esmoudle
import { ShaderLab } from "@galacean/engine-shader-lab/dist/module.editor";
// commonjs
import { ShaderLab } from "@galacean/engine-shader-lab/dist/main.editor";

Improve the error log when compiation error of ShaderLab occur in Editor version.

6 errors occur!
ShaderLab.ts:167
CompilationError: Invalid engine constant: BlendFactor.SourceAlph22

|···                BlendState {
|···                  Enabled = true;
|···                  SourceColorBlendFactor = BlendFactor.SourceAlph22;
                                                           ^^^^^^^^^^^^
|···                  DestinationColorBlendFactor = BlendFactor.OneMinusSourceAlpha;
|···                  SourceAlphaBlendFactor = BlendFactor.One;

CompilationError: Invalid render queue Transparent22

|···                  WriteEnabled = false;
|···                }
|···                RenderQueueType = Transparent22;
                                      ^^^^^^^^^^^^^
|···              #else
|···                BlendState {

CompilationError: Invalid "BlendState" variable: blendState

|···              #endif
|···
|···              BlendState = blendState;
                               ^^^^^^^^^^
|···
|···              mat4 renderer_MVPMat;

CompilationError: undeclared identifier:attr2

|···                Varyings v;
|···              
|···                gl_Position = renderer_MVPMat * attr2.POSITION;
                                                    ^^^^^
|···                none();
|···                v.v_pos = gl_Position.xyz;

CompilationError: No overload function type found: none

|···              
|···                gl_Position = renderer_MVPMat * attr2.POSITION;
|···                none();
                    ^^^^^^
|···                v.v_pos = gl_Position.xyz;
|···                v.v_uv = attr.TEXCOORD_023;

CompilationError: referenced attribute not found: TEXCOORD_023

|···                none();
|···                v.v_pos = gl_Position.xyz;
|···                v.v_uv = attr.TEXCOORD_023;
                                  ^^^^^^^^^^^^
|···                return v;
|···              }

In Release version, ShaderLab will immediately terminate the compilation and throw when encountering an error.

related issue: #2248

Summary by CodeRabbit

Summary by CodeRabbit

  • New Features

    • Enhanced error handling across various components, improving clarity and robustness in shader processing and compilation.
    • Introduced new methods for better error tracking and reporting, including scanToCharacter and reportError.
    • Added support for more complex built-in functions with updated signatures.
    • Introduced a new shader for physically-based rendering with configurable properties.
  • Bug Fixes

    • Improved handling of shader parsing errors and compilation issues, ensuring more informative error messages.
  • Documentation

    • Updated ShaderLab documentation to clarify differences between Release and Debug versions, including import instructions.
  • Chores

    • Streamlined build process in configuration files to enhance flexibility based on development environments.
    • Adjusted import paths in test files for improved module structure.

Copy link

coderabbitai bot commented Aug 27, 2024

Walkthrough

The changes encompass modifications across various files in the shader lab project, focusing on error handling improvements, build command simplifications, and enhancements to documentation. Key updates include the consolidation of build scripts, the introduction of new error handling mechanisms, and the refinement of testing frameworks. Additionally, shader parsing capabilities have been enhanced, and new shader files have been added to support physically-based rendering.

Changes

Files Change Summary
.github/workflows/ci.yml, package.json Updated build commands and removed editor-specific npm scripts.
packages/shader-lab/README.md Enhanced documentation on release and debug versions of ShaderLab.
packages/shader-lab/src/Error.ts, packages/shader-lab/src/ShaderLab.ts, packages/shader-lab/src/Utils.ts, packages/shader-lab/src/codeGen/CodeGenVisitor.ts, packages/shader-lab/src/codeGen/GLESVisitor.ts, packages/shader-lab/src/parser/SemanticAnalyzer.ts Improved error handling mechanisms and logging capabilities.
packages/shader-lab/src/contentParser/ShaderContentParser.ts, packages/shader-lab/src/preprocessor/PpParser.ts Introduced conditional error reporting based on editor mode.
rollup.config.js, tests/src/shader-lab/Preprocessor.test.ts, tests/src/shader-lab/ShaderLab.test.ts Modified build configurations and updated test imports and structures.
tests/src/shader-lab/shaders/compilation-error.shader Added new shader file for physically-based rendering with configurable properties.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ShaderLab
    participant ErrorHandler
    participant Logger

    User->>ShaderLab: Parse Shader
    ShaderLab->>ErrorHandler: Check for Errors
    ErrorHandler->>ShaderLab: Report Errors
    ShaderLab->>Logger: Log Errors
Loading

🐇 In the meadow where shaders play,
A rabbit hops and cheers today!
With scripts refined and errors tamed,
Our shaders dance, no longer blamed.
So here's to builds that run so bright,
Let's hop along and code with delight! 🌟


Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

Share
Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai generate interesting stats about this repository and render them as a table.
    • @coderabbitai show all the console.log statements in this repository.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@Sway007 Sway007 self-assigned this Aug 27, 2024
@Sway007 Sway007 added enhancement New feature or request Rendering Rendering related functions shader Shader related functions high priority High priority issue labels Aug 27, 2024
@Sway007 Sway007 marked this pull request as ready for review August 28, 2024 01:49
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 9

Outside diff range, codebase verification and nitpick comments (1)
packages/shader-lab/README.md (1)

31-31: Fix grammatical issues.

The sentence should be: "You can use the debug version by importing it as follows:"

Apply this diff to fix the grammatical issues:

-you can use debug version by import:
+You can use the debug version by importing it as follows:
Tools
LanguageTool

[uncategorized] ~31-~31: You might be missing the article “the” here.
Context: ...ides superior performance. you can use debug version by import: ```ts // umd import...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~31-~31: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...formance. you can use debug version by import: ```ts // umd import { ShaderLab } fro...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 337ba2e and c679a9e.

Files selected for processing (30)
  • .github/workflows/ci.yml (3 hunks)
  • package.json (1 hunks)
  • packages/shader-lab/README.md (1 hunks)
  • packages/shader-lab/src/Error.ts (1 hunks)
  • packages/shader-lab/src/ShaderLab.ts (6 hunks)
  • packages/shader-lab/src/Utils.ts (2 hunks)
  • packages/shader-lab/src/codeGen/CodeGenVisitor.ts (3 hunks)
  • packages/shader-lab/src/codeGen/GLES100.ts (1 hunks)
  • packages/shader-lab/src/codeGen/GLESVisitor.ts (5 hunks)
  • packages/shader-lab/src/codeGen/VisitorContext.ts (3 hunks)
  • packages/shader-lab/src/common/BaseScanner.ts (5 hunks)
  • packages/shader-lab/src/common/BaseToken.ts (1 hunks)
  • packages/shader-lab/src/common/ShaderPosition.ts (1 hunks)
  • packages/shader-lab/src/contentParser/Scanner.ts (1 hunks)
  • packages/shader-lab/src/contentParser/ShaderContentParser.ts (9 hunks)
  • packages/shader-lab/src/index.ts (1 hunks)
  • packages/shader-lab/src/lexer/Lexer.ts (3 hunks)
  • packages/shader-lab/src/parser/AST.ts (4 hunks)
  • packages/shader-lab/src/parser/SemanticAnalyzer.ts (3 hunks)
  • packages/shader-lab/src/parser/ShaderTargetParser.ts (3 hunks)
  • packages/shader-lab/src/parser/builtin/functions.ts (1 hunks)
  • packages/shader-lab/src/preprocessor/MacroDefine.ts (2 hunks)
  • packages/shader-lab/src/preprocessor/PpParser.ts (16 hunks)
  • packages/shader-lab/src/preprocessor/PpScanner.ts (5 hunks)
  • packages/shader-lab/src/preprocessor/Preprocessor.ts (2 hunks)
  • rollup.config.js (9 hunks)
  • tests/src/shader-lab/Preprocessor.test.ts (1 hunks)
  • tests/src/shader-lab/ShaderLab.test.ts (5 hunks)
  • tests/src/shader-lab/ShaderValidate.ts (2 hunks)
  • tests/src/shader-lab/shaders/compilation-error.shader (1 hunks)
Files skipped from review due to trivial changes (4)
  • .github/workflows/ci.yml
  • package.json
  • packages/shader-lab/src/codeGen/GLES100.ts
  • tests/src/shader-lab/Preprocessor.test.ts
Additional context used
LanguageTool
packages/shader-lab/README.md

[uncategorized] ~31-~31: You might be missing the article “the” here.
Context: ...ides superior performance. you can use debug version by import: ```ts // umd import...

(AI_EN_LECTOR_MISSING_DETERMINER_THE)


[uncategorized] ~31-~31: This verb may not be in the correct form. Consider using a different form for this context.
Context: ...formance. you can use debug version by import: ```ts // umd import { ShaderLab } fro...

(AI_EN_LECTOR_REPLACEMENT_VERB_FORM)

Biome
packages/shader-lab/src/parser/SemanticAnalyzer.ts

[error] 72-72: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

packages/shader-lab/src/codeGen/VisitorContext.ts

[error] 74-74: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)


[error] 93-93: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

packages/shader-lab/src/parser/ShaderTargetParser.ts

[error] 123-123: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

packages/shader-lab/src/common/BaseScanner.ts

[error] 137-137: This code is unreachable

... because this statement will throw an exception beforehand

(lint/correctness/noUnreachable)

packages/shader-lab/src/ShaderLab.ts

[error] 27-27: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

packages/shader-lab/src/codeGen/CodeGenVisitor.ts

[error] 198-198: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

packages/shader-lab/src/contentParser/ShaderContentParser.ts

[error] 68-68: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

packages/shader-lab/src/preprocessor/PpParser.ts

[error] 24-723: Avoid classes that contain only static members.

Prefer using simple functions instead of classes with only static members.

(lint/complexity/noStaticOnlyClass)


[error] 49-49: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 67-67: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 68-68: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (81)
packages/shader-lab/src/index.ts (1)

5-5: LGTM!

The export statement for the Error module is correctly added within the _EDITOR directive.

The code changes are approved.

packages/shader-lab/src/common/ShaderPosition.ts (3)

5-5: LGTM!

Changing the line property from optional to mandatory enhances the robustness of the code.

The code changes are approved.


6-6: LGTM!

Changing the column property from optional to mandatory enhances the robustness of the code.

The code changes are approved.


8-8: LGTM!

Updating the setX method signature to require line and column as parameters enhances the robustness of the code.

The code changes are approved.

packages/shader-lab/src/preprocessor/Preprocessor.ts (2)

1-1: LGTM!

Changing the import statement for PpParser from a default import to a named import is appropriate and does not affect the logic of the code.

The code changes are approved.


19-19: LGTM!

Changing the return type of the process method to string | null enhances the method's functionality by allowing it to represent a failure or an exceptional case more explicitly.

The code changes are approved.

packages/shader-lab/src/common/BaseToken.ts (1)

23-24: LGTM!

The new implementation simplifies the code and enhances readability without altering the overall behavior.

The code changes are approved.

packages/shader-lab/src/preprocessor/MacroDefine.ts (1)

32-32: LGTM!

The new implementation enhances the clarity and specificity of error handling in the preprocessor context.

The code changes are approved.

packages/shader-lab/README.md (3)

29-29: LGTM!

The documentation correctly explains the purpose of the Release and Debug versions.

The documentation change is approved.


33-40: LGTM!

The import statements for the Debug version across different module systems are correctly provided and improve user guidance.

The documentation change is approved.


41-41: LGTM!

The line is correctly placed to separate the sections.

The documentation change is approved.

packages/shader-lab/src/Utils.ts (1)

3-3: LGTM!

The removal of the Logger import is consistent with the changes in the error handling strategy.

The code change is approved.

packages/shader-lab/src/parser/SemanticAnalyzer.ts (3)

4-4: LGTM!

The import statement for CompilationError is correctly added, consistent with the shift in error handling strategy.

The code change is approved.


26-26: LGTM!

The errors property is correctly updated to hold an array of CompilationError instances, consistent with the shift in error handling strategy.

The code change is approved.


67-71: LGTM!

The error handling logic within the error method is correctly updated to construct a CompilationError and include a reference to ShaderLab._processingPassText, enhancing the error reporting mechanism.

The code change is approved.

packages/shader-lab/src/Error.ts (8)

2-3: LGTM!

The new imports are correct and necessary for the updated functionality.

The code changes are approved.


6-6: LGTM!

The new static property wrappingLineCount is correctly defined.

The code changes are approved.


8-10: LGTM!

The new properties loc, source, and file are correctly defined.

The code changes are approved.


12-17: LGTM!

The updated constructor correctly initializes the new properties.

The code changes are approved.


56-61: LGTM!

The updated constructor correctly aligns with GSError.

The code changes are approved.


63-66: LGTM!

The updated constructor correctly aligns with GSError.

The code changes are approved.


70-73: LGTM!

The updated constructor correctly aligns with GSError.

The code changes are approved.


19-53: Verify the correctness of the log method.

The log method is well-implemented, but ensure that it correctly processes all possible inputs and edge cases.

Run the following script to verify the log method:

packages/shader-lab/src/codeGen/VisitorContext.ts (2)

39-39: LGTM!

The constructor changes maintain the singleton pattern.

The code changes are approved.


98-98: No changes detected.

No review comment needed.

tests/src/shader-lab/shaders/compilation-error.shader (3)

2-6: LGTM!

The EditorProperties section is correctly defined.

The code changes are approved.


8-14: LGTM!

The EditorMacros section is correctly defined.

The code changes are approved.


16-43: LGTM!

The SubShader section is correctly defined.

The code changes are approved.

tests/src/shader-lab/ShaderValidate.ts (2)

97-97: No changes detected.

No changes were made to the glslValidate function.


98-123: Verify the correctness of _parseShaderContent and _parseShaderPass methods.

Ensure that _parseShaderContent and _parseShaderPass methods are correctly implemented and accessible.

Consider adding error handling.

Add error handling for potential issues during parsing to improve robustness.

packages/shader-lab/src/parser/ShaderTargetParser.ts (1)

38-43: LGTM!

The changes improve error handling and provide better debugging capabilities in the editor context.

packages/shader-lab/src/common/BaseScanner.ts (2)

41-42: Verify the correctness of the new parameter order.

Ensure that the new order of parameters passed to the ShaderLab.createPosition method is correct and consistent with the rest of the codebase.


131-139: LGTM!

The changes improve error handling and provide a more structured way to handle errors during scanning.

Tools
Biome

[error] 137-137: This code is unreachable

... because this statement will throw an exception beforehand

(lint/correctness/noUnreachable)

packages/shader-lab/src/ShaderLab.ts (8)

12-12: LGTM!

The import statement for GSError is correct and necessary for the new error handling logic.


24-24: LGTM!

The addition of the static property _processingPassText is correct and aligns with the changes in the class.


39-39: LGTM!

The addition of the private property _errors is necessary for the new error handling logic.


44-45: LGTM!

The getter method errors is correctly implemented to retrieve the compilation errors.


69-77: LGTM!

The error handling logic in the _parseShaderPass method is correctly implemented to log and handle errors during shader pass parsing.

Also applies to: 89-97, 107-112


121-126: LGTM!

The error handling logic in the _parseShaderContent method is correctly implemented to clear and log errors during shader content parsing.


137-138: LGTM!

The addition of default values to the parameters of the _parse method improves its flexibility.


165-171: LGTM!

The _logErrors method is correctly implemented to log errors.

packages/shader-lab/src/codeGen/GLESVisitor.ts (3)

9-9: LGTM!

The import statement for EKeyword is correct and necessary for the new error handling logic.


32-32: LGTM!

The error handling logic in the visitShaderProgram method is correctly implemented to clear errors and handle invalid return types.

Also applies to: 51-59


71-71: LGTM!

The error handling logic in the vertexMain method is correctly implemented to handle missing attribute structs.

rollup.config.js (9)

28-29: LGTM!

The addition of the variable shaderLabPkg is correct and necessary for the new build configuration logic.


61-61: LGTM!

The addition of the parameter editorMode to the config function is correct and necessary for the new build configuration logic.


64-70: LGTM!

The update to the curPlugins array to include the jscc plugin is correct and necessary for the new build configuration logic.


86-91: LGTM!

The update to the umd function to handle editorMode is correct and necessary for the new build configuration logic.


111-115: LGTM!

The update to the mini function to handle editorMode is correct and necessary for the new build configuration logic.


130-135: LGTM!

The update to the module function to handle editorMode is correct and necessary for the new build configuration logic.


194-195: LGTM!

The update to the getUMD function to include shaderLabPkg with editorMode is correct and necessary for the new build configuration logic.


200-202: LGTM!

The update to the getModule function to include shaderLabPkg with editorMode is correct and necessary for the new build configuration logic.


207-209: LGTM!

The update to the getMini function to include shaderLabPkg with editorMode is correct and necessary for the new build configuration logic.

packages/shader-lab/src/codeGen/CodeGenVisitor.ts (1)

47-50: LGTM!

The function correctly handles errors by pushing them to the _errors array, improving error tracking during code generation.

The code changes are approved.

Also applies to: 53-56

packages/shader-lab/src/preprocessor/PpScanner.ts (3)

89-89: LGTM!

The function correctly uses this.throwError to handle errors, improving encapsulation.

The code changes are approved.


143-143: LGTM!

The function correctly uses this.throwError to handle errors, improving encapsulation.

The code changes are approved.

Also applies to: 150-150


232-232: LGTM!

The function correctly uses this.throwError to handle errors, improving encapsulation.

The code changes are approved.

tests/src/shader-lab/ShaderLab.test.ts (1)

1-5: LGTM!

The function correctly uses ShaderLabEditor and ShaderLabRelease to test both versions of the ShaderLab class. The new test case for handling compilation errors improves test coverage.

The code changes are approved.

Also applies to: 107-108, 117-117, 126-126, 185-186, 191-191, 196-197, 202-203, 208-209, 214-215, 220-221, 226-227, 232-233, 238-239, 242-251

packages/shader-lab/src/lexer/Lexer.ts (2)

279-279: LGTM!

The use of the throwError method improves error handling by providing more context.

The code changes are approved.


385-386: LGTM!

The use of the throwError method improves error handling by providing more context.

The code changes are approved.

packages/shader-lab/src/contentParser/ShaderContentParser.ts (6)

185-196: LGTM!

The use of conditional compilation directives for error handling improves the robustness and flexibility of the code.

The code changes are approved.


244-256: LGTM!

The use of conditional compilation directives for error handling improves the robustness and flexibility of the code.

The code changes are approved.


263-273: LGTM!

The use of conditional compilation directives for error handling improves the robustness and flexibility of the code.

The code changes are approved.


334-339: LGTM!

The use of conditional compilation directives for error handling improves the robustness and flexibility of the code.

The code changes are approved.


301-314: LGTM!

The use of conditional compilation directives for error handling improves the robustness and flexibility of the code.

The code changes are approved.


485-491: LGTM!

The use of conditional compilation directives for error handling improves the robustness and flexibility of the code.

The code changes are approved.

packages/shader-lab/src/preprocessor/PpParser.ts (9)

49-50: LGTM!

The use of conditional compilation directives for error handling improves the robustness and flexibility of the code.

The code changes are approved.

Tools
Biome

[error] 49-49: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


Line range hint 66-100: LGTM!

The use of conditional compilation directives for error handling improves the robustness and flexibility of the code. The change in return type allows for better error handling.

The code changes are approved.

Tools
Biome

[error] 63-63: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 67-67: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 68-68: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 70-70: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


[error] 70-70: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)


109-115: LGTM!

The reportError function centralizes error reporting and improves the maintainability and readability of the code.

The code changes are approved.


136-137: LGTM!

The use of the reportError method improves error handling by providing more context.

The code changes are approved.


311-312: LGTM!

The use of the reportError method improves error handling by providing more context.

The code changes are approved.


337-338: LGTM!

The use of the reportError method improves error handling by providing more context.

The code changes are approved.


361-362: LGTM!

The use of the reportError method improves error handling by providing more context.

The code changes are approved.


383-384: LGTM!

The use of the reportError method improves error handling by providing more context.

The code changes are approved.


405-405: LGTM!

The use of the reportError method improves error handling by providing more context.

The code changes are approved.

packages/shader-lab/src/parser/builtin/functions.ts (2)

135-138: Ensure consistency across all overloads of the max function.

The additional parameter enhances flexibility. Verify that all overloads are correctly updated.

Run the following script to verify the function usage:

Verification successful

All overloads of the max function are consistent with the new signature.

The changes have been correctly applied across all instances in the codebase. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `BuiltinFunction._create("max")` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type ts -A 5 $'BuiltinFunction._create("max")'

Length of output: 52


Script:

#!/bin/bash
# Description: Broaden the search to find any occurrences of `BuiltinFunction._create` involving `max`.

# Test: Search for any `BuiltinFunction._create` calls with `max` as a parameter.
rg --type ts -A 5 'BuiltinFunction\._create\("max"'

Length of output: 1329


129-132: Ensure consistency across all overloads of the min function.

The additional parameter enhances flexibility. Verify that all overloads are correctly updated.

Run the following script to verify the function usage:

Verification successful

All overloads of the min function are consistent.

The changes to the min function have been applied uniformly across all overloads, ensuring consistency and correctness. No further action is needed.

Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Verify all function calls to `BuiltinFunction._create("min")` match the new signature.

# Test: Search for the function usage. Expect: Only occurrences of the new signature.
rg --type ts -A 5 $'BuiltinFunction._create("min")'

Length of output: 52


Script:

#!/bin/bash
# Description: Search for all occurrences of `BuiltinFunction._create` to verify its usage.

# Test: Search for the function usage. Expect: Occurrences of `BuiltinFunction._create` with different parameters.
rg --type ts -A 5 $'BuiltinFunction._create'

Length of output: 45037

packages/shader-lab/src/parser/AST.ts (4)

438-438: LGTM!

The updated error message improves clarity and consistency.

The code changes are approved.


462-465: LGTM!

The updated error messages improve clarity and consistency.

The code changes are approved.


538-538: LGTM!

The updated error message improves clarity and consistency.

The code changes are approved.


875-875: LGTM!

The updated error message improves clarity and consistency.

The code changes are approved.

Comment on lines 29 to 34
scanToCharacter(char: string): void {
while (this.getCurChar() !== char) {
this._advance();
}
this._advance();
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Handle the case where the specified character is not found.

The method does not handle the case where the specified character is not found in the source content, which could lead to an infinite loop. Consider adding a check to handle this scenario.

Apply this diff to handle the case where the specified character is not found:

 def scanToCharacter(char: string): void {
-  while (this.getCurChar() !== char) {
+  while (this.getCurChar() !== char && !this.isEnd()) {
     this._advance();
   }
   if (!this.isEnd()) {
     this._advance();
   }
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
scanToCharacter(char: string): void {
while (this.getCurChar() !== char) {
this._advance();
}
this._advance();
}
scanToCharacter(char: string): void {
while (this.getCurChar() !== char && !this.isEnd()) {
this._advance();
}
if (!this.isEnd()) {
this._advance();
}
}

this.errors.push(err);
return err;
// #else
throw new Error(param.join(""));
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unreachable code.

The code is unreachable because the previous statement returns from the function.

Apply this diff to remove the unreachable code:

-    throw new Error(param.join(""));
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
throw new Error(param.join(""));
Tools
Biome

[error] 72-72: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

Comment on lines +61 to +77
referenceAttribute(ident: BaseToken): GSError {
if (this._referencedAttributeList[ident.lexeme]) return;

const prop = this.attributeList.find((item) => item.ident.lexeme === ident);
const prop = this.attributeList.find((item) => item.ident.lexeme === ident.lexeme);
if (!prop) {
Logger.error("referenced attribute not found:", ident);
return;
// #if _EDITOR
return new CompilationError(
`referenced attribute not found: ${ident.lexeme}`,
ident.location,
ShaderLab._processingPassText
);
// #else
// @ts-ignore
throw new Error(`referenced attribute not found: ${ident.lexeme}`);
// #endif
}
this._referencedAttributeList[ident] = prop;
this._referencedAttributeList[ident.lexeme] = prop;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! But address the unreachable code.

The changes improve type safety and error handling. However, the throw statement is unreachable due to the preceding return.

Apply this diff to remove the unreachable code:

-      // @ts-ignore
-      throw new Error(`referenced attribute not found: ${ident.lexeme}`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
referenceAttribute(ident: BaseToken): GSError {
if (this._referencedAttributeList[ident.lexeme]) return;
const prop = this.attributeList.find((item) => item.ident.lexeme === ident);
const prop = this.attributeList.find((item) => item.ident.lexeme === ident.lexeme);
if (!prop) {
Logger.error("referenced attribute not found:", ident);
return;
// #if _EDITOR
return new CompilationError(
`referenced attribute not found: ${ident.lexeme}`,
ident.location,
ShaderLab._processingPassText
);
// #else
// @ts-ignore
throw new Error(`referenced attribute not found: ${ident.lexeme}`);
// #endif
}
this._referencedAttributeList[ident] = prop;
this._referencedAttributeList[ident.lexeme] = prop;
referenceAttribute(ident: BaseToken): GSError {
if (this._referencedAttributeList[ident.lexeme]) return;
const prop = this.attributeList.find((item) => item.ident.lexeme === ident.lexeme);
if (!prop) {
// #if _EDITOR
return new CompilationError(
`referenced attribute not found: ${ident.lexeme}`,
ident.location,
ShaderLab._processingPassText
);
// #else
// #endif
}
this._referencedAttributeList[ident.lexeme] = prop;
Tools
Biome

[error] 74-74: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

Comment on lines +80 to +96
referenceVarying(ident: BaseToken): CompilationError | undefined {
if (this._referencedVaryingList[ident.lexeme]) return;

const prop = this.varyingStruct?.propList.find((item) => item.ident.lexeme === ident);
const prop = this.varyingStruct?.propList.find((item) => item.ident.lexeme === ident.lexeme);
if (!prop) {
Logger.error("referenced varying not found:", ident);
return;
// #if _EDITOR
return new CompilationError(
`referenced varying not found: ${ident.lexeme}`,
ident.location,
ShaderLab._processingPassText
);
// #else
// @ts-ignore
throw new Error(`referenced varying not found: ${ident.lexeme}`);
// #endif
}
this._referencedVaryingList[ident] = prop;
this._referencedVaryingList[ident.lexeme] = prop;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! But address the unreachable code.

The changes improve type safety and error handling. However, the throw statement is unreachable due to the preceding return.

Apply this diff to remove the unreachable code:

-      // @ts-ignore
-      throw new Error(`referenced varying not found: ${ident.lexeme}`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
referenceVarying(ident: BaseToken): CompilationError | undefined {
if (this._referencedVaryingList[ident.lexeme]) return;
const prop = this.varyingStruct?.propList.find((item) => item.ident.lexeme === ident);
const prop = this.varyingStruct?.propList.find((item) => item.ident.lexeme === ident.lexeme);
if (!prop) {
Logger.error("referenced varying not found:", ident);
return;
// #if _EDITOR
return new CompilationError(
`referenced varying not found: ${ident.lexeme}`,
ident.location,
ShaderLab._processingPassText
);
// #else
// @ts-ignore
throw new Error(`referenced varying not found: ${ident.lexeme}`);
// #endif
}
this._referencedVaryingList[ident] = prop;
this._referencedVaryingList[ident.lexeme] = prop;
referenceVarying(ident: BaseToken): CompilationError | undefined {
if (this._referencedVaryingList[ident.lexeme]) return;
const prop = this.varyingStruct?.propList.find((item) => item.ident.lexeme === ident.lexeme);
if (!prop) {
// #if _EDITOR
return new CompilationError(
`referenced varying not found: ${ident.lexeme}`,
ident.location,
ShaderLab._processingPassText
);
// #else
// #endif
}
this._referencedVaryingList[ident.lexeme] = prop;
Tools
Biome

[error] 93-93: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

Comment on lines +63 to +70
Varyings vert(Attributes attr) {
Varyings v;

gl_Position = renderer_MVPMat * attr2.POSITION;
none();
v.v_pos = gl_Position.xyz;
v.v_uv = attr.TEXCOORD_023;
return v;
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix the syntax errors in the vertex shader.

The vertex shader has syntax errors in the gl_Position and v.v_uv assignments.

Apply this diff to fix the syntax errors:

-                gl_Position = renderer_MVPMat * attr2.POSITION;
+                gl_Position = renderer_MVPMat * attr.POSITION;
-                v.v_uv = attr.TEXCOORD_023;
+                v.v_uv = attr.TEXCOORD_0;
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
Varyings vert(Attributes attr) {
Varyings v;
gl_Position = renderer_MVPMat * attr2.POSITION;
none();
v.v_pos = gl_Position.xyz;
v.v_uv = attr.TEXCOORD_023;
return v;
Varyings vert(Attributes attr) {
Varyings v;
gl_Position = renderer_MVPMat * attr.POSITION;
none();
v.v_pos = gl_Position.xyz;
v.v_uv = attr.TEXCOORD_0;
return v;

Comment on lines +117 to +124
// #if _EDITOR
this.sematicAnalyzer.errors.push(
new CompilationError(`Unexpected token ${token.lexeme}`, token.location, ShaderLab._processingPassText)
);
return null;
// #else
throw new Error(`Unexpected token ${token.lexeme}`);
// #endif
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unreachable code.

The code at line 137 is unreachable because the function will return beforehand. Remove the unreachable code to improve clarity.

-        throw new Error(`Unexpected token ${token.lexeme}`);
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
// #if _EDITOR
this.sematicAnalyzer.errors.push(
new CompilationError(`Unexpected token ${token.lexeme}`, token.location, ShaderLab._processingPassText)
);
return null;
// #else
throw new Error(`Unexpected token ${token.lexeme}`);
// #endif
// #if _EDITOR
this.sematicAnalyzer.errors.push(
new CompilationError(`Unexpected token ${token.lexeme}`, token.location, ShaderLab._processingPassText)
);
return null;
// #else
// #endif
Tools
Biome

[error] 123-123: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

Comment on lines +131 to +139
throwError(pos: ShaderPosition | ShaderRange, ...msgs: any[]) {
// #if _EDITOR
const error = new ScannerError(msgs.join(" "), pos, this._source);
error.log();
throw error;
// #else
throw new Error(msgs.join(""));
// #endif
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unreachable code.

The code at line 137 is unreachable because the function will throw an exception beforehand. Remove the unreachable code to improve clarity.

-    throw new Error(msgs.join(""));
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
throwError(pos: ShaderPosition | ShaderRange, ...msgs: any[]) {
// #if _EDITOR
const error = new ScannerError(msgs.join(" "), pos, this._source);
error.log();
throw error;
// #else
throw new Error(msgs.join(""));
// #endif
}
throwError(pos: ShaderPosition | ShaderRange, ...msgs: any[]) {
// #if _EDITOR
const error = new ScannerError(msgs.join(" "), pos, this._source);
error.log();
throw error;
// #else
// #endif
}
Tools
Biome

[error] 137-137: This code is unreachable

... because this statement will throw an exception beforehand

(lint/correctness/noUnreachable)

Comment on lines +191 to +200
protected reportError(loc: ShaderRange | ShaderPosition, message: string): CompilationError {
let error: Error;
// #if _EDITOR
error = new CompilationError(message, loc, ShaderLab._processingPassText);
this._errors.push(<CompilationError>error);
return <CompilationError>error;
// #else
throw new Error(message);
// #endif
}
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Remove unreachable code.

The function correctly handles errors based on the _EDITOR preprocessor directive. However, the code after the return statement is unreachable.

Apply this diff to remove the unreachable code:

 protected reportError(loc: ShaderRange | ShaderPosition, message: string): CompilationError {
   let error: Error;
   // #if _EDITOR
   error = new CompilationError(message, loc, ShaderLab._processingPassText);
   this._errors.push(<CompilationError>error);
   return <CompilationError>error;
   // #else
-  throw new Error(message);
   // #endif
 }
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
protected reportError(loc: ShaderRange | ShaderPosition, message: string): CompilationError {
let error: Error;
// #if _EDITOR
error = new CompilationError(message, loc, ShaderLab._processingPassText);
this._errors.push(<CompilationError>error);
return <CompilationError>error;
// #else
throw new Error(message);
// #endif
}
protected reportError(loc: ShaderRange | ShaderPosition, message: string): CompilationError {
let error: Error;
// #if _EDITOR
error = new CompilationError(message, loc, ShaderLab._processingPassText);
this._errors.push(<CompilationError>error);
return <CompilationError>error;
// #else
// #endif
}
Tools
Biome

[error] 198-198: This code is unreachable

... because this statement will return from the function beforehand

(lint/correctness/noUnreachable)

@zhuxudong
Copy link
Member

建议使用 LogLevel 的设计去实现编译细节差异,而不是针对平台去设计不同的实现,平台是内部的期望,不具有通用性意义,且维护成本大,容易烂尾。有机会的话建议把以前的 build:editor 都改成通用的设计。

@Sway007
Copy link
Member Author

Sway007 commented Aug 28, 2024

建议使用 LogLevel 的设计去实现编译细节差异,而不是针对平台去设计不同的实现,平台是内部的期望,不具有通用性意义,且维护成本大,容易烂尾。有机会的话建议把以前的 build:editor 都改成通用的设计。

条件编译最大的优势是减小最终打包的包体尺寸,运行时还能去除if else比较的开销。缺点是维护性欠佳,主要是因为js语言没有原生的宏编译,只能借助rollup插件实现。现在release版本包体尺寸比editor版本包体尺寸少30kb (109kb / 139kb)

diagnosticMessage += lineSplit;
diagnosticMessage += `${lines[i]}\n`;
if (i >= start.line && i <= end.line) {
diagnosticMessage += " ".repeat(lineSplit.length + start.column);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

for 循环要特别注意这种高频操作,别浪费性能,移到外面去

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个类都是在Editor版本里的,release版本没有这些性能损耗

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

哥,Editor 就不用管性能了吗

diagnosticMessage += `${lines[i]}\n`;
if (i >= start.line && i <= end.line) {
diagnosticMessage += " ".repeat(lineSplit.length + start.column);
diagnosticMessage += "^".repeat(Math.max(end.column - start.column, 1));
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上,max 更耗性能了

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同上

// commonjs
import { ShaderLab } from "@galacean/engine-shader-lab/dist/main.editor";
```

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这个也是用平台编译带来的缺点,带来这么多潜规则

let source = originSource;
if (_source) source = _source;
if (!source) {
Logger.error(message);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里没有 source 可以直接 return 了

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@Sway007 Sway007 changed the base branch from main to dev/1.4 September 2, 2024 09:30
Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between c679a9e and 44b7e84.

Files selected for processing (2)
  • packages/shader-lab/src/Error.ts (1 hunks)
  • packages/shader-lab/src/ShaderLab.ts (6 hunks)
Files skipped from review as they are similar to previous changes (1)
  • packages/shader-lab/src/Error.ts
Additional context used
Biome
packages/shader-lab/src/ShaderLab.ts

[error] 27-27: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (12)
packages/shader-lab/src/ShaderLab.ts (12)

5-5: LGTM!

The code changes are approved.


11-13: LGTM!

The code changes are approved.


19-20: LGTM!

The code changes are approved.


24-24: LGTM!

The code changes are approved.


38-47: LGTM!

The code changes are approved.


69-77: LGTM!

The code changes are approved.


83-87: LGTM!

The code changes are approved.


89-97: LGTM!

The code changes are approved.


105-112: LGTM!

The code changes are approved.


118-127: LGTM!

The code changes are approved.


137-138: LGTM!

The code changes are approved.


162-171: LGTM!

The code changes are approved.

Comment on lines +26 to +28
static createPosition(index: number, line?: number, column?: number): ShaderPosition {
const position = this._shaderPositionPool.get();
position.setX(
index,
// #if _EDITOR
line,
column
// #endif
);
position.setX(index, line, column);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Refactor suggestion: Use class name instead of this in static context.

Using this in a static context can be confusing. Use the class name instead.

Apply this diff to refactor the code:

- const position = this._shaderPositionPool.get();
+ const position = ShaderLab._shaderPositionPool.get();
Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
static createPosition(index: number, line?: number, column?: number): ShaderPosition {
const position = this._shaderPositionPool.get();
position.setX(
index,
// #if _EDITOR
line,
column
// #endif
);
position.setX(index, line, column);
static createPosition(index: number, line?: number, column?: number): ShaderPosition {
const position = ShaderLab._shaderPositionPool.get();
position.setX(index, line, column);
Tools
Biome

[error] 27-27: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

/**
* Retrieve the compilation errors
*/
get errors(): GSError[] | undefined {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

不是最多空数组么,怎么会有 undefined

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@@ -25,4 +25,11 @@ export default class Scanner extends BaseScanner {
}
return Number(this._source.substring(start, this._currentIndex));
}

scanToCharacter(char: string): void {
while (this.getCurChar() !== char) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

这里用户不小心写错,不会死循环吗

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 0

Outside diff range, codebase verification and nitpick comments (1)
packages/shader-lab/src/ShaderLab.ts (1)

26-30: LGTM, but consider using the class name instead of this in a static context.

The changes to the createPosition method improve code readability and maintainability by removing unnecessary comments and simplifying the parameter handling.

However, using this in a static context can be confusing. Use the class name instead.

Apply this diff to refactor the code:

- const position = this._shaderPositionPool.get();
+ const position = ShaderLab._shaderPositionPool.get();
Tools
Biome

[error] 27-27: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Review details

Configuration used: CodeRabbit UI
Review profile: CHILL

Commits

Files that changed from the base of the PR and between 44b7e84 and eb0bcde.

Files selected for processing (2)
  • packages/shader-lab/src/ShaderLab.ts (6 hunks)
  • packages/shader-lab/src/contentParser/Scanner.ts (1 hunks)
Additional context used
Biome
packages/shader-lab/src/ShaderLab.ts

[error] 27-27: Using this in a static context can be confusing.

this refers to the class.
Unsafe fix: Use the class name instead.

(lint/complexity/noThisInStatic)

Additional comments not posted (7)
packages/shader-lab/src/contentParser/Scanner.ts (1)

29-34: LGTM! The previous comment has been addressed.

The new scanToCharacter method correctly handles the case where the specified character is not found by checking for the end of the source content, thus avoiding a potential infinite loop.

packages/shader-lab/src/ShaderLab.ts (6)

39-39: LGTM!

The new _errors property enhances error handling capabilities by providing a centralized location to store compilation errors.


44-46: LGTM!

The new errors getter method provides a convenient way to access the compilation errors stored in the _errors property.


Line range hint 49-115: LGTM!

The modifications to the _parseShaderPass method improve error handling by logging errors from the PpParser and the shader parser, and storing them in the _errors array for later retrieval. These changes enhance the robustness of the shader compilation process.


117-127: LGTM!

The modifications to the _parseShaderContent method enhance error handling by clearing the _errors array at the start of its execution and collecting errors from the ShaderContentParser, appending them to the _errors array. These changes improve error tracking and ensure that the method starts fresh for each shader content parsing.


Line range hint 133-160: LGTM!

The modifications to the _parse method improve its flexibility by providing default values for its parameters. These changes make the method more adaptable and easier to use in different scenarios.


165-171: LGTM!

The addition of the _logErrors method enhances error handling capabilities by encapsulating the error logging logic. It provides a centralized and consistent way to log errors, making the code more maintainable and easier to understand.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request high priority High priority issue Rendering Rendering related functions shader Shader related functions
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants