Plasmoid + VSCode: How to properly import org.kde.plasma.plasmoid?

I am setting up VSCode to develop Plasmoids and it is working fine so far in the sense that I get intellisense support for most of the code. The only thing not working is import org.kde.plasma.plasmoid, it just cannot be found. Other plasma components do work fine. On Reddit I read it is because it is a dynamically generated module, whatever that means.

Is it true or do I have other options to properly import org.kde.plasma.plasmoid?

Thanks!

As for any programming language nowadays you need a Language Server Procotol.

For qml it is QML Language Server | Qt Qml | Qt 6.9.0

Once plasma is built you will need to set QMLLS_BUILD_DIRS to the relevant build dirs that contain .qmlls.ini files provided you used -DQT_QML_GENERATE_QMLLS_INI=ON, that can be setup in kde-builder in cmake-options to generate those files on your next build.

I think kde-builder should turn this on it by default, and could even set-up QMLLS_BUILD_DIRS.

There was nice blog posts on the matter by Nicolas Fella:

Once you have the KDE side done, you have a guide for using qmlls and .qmlls.ini in viscode

Thank you, very informative!

Does that mean I absolutely have to build plasma to be able to find org.kde.plasma.plasmoid? Or is there some dev-dependencies package I can install instead? I am still wondering why the rest of Plasma like org.kde.plasma.components can be found. Only the plasmoid package is making trouble.

libplasma should be the main part you’d need.
Depending on what you want to do it will vary.

I don’t think there is, those .qmlls.ini is quite recent.
But that should become part of development packages for sure… at some point.

The Component could be part of the current code base, it is part of libplasma.
Or that’s because Component is implemented in qml while plasmoid is in C++.
Not exactly sure.

1 Like

I think I got a better understanding now. When I open a .qml file in VSCode the Qt Extension Pack generates a new CMake tool kit entry here: ~/.local/share/CMakeTools/cmake-tools-kits.json (which did not work the first time but eventually it worked and it creates four identical entries but I don’t care as it is working now).

The VSCode CMake extension then picks up the list of kits and lets me select one when I execute the VSCode command CMake: Select a Kit. As soon as I select e.g. Qt-6.8.3-linux-g++ intellisense starts working properly. The entry Qt-6.8.3-linux-g++ links to the following configuration in ~/.local/share/CMakeTools/cmake-tools-kits.json:

{
  "name": "Qt-6.8.3-linux-g++",
  "isTrusted": true,
  "cmakeSettings": {
    "QT_QML_GENERATE_QMLLS_INI": "ON"
  },
  "preferredGenerator": {
    "name": "Ninja"
  },
  "toolchainFile": "/usr/lib/cmake/Qt6/qt.toolchain.cmake",
  "environmentVariables": {
    "VSCODE_QT_QTPATHS_EXE": "/usr/lib/qt6/bin/qmake6",
    "PATH": "/usr:/usr/lib/qt6:/usr/share/qt6:/usr/share/doc/qt6:/usr/include/qt6:/usr/lib:/usr/lib/qt6/bin:/usr/tests:/usr/lib/qt6/plugins:/usr/lib/qt6/qml:/usr/share/qt6/translations:/usr/share/doc/qt6/examples:${env:PATH}"
  }
}

One can see that the referenced Qt installation is located at /usr/lib/qt6. Below that folder there are also KDE related QML folders, e.g. qml/org/kde/plasma/.

The content of qml/org/kde/plasma/ is:

/u/l/q/q/o/k/plasma> ls -lah /usr/lib/qt6/qml/org/kde/plasma/
insgesamt 0
drwxr-xr-x 1 root root  266 23. Jan 10:40 ./
drwxr-xr-x 1 root root 1018 23. Jan 10:40 ../
drwxr-xr-x 1 root root  208 17. Mär 19:47 activityswitcher/
drwxr-xr-x 1 root root 1,5K 17. Mär 19:46 components/
drwxr-xr-x 1 root root  232 17. Mär 19:46 core/
drwxr-xr-x 1 root root  180 17. Mär 19:47 emoji/
drwxr-xr-x 1 root root  766 17. Mär 19:46 extras/
drwxr-xr-x 1 root root   64  1. Apr 22:13 lookandfeel/
drwxr-xr-x 1 root root  164 17. Mär 19:47 networkmanagement/
drwxr-xr-x 1 root root   60 17. Mär 19:46 PimCalendars/
drwxr-xr-x 1 root root  164 17. Mär 19:46 plasma5support/
drwxr-xr-x 1 root root  128 17. Mär 19:47 printmanager/
drwxr-xr-x 1 root root  756 30. Mär 19:28 private/
drwxr-xr-x 1 root root   18 16. Sep 2024  wallpapers/
drwxr-xr-x 1 root root  124 16. Sep 2024  workspace/

Which is exactly the list of importable modules. There is no plasmoid folder so it makes sense that I cannot import it.

This means that, I think, import org.kde.plasma.plasmoid is somehow special.

The folders below /usr/lib/qt6/qml/org/kde are populated by different Arch packages like extra/plasma-desktop, extra/kdepim-addons and extra/libplasma.

So to summarize:

  • I don’t necessarily need to build plasma to import plasma modules
  • I can import everything located under /usr/lib/qt6/qml (more specifically /usr/lib/qt6/qml/org/kde/), without extra configuration
  • There is no plasmoid folder under /usr/lib/qt6/qml/org/kde/plasma/ and so I cannot import it. Something else happens, maybe the plasmoid package is injected at runtime like it is the case with the i18n function:

Quote from your second link:

Our translation functions, i18n and friends, are considered unqualified lookups by qmllint/qmlls. This is because they are magically injected into the engine at runtime.

I guess this is the best I can achieve for now, from your linked posts it sounds like the language server is still under heavy development and I will then just wait for improvements. The language server is already a big help, even with the remaining issues present.

Thanks also for your help so far!