Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Toggle main menu visibility
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
13
in your favorite (LSP-supporting) editor.
14
See \l{https://microsoft.github.io/language-server-protocol/}{Language Server Protocol}
15
for more information.
16
17
Currently, 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
36
and display warnings or errors straight in the editor. See
37
\l{qmllint} for more information about the linting process,
38
and \l{QML Lint Warning and Errors} on how to fix warnings and
39
errors.
40
41
\section2 Formatting
42
43
\QMLLS can format entire files from inside
44
the editor. See \l{qmlformat} for more information about the
45
formatting process.
46
47
48
\section2 Finding Definitions
49
50
\QMLLS can find definitions of JavaScript variables,
51
functions, QML object id's and QML properties from their usages.
52
53
\QMLLS can also find the definition of types used in
54
type annotations for JavaScript functions, QML object properties,
55
and QML object instantiation.
56
57
\section2 Finding Usages
58
59
\QMLLS can find usages of JavaScript variables,
60
QML object properties, JavaScript functions, QML object methods,
61
and QML object id's.
62
63
\section2 Renaming
64
65
\QMLLS can rename JavaScript variables and functions,
66
as well as QML object properties, methods, and id's, as long as
67
they are defined in a QML file.
68
69
\section2 Suggesting Autocompletion Items
70
71
\QMLLS provides autocompletion suggestions for
72
JavaScript variables, expressions, and statements, as well as
73
QML 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
78
types. It automatically rebuilds CMake QML modules to provide
79
accurate and up-to-date warnings and completion items for C++
80
defined QML types.
81
82
You can
83
\l{Configuring Automatic CMake Builds}{disable this feature}.
84
85
\section2 Documentation Hints
86
87
\QMLLS includes a documentation hints feature that
88
provides programmers with quick access to Qt’s documentation
89
by hovering over a keyword. In order to use this feature, your
90
Qt kit should contain the Qt documentation and your project
91
should be built with \l{QT_QML_GENERATE_QMLLS_INI} variable.
92
93
\section1 Setting up \QMLLS in Your Editor
94
95
This section describes how to develop the \QMLLS client or how to
96
use your own \QMLLS client.
97
98
You can find the \QMLLS binary under
99
\c{<Qt installation folder>/bin/qmlls} in installations of Qt
100
made with \QOI. If you want your \QMLLS client to download the binary
101
directly, 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.
108
You can pass the build folder in the following ways.
109
110
\section3 AddBuildDirs LSP Extension
111
112
To pass build directories via the LSP extension, send a notification
113
to \QMLLS for the \c{$/addBuildDirs} method. \c{$/addBuildDirs}
114
accepts one parameter of the form:
115
\badcode
116
interface AddBuildDirsParams {
117
buildDirsToSet: UriToBuildDirs[];
118
}
119
\endcode
120
where \c{UriToBuildDirs} contains a workspace URI and a list of build
121
directories.
122
The 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}
124
or
125
\l{https://microsoft.github.io/language-server-protocol/specifications/lsp/3.17/specification/#workspace_didChangeWorkspaceFolders}{didChangeWorkspaceFolders}.
126
The build directories are file paths, not URIs.
127
\badcode
128
interface UriToBuildDirs {
129
baseUri: URI;
130
buildDirs: string[];
131
}
132
\endcode
133
134
\section3 --build-dir Command Line Option
135
136
If you don't need to support multiple workspaces, you can pass the build
137
directories via the \c{--build-dir} command line option. In this case
138
your editor should invoke \c{qmlls} as following:
139
\badcode
140
<path/to/qmlls> ... --build-dir <path/to/build-directory> ...
141
\endcode
142
143
The build directory will be applied to all workspaces if you use multiple
144
workspaces in the same \QMLLS. The values from \c{addBuildDirsMethod}
145
have higher precedence than the command line option.
146
147
\section3 QMLLS_BUILD_DIRS Environment Variable
148
149
You can also pass the build directories via the \c{QMLLS_BUILD_DIRS}
150
environment variable. The build directory will be applied to all
151
workspaces if you use multiple workspaces in the same \QMLLS.
152
The values from \c{--build-dir} have higher precedence than the
153
environment variable.
154
155
\section3 \c{.qmlls.ini} Settings File
156
157
If you can't pass the build directories using one of the previous options,
158
you could try passing build directories to \QMLLS via a configuration file.
159
See also \l{Configuration File}.
160
The values from the settings file have lower precedence than
161
\c{--build-dir}, \c{QMLLS_BUILD_DIRS}, and \c{addBuildDirsMethod}.
162
163
\section2 Configuring Module Import Completion
164
165
\QMLLS searches the import paths in the background for QML modules to suggest
166
them when completing an \c{import} statement.
167
168
To disable this feature, use the following ways:
169
\list
170
\li The \c{--no-module-exploration} command line option.
171
\li The \c{QMLLS_NO_MODULE_EXPLORATION} environment variable.
172
\li The \c{.qmlls.ini} settings file, see \l {Configuration File}.
173
\endlist
174
175
\section2 Configuring Automatic CMake Builds
176
177
\QMLLS runs CMake on its own, without being asked by the user or the client.
178
On startup, and whenever it detects that the source code of a C++ defined QML
179
type has been modified, it runs
180
\code [cmake]
181
cmake --build <build-directory> -t all_qmltyperegistrations
182
\endcode
183
for each build directory in use. Building this target
184
can compile C++ code, run code generators, and re-run the CMake configuration
185
step, which executes the \c{CMakeLists.txt} files of the project.
186
187
The build directories are taken from the sources described in
188
\l{Setting up the Build Directory}. If none of the other sources provides a
189
build directory for an opened QML file, \QMLLS uses the \c{buildDir} entry of
190
the nearest \c{.qmlls.ini} file found by walking up the directory tree from the
191
opened file. Because that file is part of the project, opening a QML file from a
192
project with a \c{.qmlls.ini} file can start a build of a build directory chosen
193
by the project.
194
195
\warning Do not open QML files from untrusted locations with an editor that uses
196
\QMLLS. Building an untrusted project can execute arbitrary code with your
197
privileges. See also \l{Using Qt's Developer Tools Securely}.
198
199
To disable this feature, use the following ways:
200
\list
201
\li The \c{--no-cmake-calls} command line option. In this case
202
your editor should invoke \c{qmlls} as follows:
203
\badcode
204
<path/to/qmlls> --build-dir <path/to/build-directory> --no-cmake-calls
205
\endcode
206
\li The \c{QMLLS_NO_CMAKE_CALLS} environment variable.
207
\li The \c{.qmlls.ini} settings file, see \l {Configuration File}.
208
\li The \l{QT_QML_GENERATE_QMLLS_INI_NO_CMAKE_CALLS} CMake variable
209
if \l{QT_QML_GENERATE_QMLLS_INI} is enabled.
210
\endlist
211
212
The \c{--no-cmake-calls} command line option and the \c{QMLLS_NO_CMAKE_CALLS}
213
environment variable take precedence over every other setting. When either of
214
them disables CMake calls, a \c{.qmlls.ini} file cannot re-enable them. In
215
contrast, the \c{no-cmake-calls} entry of a \c{.qmlls.ini} file is only
216
consulted if neither of them is set. The nearest \c{.qmlls.ini} file to the
217
opened file wins, so a \c{.qmlls.ini} file shipped with a project takes
218
precedence over one in a parent directory, such as your own. To reliably
219
prevent \QMLLS from running CMake, regardless of the projects you open,
220
pass \c{--no-cmake-calls} on the command line or set
221
\c{QMLLS_NO_CMAKE_CALLS} in the environment of \QMLLS.
222
223
To control the number of jobs used by CMake, use
224
\list
225
\li The \c{--cmake-jobs} command line option. In this case
226
your editor should invoke \c{qmlls} as follows:
227
\badcode
228
<path/to/qmlls> --build-dir <path/to/build-directory> --cmake-jobs <jobs>
229
\endcode
230
\li The \c{QMLLS_CMAKE_JOBS} environment variable.
231
\li The \c{.qmlls.ini} settings file, see \l {Configuration File}.
232
\endlist
233
Accepted values are integers greater than 0 and \c{max} to use all available
234
cores.
235
236
\section2 Modifying the maximum amount of files to search
237
238
\QMLLS respects a limit of files to search when searching the source
239
folders for headers, for example when going to the definition of a QML
240
component defined in a C++ header.
241
242
To set the maximum amount of files to search, write a numeric value in the
243
\c QMLLS_MAX_FILES_TO_SEARCH environment variable. 0 disables the file
244
searching feature, 20000 is the default value.
245
246
\section1 Configuration File
247
248
\QMLLS can be configured via a configuration file \c{.qmlls.ini}.
249
This file should be in the root source directory of the project.
250
It should be a text file in the ini-format.
251
252
The configuration file can have the following entries:
253
\code
254
// .qmlls.ini
255
[General]
256
no-cmake-calls=<true-or-false>
257
CMakeJobs=<some integer value>
258
259
buildDir=<path/to/build-directory> # not required in Qt 6.10 and later
260
docDir=<path/to/qt-documentation> # not required in Qt 6.10 and later
261
importPaths=<path/to/imports> # not required in Qt 6.10 and later
262
\endcode
263
264
To use the configuration file to disable the automatic CMake rebuild
265
functionality, set \c{no-cmake-calls} to \c{true}.
266
267
To control the number of jobs used by automatic CMake rebuilds, set the
268
CMakeJobs value.
269
270
To support clients that can't pass the build directory to \QMLLS, as
271
described in \l{Setting up the Build Directory}, set the buildDir value
272
or let CMake generate the .qmlls.ini via \l {QT_QML_GENERATE_QMLLS_INI}.
273
274
\note \QMLLS can create default configuration files
275
using the \c{--write-defaults} option. This will overwrite an
276
already existing .qmlls.ini file in the current directory.
277
278
\section1 Known Limitations
279
280
Despite covering many common QML features, \QMLLS is still in development with some features
281
yet to be supported:
282
\list
283
\li Suggesting autocompletions on invalid QML files.
284
\li Autocompleting context properties
285
\endlist
286
287
\QMLLS might emit false positive warnings on projects
288
\list
289
\li using QMake or imperative type registration---see \l{Port QML modules to CMake}
290
\li that were not built---\QMLLS uses the build information to find QML modules
291
\li where QML modules don't follow the guidelines in \l{Modernizing QML Modules}
292
\endlist
293
294
*/
qtdeclarative
src
qml
doc
src
tools
qtqml-tooling-qmlls.qdoc
Generated on
for Qt by
1.18.0