Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qtqml-tooling-qmlls.qdoc
Go to the documentation of this file.
1// Copyright (C) 2023 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5\page qtqml-tooling-qmlls.html
6\title \QMLLS
7\brief A tool that helps you write code in your favorite LSP-supporting editor.
8\ingroup qtqml-tooling
9\ingroup qtqml-tooling-devtools
10\keyword qmlls
11
12\QMLLS is a tool shipped with Qt that helps you write code
13in your favorite (LSP-supporting) editor.
14See \l{https://microsoft.github.io/language-server-protocol/}{Language Server Protocol}
15for more information.
16
17Currently, it enables your editor to:
18\list
19 \li Autocomplete your code
20 \li Display qmllint warnings
21 \li Navigate to definitions in QML files
22 \li Find usages of JavaScript variables and QML objects
23 \li Rename JavaScript variables and QML objects
24 \li Format QML files
25 \li Get help from Qt Documentation
26\endlist
27
28\note \c qmlls is currently in development, see
29\l{#Known Limitations}{Known Limitations} for more details.
30
31\section1 Supported Features
32
33\section2 Linting
34
35\QMLLS can automatically lint opened QML files
36and display warnings or errors straight in the editor. See
37\l{qmllint} for more information about the linting process,
38and \l{QML Lint Warning and Errors} on how to fix warnings and
39errors.
40
41\section2 Formatting
42
43\QMLLS can format entire files from inside
44the editor. See \l{qmlformat} for more information about the
45formatting process.
46
47
48\section2 Finding Definitions
49
50\QMLLS can find definitions of JavaScript variables,
51functions, QML object id's and QML properties from their usages.
52
53\QMLLS can also find the definition of types used in
54type annotations for JavaScript functions, QML object properties,
55and QML object instantiation.
56
57\section2 Finding Usages
58
59\QMLLS can find usages of JavaScript variables,
60QML object properties, JavaScript functions, QML object methods,
61and QML object id's.
62
63\section2 Renaming
64
65\QMLLS can rename JavaScript variables and functions,
66as well as QML object properties, methods, and id's, as long as
67they are defined in a QML file.
68
69\section2 Suggesting Autocompletion Items
70
71\QMLLS provides autocompletion suggestions for
72JavaScript variables, expressions, and statements, as well as
73QML object properties, methods, and id's.
74
75\section2 Tracking Changes in C++ Files
76
77\QMLLS can track changes in C++ files defining QML
78types. It automatically rebuilds CMake QML modules to provide
79accurate and up-to-date warnings and completion items for C++
80defined QML types.
81
82You can
83\l{Configuring Automatic CMake Builds}{disable this feature}.
84
85\section2 Documentation Hints
86
87\QMLLS includes a documentation hints feature that
88provides programmers with quick access to Qt’s documentation
89by hovering over a keyword. In order to use this feature, your
90Qt kit should contain the Qt documentation and your project
91should be built with \l{QT_QML_GENERATE_QMLLS_INI} variable.
92
93\section1 Setting up \QMLLS in Your Editor
94
95This section describes how to develop the \QMLLS client or how to
96use your own \QMLLS client.
97
98You can find the \QMLLS binary under
99\c{<Qt installation folder>/bin/qmlls} in installations of Qt
100made with \QOI. If you want your \QMLLS client to download the binary
101directly, you can download the standalone version from github via
102\l{https://github.com/TheQtCompanyRnD/qmlls-workflow/releases} or
103\l{https://qtccache.qt.io/QMLLS/LatestRelease}.
104
105\section2 Setting up the Build Directory
106
107\QMLLS needs to know the location of the project build folder.
108You can pass the build folder in the following ways.
109
110\section3 AddBuildDirs LSP Extension
111
112To pass build directories via the LSP extension, send a notification
113to \QMLLS for the \c{$/addBuildDirs} method. \c{$/addBuildDirs}
114accepts one parameter of the form:
115\badcode
116interface AddBuildDirsParams {
117 buildDirsToSet: UriToBuildDirs[];
118}
119\endcode
120where \c{UriToBuildDirs} contains a workspace URI and a list of build
121directories.
122The workspace URI must designate a workspace advertised to \QMLLS via
123\l{https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_workspaceFolders}{workspaceFolders}
124or
125\l{https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeWorkspaceFolders}{didChangeWorkspaceFolders}.
126The build directories are file paths, not URIs.
127\badcode
128interface UriToBuildDirs {
129 baseUri: URI;
130 buildDirs: string[];
131}
132\endcode
133
134\section3 --build-dir Command Line Option
135
136If you don't need to support multiple workspaces, you can pass the build
137directories via the \c{--build-dir} command line option. In this case
138your editor should invoke \c{qmlls} as following:
139\badcode
140<path/to/qmlls> ... --build-dir <path/to/build-directory> ...
141\endcode
142
143The build directory will be applied to all workspaces if you use multiple
144workspaces in the same \QMLLS. The values from \c{addBuildDirsMethod}
145have higher precedence than the command line option.
146
147\section3 QMLLS_BUILD_DIRS Environment Variable
148
149You can also pass the build directories via the \c{QMLLS_BUILD_DIRS}
150environment variable. The build directory will be applied to all
151workspaces if you use multiple workspaces in the same \QMLLS.
152The values from \c{--build-dir} have higher precedence than the
153environment variable.
154
155\section3 \c{.qmlls.ini} Settings File
156
157If you can't pass the build directories using one of the previous options,
158you could try passing build directories to \QMLLS via a configuration file.
159See also \l{Configuration File}.
160The values from the settings file have lower precedence than
161\c{--build-dir}, \c{QMLLS_BUILD_DIRS}, and \c{addBuildDirsMethod}.
162
163\section2 Configuring Automatic CMake Builds
164
165\QMLLS will try to trigger a CMake rebuild when it detects that the
166source code of a C++ defined QML type has been modified.
167
168To disable this feature, use the following ways:
169\list
170 \li The \c{--no-cmake-calls} command line option. In this case
171your editor should invoke \c{qmlls} as follows:
172\badcode
173<path/to/qmlls> --build-dir <path/to/build-directory> --no-cmake-calls
174\endcode
175 \li The \c{QMLLS_NO_CMAKE_CALLS} environment variable.
176 \li The \c{.qmlls.ini} settings file, see \l {Configuration File}.
177 \li The \l{QT_QML_GENERATE_QMLLS_INI_NO_CMAKE_CALLS} CMake variable
178if \l{QT_QML_GENERATE_QMLLS_INI} is enabled.
179\endlist
180
181To control the number of jobs used by CMake, use
182\list
183 \li The \c{--cmake-jobs} command line option. In this case
184your editor should invoke \c{qmlls} as follows:
185\badcode
186<path/to/qmlls> --build-dir <path/to/build-directory> --cmake-jobs <jobs>
187\endcode
188 \li The \c{QMLLS_CMAKE_JOBS} environment variable.
189 \li The \c{.qmlls.ini} settings file, see \l {Configuration File}.
190\endlist
191Accepted values are integers greater than 0 and \c{max} to use all available
192cores.
193
194\section2 Modifying the maximum amount of files to search
195
196\QMLLS respects a limit of files to search when searching the source
197folders for headers, for example when going to the definition of a QML
198component defined in a C++ header.
199
200To set the maximum amount of files to search, write a numeric value in the
201\c QMLLS_MAX_FILES_TO_SEARCH environment variable. 0 disables the file
202searching feature, 20000 is the default value.
203
204\section1 Configuration File
205
206\QMLLS can be configured via a configuration file \c{.qmlls.ini}.
207This file should be in the root source directory of the project.
208It should be a text file in the ini-format.
209
210The configuration file can have the following entries:
211\code
212// .qmlls.ini
213[General]
214no-cmake-calls=<true-or-false>
215CMakeJobs=<some integer value>
216
217buildDir=<path/to/build-directory> # not required in Qt 6.10 and later
218docDir=<path/to/qt-documentation> # not required in Qt 6.10 and later
219importPaths=<path/to/imports> # not required in Qt 6.10 and later
220\endcode
221
222To use the configuration file to disable the automatic CMake rebuild
223functionality, set \c{no-cmake-calls} to \c{true}.
224
225To control the number of jobs used by automatic CMake rebuilds, set the
226CMakeJobs value.
227
228To support clients that can't pass the build directory to \QMLLS, as
229described in \l{Setting up the Build Directory}, set the buildDir value
230or let CMake generate the .qmlls.ini via \l {QT_QML_GENERATE_QMLLS_INI}.
231
232\note \QMLLS can create default configuration files
233using the \c{--write-defaults} option. This will overwrite an
234already existing .qmlls.ini file in the current directory.
235
236\section1 Known Limitations
237
238Despite covering many common QML features, \QMLLS is still in development with some features
239yet to be supported:
240\list
241 \li Suggesting autocompletions on invalid QML files.
242 \li Autocompleting context properties
243\endlist
244
245\QMLLS might emit false positive warnings on projects
246\list
247 \li using QMake or imperative type registration---see \l{Port QML modules to CMake}
248 \li that were not built---\QMLLS uses the build information to find QML modules
249 \li where QML modules don't follow the guidelines in \l{Modernizing QML Modules}
250\endlist
251
252*/