nolanderc / glsl_analyzer

Language server for GLSL (autocomplete, goto-definition, formatter, and more)
GNU General Public License v3.0
200 stars 6 forks source link

Formatting duplicates comments #57

Closed akberg closed 7 months ago

akberg commented 7 months ago

When formatting with glsl_analyzer, multiline block comments seem to duplicate.

/** Some 
 * long 
 * multiline comment
 */

/** Remapping from input array to output array.
 * m_primitive_list[primitive_remap_index[i]] = m_primitive_list_in[i] */
layout(binding = 4, std430) buffer primitivesRemapSSBOOut {
    uint primitive_remap_index[];
};

becomes

/** Some
 * long
 * multiline comment
/** Some 
 * long 
 * multiline comment
 */

/** Remapping from input array to output array.
/** Remapping from input array to output array.
 * m_primitive_list[primitive_remap_index[i]] = m_primitive_list_in[i] */
layout(binding = 4, std430) buffer primitivesRemapSSBOOut {
    uint primitive_remap_index[];
};

This is not an issue with multiple lines of C++ style line comments.

Same goes for multiline defines:

#define SNIPPET(x) \
do { \
x ++; \
} while (0)

becomes

#define SNIPPET(x) \
do { \
x ++; \
#define SNIPPET(x) \
do { \
x ++; \
} while (0)

This might be connected to line endings, as these two cases are syntax which ignore line endings.

nolanderc commented 7 months ago

Very interesting! Seems everything but the last line of the comment is duplicated. I’ll try to reproduce later. Until then could you post the output from running glsl_analyzer --parse-file <path> --print-ast?

nolanderc commented 7 months ago

Also, did you build from source or use one of the precompiled binaries?

akberg commented 7 months ago

Good point, I'm using the version packed with the VSCode extension.

Now neither comments nor preprocessor defines are printed with the AST. Not sure how you are handling macros, judging from one of your other issue I'm guessing you're not (yet)?

Given Some bug.comp

#version 450

#define SNIPPET(x) \
do {\
x++;\
} while (0)

/** Some
multi-line
comment
*/

void main() {
    SNIPPET(x);
}
glsl_analyzer --parse-file shaders/src/bug.comp --print-ast
file
  function_declaration
    identifier 'void'
    identifier 'main'
    parameter_list
      (
      )
    block
      {
      statement
        call
          identifier 'SNIPPET'
          (
          argument
            identifier 'x'
          )
        ;
      }
nolanderc commented 7 months ago

Right… the comments/macros are not shown in the AST printing (they are there, just in a different structure, which makes them harder to visualize). Sorry, it’s been a while since I worked on that code.

Good point, I'm using the version packed with the VSCode extension.

Okay, I’m just asking because I recently updated the master branch to a newer version of Zig, thinking it could be related, but it’s not, so that’s good.

nolanderc commented 7 months ago

Turned out to be a small typo:

-            if (start < bytes.len) try self.writeLine(bytes[0..]);
+            if (start < bytes.len) try self.writeLine(bytes[start..]);
nolanderc commented 7 months ago

I've tagged a new release, it should be available for download in VSCode in a few minutes :)