Indentation of namespace contents

Sysprogs forums Forums VisualGDB Indentation of namespace contents

Viewing 7 posts - 1 through 7 (of 7 total)
  • Author
    Posts
  • #20853
    aronrubin
    Participant

    How do I configure the VisualGDB formatter to not indent namespace contents? There are other advanced formatting issues like misaligned argument indentation but the namespace one is particularly frustrating.

    Thank you

    #20857
    support
    Keymaster

    Hi,

    VisualGDB tries to inherit the regular Visual C++ formatting settings under Tools->Options->Text Editor->C/C++, so please double-check that the indentation settings there match your expectations. If VisualGDB still indents the code the wrong way, please attach a screenshot of the relevant VC++ setting and a screenshot of a formatted code fragment and we will try investigating this further.

    #20910
    aronrubin
    Participant

    Everything matches. Looking into the problem further as it appeared intermittent I have found that the indentation (not just for namespaces) while typing (newline, semicolon, or close brace) is erratic. However if I have everything written and I select the same code and Edit -> Format Select I get the desired/expected formatting style. I do have settings expressed vi Text Editor -> C/C++, Text Editor -> C/C++ (VisualGDB), .editorconfig file, and .clang-format file. All are consistent as far as I can tell.

    Attachments:
    You must be logged in to view attached files.
    #20913
    aronrubin
    Participant

    Here is a small header that was funky as I wrote it. It is part of a cmake project that is being cross compiled for a Raspberry Pi (filesystem synchronized):

    #pragma once
    
    #ifndef IMAGEREF_HPP_INCLUDED
    #define IMAGEREF_HPP_INCLUDED
    
    #include <cstdint>
    #include <memory>
    #include <string>
    #include <vector>
    #include <map>
    
    namespace ffm {
    
    inline constexpr uint32_t fcc( const char a, const char b, const char c, const char d ) {
      return (a | (b << 8) | (c << 16) | (d << 24));
    }
    inline constexpr uint32_t fcc( const char str[] ) {
      return (str[0] | (str[1] << 8) | (str[2] << 16) | (str[3] << 24));
    }
    
    class ImageRef {
    public:
      typedef std::function<void( const uint8_t * )> DataUnref;
      static DataUnref weak;
      
      struct Data {
        uint32_t fmt_4cc = 0;
        const uint8_t *data = nullptr;
        size_t datalength = 0;
        std::vector<uint8_t> datastore;
        DataUnref unref = nullptr;
        
        Data() = default;
        Data( uint32_t fmt_4cc, const uint8_t *data, size_t datalength, DataUnref &unref = weak ) : 
          fmt_4cc( fmt_4cc ), data( data ), datalength( datalength ), unref( unref ) { 
        }
      };
    
    
      size_t width = 0;
      size_t height = 0;
      int64_t pts = 0;
      uint32_t orig_fmt_4cc = 0;
      std::map<uint32_t, Data> datas;
      
      ImageRef() = default;
      
      ImageRef( uint32_t fmt_4cc,
                size_t width,
                size_t height,
                const uint8_t *data,
                size_t datalength = 0,
                DataUnref &unref = weak ) : 
          width(width), height(height) {
        if (data) {
          orig_fmt_4cc = fmt_4cc;
          datas.emplace( std::piecewise_construct,
                         std::forward_as_tuple( fmt_4cc ),
                         std::forward_as_tuple( fmt_4cc, data, datalength, unref ) );
        }
      }
      
      void addDataRef( uint32_t fmt_4cc,
                       size_t data_width,
                       size_t data_height,
                       const uint8_t *data,
                       size_t datalength = 0,
                       DataUnref &unref = weak ) {
        if( fmt_4cc && data && data_width == width && data_height == height ) {
          auto it = datas.find( fmt_4cc );
          if (it != datas.end()) {
            it->second = Data( fmt_4cc, data, datalength );
          } else {
            datas.emplace( std::piecewise_construct,
                           std::forward_as_tuple( fmt_4cc ),
                           std::forward_as_tuple( fmt_4cc, data, datalength, unref ) );
          }
        }
      }
      
    };
    
    ImageRef::DataUnref ImageRef::weak = nullptr;
    
    } // namespace ffm
    
    #endif // IMAGEREF_HPP_INCLUDED
    
    #20918
    support
    Keymaster

    Hi,

    This looks consistent with your settings – the namespace contents are not indented, the class contents are. If you could narrow this down to some specific steps that lead to undesired behavior, we should be able to diagnose/fix this. Otherwise it is hard to see what exactly could be causing the trouble.

    #20920
    aronrubin
    Participant

    Sorry that version was after I fixed the formatting. Here are some artifacts if I just type enter after the curly brackets (lines 55 and 69):

    #pragma once
    
    #ifndef IMAGEREF_HPP_INCLUDED
    #define IMAGEREF_HPP_INCLUDED
    
    #include <cstdint>
    #include <memory>
    #include <string>
    #include <vector>
    #include <map>
    
    namespace ffm {
    
    inline constexpr uint32_t fcc( const char a, const char b, const char c, const char d ) {
      return (a | (b << 8) | (c << 16) | (d << 24));
    }
    inline constexpr uint32_t fcc( const char str[] ) {
      return (str[0] | (str[1] << 8) | (str[2] << 16) | (str[3] << 24));
    }
    
    class ImageRef {
    public:
      typedef std::function<void( const uint8_t * )> DataUnref;
      static DataUnref weak;
      
      struct Data {
        uint32_t fmt_4cc = 0;
        const uint8_t *data = nullptr;
        size_t datalength = 0;
        std::vector<uint8_t> datastore;
        DataUnref unref = nullptr;
        
        Data() = default;
        Data( uint32_t fmt_4cc, const uint8_t *data, size_t datalength, DataUnref &unref = weak ) : 
          fmt_4cc( fmt_4cc ), data( data ), datalength( datalength ), unref( unref ) { 
        }
      };
    
    
      size_t width = 0;
      size_t height = 0;
      int64_t pts = 0;
      uint32_t orig_fmt_4cc = 0;
      std::map<uint32_t, Data> datas;
      
      ImageRef() = default;
    
      ImageRef( uint32_t fmt_4cc,
                size_t width,
                size_t height,
                const uint8_t *data,
                size_t datalength = 0,
                DataUnref &unref = weak ) : 
          width(width), height(height) {
            if (data) {
              orig_fmt_4cc = fmt_4cc;
              datas.emplace( std::piecewise_construct,
                            std::forward_as_tuple( fmt_4cc ),
                            std::forward_as_tuple( fmt_4cc, data, datalength, unref ) );
        }
      }
      
      void addDataRef( uint32_t fmt_4cc,
                       size_t data_width,
                       size_t data_height,
                       const uint8_t *data,
                       size_t datalength = 0,
                       DataUnref &unref = weak ) {
                         if( fmt_4cc && data && data_width == width && data_height == height ) {
                           auto it = datas.find( fmt_4cc );
                           if (it != datas.end()) {
                             it->second = Data( fmt_4cc, data, datalength );
                           } else {
                             datas.emplace( std::piecewise_construct,
                                           std::forward_as_tuple( fmt_4cc ),
                                           std::forward_as_tuple( fmt_4cc, data, datalength, unref ) );
          }
        }
      }
    
    };
    
    ImageRef::DataUnref ImageRef::weak = nullptr;
    
    } // namespace ffm
    
    #endif // IMAGEREF_HPP_INCLUDED
    
    
    • This reply was modified 6 years, 7 months ago by aronrubin.
    #20925
    support
    Keymaster

    Hi,

    Thanks for the repro case. It looks like VisualGDB is incorrectly picking up the indentation of the “width(width), height(height) {” line as a base instead of the “ImageRef( uint32_t fmt_4cc,” line. We are currently experimenting with switching our indentation engine to clang-format (that will also let you reuse the clang-format settings files), so this will likely resolve the issue once the switch is complete.

    If we decide to delay the switch to one of the next VisualGDB releases, we will improve our current indentation logic to locate the start of the statement properly.

Viewing 7 posts - 1 through 7 (of 7 total)
  • You must be logged in to reply to this topic.