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