Uploaded image for project: 'Qt Creator'
  1. Qt Creator
  2. QTCREATORBUG-28008

Add a way to link a generated qmldir file back to the source folder

    XMLWordPrintable

Details

    Description

      Use-case

      Organizing a large project into smaller standalone (and possibly reusable) submodules.

       

      Backstory

      In the past, we had to manually write and deploy qmldir files when creating QML modules. To help the Qt Creator code model find our custom modules, we would simply point QML_IMPORT_PATH to our source directory and everything would work fine, in particular the code navigator: When we activate "Follow Symbol Under Cursor" Qt Creator would open the source .qml file for editing.

      qt_add_qml_module() was introduced to automate and standardize many things about creating custom modules. One of the outcomes is that we no longer need to write qmldir files.

       

      Problem

      Since our source tree no longer contains qmldir files, we can no longer point QML_IMPORT_PATH to it. We need to point it to the build directory instead. For the most part, this doesn't affect the code model – the syntax highlighter, code analyzer, code completer, etc. still work fine.

      Unfortunately, the code navigator no longer works fine. If we activate "Follow Symbol Under Cursor" now, Qt Creator would open the .qml file that's in the build directory. qt_add_qml_module() has broken our code navigation.

      • At best, this is an inconvenience: We've lost the shortcut and now need to find the file in the "Projects" pane and open it for editing.

       

      Ultimately, we need a way to get Qt Creator to open the source file when activating "Follow Symbol Under Cursor".

       

      Suggestion

      Here is my idea for a possible solution: During the build process, generate a "qmlsourcemap" file which records the path to the source directory of each auto-generated module. This file plays no role in the final executable; it is only for the code model's use. The code model would continue behaving as it always has in the past, but with one difference: If it finds a "qmlsourcemap" file for a module, then it now stores and uses the source path too.

      I can think of two different ways to use this "qmlsourcemap":

      • The narrow way: Use "qmlsourcemap" for code navigation only. Syntax highlighting, code analysis, etc. would still be based on the contents of the build directory, but "Follow Symbol Under Cursor" would open the file from the stored source path instead of the file that's actually used by the code model.
      • The broad way: Use "qmlsourcemap" for all of qmljslib's tasks. This implies that the code model needs the ability to load QML files from a different directory than the qmldir file. The .qml files in the build folder would be ignored.

       

      My impression is – and I could be wrong – that the narrow way is less risky, but the broad way is handier (for example, when a component's API is updated, it can be reflected in the code model immediately without rebuilding the project).

      Attachments

        Issue Links

          Activity

            People

              fawzi Fawzi Mohamed
              skoh-qt Sze Howe Koh
              Votes:
              6 Vote for this issue
              Watchers:
              6 Start watching this issue

              Dates

                Created:
                Updated: