generate.ts: update types to 3.17 specification


Update the generate.ts script to use the metaModel specified in the 3.17
specification. The new specification contains aliases and anonymous
object literals, which require rewriting some code in generate.ts. This
exercise allowed to spot some bugs in our LSP classes, see also later
patches in the relation chain.

Some types declared in qlanguageserverspectypes_p.h moved up to be
declared before their new usages in protocol version 3.17.

In no particular order:
* Remove the special casing for WorkDoneProgress(Begin|End|...): we now
  have information on hardcoded string literals and can directly
  hardcode them in C++ code emitted by generateProperty().
* replace most of previously existing types with the types from the
  metamodel.
* the protocol introduced the recursive types LSPAny, LSPObject, and
  LSPArray in 3.17. Use QJson(Value|Object|Array) to represent them. It
  turned out that implementing our own versions of them comes with lots
  of challenges: qt container types do not support the recursive
  inheritance, which leads to weird compile errors like QTBUG-146007 or
  QTBUG-146563. Also, to make a custom LSPAny class usable you have to
  implement methods to get the underlying type (string, int, ...), which
  is exactly what QJsonValue offers, so lets not reinvent the wheel here.
* map metamodel types to C++ types via typeToCppType(), some
  differences to the previous code in effectiveType():
 * * remove regexp parsing
 * * the literalObjectName argument to typeToCppImpl allows to generate
     C++ types for the anonymous object literals. The specs repeatedly
     contains aliases to variants containing anonymous object literals,
     and we want to be able to use these types. Currently they have
     dummy names like
     using PrepareRenameResult =
             std::variant<Range,
                 PrepareRenameResultVariant1,
                 PrepareRenameResultVariant2>;
* adapt the struct sorting algorithm to support aliases
 * * add collectDependencies() that lists all dependent types and use
     it with
     calculateOrderingOfGeneratedClassesAndAliases to get an ordering of
     structs and aliases such that each usage happens after its definition.
     Try to keep the ordering the same to avoid too much diff in the
     generated classes.
* the specification 3.17 have invisible base types in its metaModel, for
  example RenameFile has no base type in the html version of the
  protocol but has a ResourceOperation base type in the metamodel. Just
  treat those invisible basetypes as normal basetypes.
* the specification also added "mixins" that seem to be some kind of
  base types, treat them as normal base types.
* generate `using T = ...` type aliases for the metamodel type aliases
* remove all the specification.md parsing code
* move types from the Responses namespace into the Requests namespace
* don't overwrite qlanguageservergen_p_p.h with a constant value:
  proto.registerVars.join("\n") used to be empty in the previous script,
  so remove the code that writes this file (but keep the file checked in).
* Update the package.json to include the command needed to compile the
  .ts files to .js.
* Use enum types instead of QJsonValue in struct properties.
* Make all base types public in our generated C++ classes, instead of
  just making the first one public.
* There is a helper variant called RequestParams and NotificationParams
  that contains a variant of all the possible parameter types that
  requests and notifications can take. The variant is used like a
  generic argument type in ProtocolBase::handleUndispatchedRequest()
  that can be constructed from any argument type... except when it
  contains duplicate, in that case the constructors are deleted.
  Therefore sort the variant entries and remove the duplicates.

Task-number: QTBUG-141713
Change-Id: I873d9632395b2ebf34ef140e069556d7df9dbf6b
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
commit7e949e315eea494aa812a34afe35bfdb120c9ef7
parent572acadaae3cd5aa70cbaadf781c9beae9cb97fd
authorSami Shalayel <sami.shalayel@qt.io>
committerSami Shalayel <sami.shalayel@qt.io>
commit timeMon, 11 May 2026 06:14:30 +0000