Commit Graph

50 Commits

Author SHA1 Message Date
Artem Sokolovskii
e396f84d10 SyntaxHighlighter: Move generic highlighter to separate thread
Adds a full copy of KSyntaxHighlighting::Repository class
to the Highlighter class, enabling the relocation of the
Highlighter class to a separate thread. This adjustment ensures
that all Definitions come from the copy of the repository, making
them immutable from external code.

The "reload Definition" function stays supported, as triggering
it results in the recreation of the highlighter for the document,
thereby reconstructing the Repository class.

Change-Id: Id7a4d865228c7e7e20e4770601a3fde55b8a6513
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2023-12-12 13:03:59 +00:00
Artem Sokolovskii
62ea85ee6a SyntaxHighlighter: Move SyntaxHighlighter to separate thread
This change involves the relocation of SyntaxHighlighter processing
to another thread. The core idea is to create a duplicate of the
original TextDocument using SyntaxHighlighterRunnerPrivate::cloneDocument.
A new SyntaxHighlighter is then instantiated by SyntaxHighLighterCreator
for the cloned document. The entire SyntaxHighLighterCreator class is
moved to a new thread, where it performs highlighting on the cloned
document. Upon completion of the highlighting process, the resultsReady
signal is emitted, and the updated highlighting data is applied to the
original document.

This shift of SyntaxHighlighter to another thread enhances the user
experience by preventing UI slowdowns during the highlighting process.

- Introduction of BaseSyntaxHighlighterRunner as an interface class for
future *SyntaxHighlighterRunner.
- Inclusion of DirectSyntaxHighlighterRunner class for performing
highlighting in the main thread, suitable for syntax highlighters
that cannot be moved to another thread.
- Introduction of ThreadedSyntaxHighlighterRunner class for highlighting
in a separate thread, preventing UI blocking during the process.
- Addition of Result data to the SyntaxHighlighter class to facilitate
data exchange between threads.

Task-number: QTCREATORBUG-28727
Change-Id: I4b6a38d15f5ec9b8828055d38d2a0c6f21a657b4
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2023-12-11 09:55:02 +00:00
Artem Sokolovskii
b26c43f133 SyntaxHighlighter: Move static functions to other namespace
- Created HighlighterHelper namespace and static functions
were moved there from the highlighter class

Change-Id: Ib93785a3819317d7c1d5cc480652d4635cb9339b
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
2023-11-20 16:04:59 +00:00
hjk
342e066886 Utils, all: Standardize on QtcSettings
Change-Id: Id222016f15b1c3bfe6710fe5d0297666d4565ef1
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
2023-09-27 13:25:31 +00:00
David Schulz
f385324bc8 TextEditor: fix highlighting after removing line
We cannot reconstruct the correct initial state for highlighting when
deleting a line if we generally save the after highlight state to the
next line.

Change-Id: I7d5f727f6b7c8340ac7f5436046cd0f1ad17ebd2
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2023-05-26 12:15:43 +00:00
hjk
17b20e0622 TextEditor: Tr::tr
Change-Id: I28aa68e25c53c3a4d1c370074d7b3318944dc45a
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2023-01-18 07:02:12 +00:00
Kai Köhne
56baf8c058 Remove GPL-3.0+ from license identifiers
Since we also license under GPL-3.0 WITH Qt-GPL-exception-1.0,
this applies only to a hypothetical newer version of GPL, that doesn't
exist yet. If such a version emerges, we can still decide to relicense...

While at it, replace (deprecated) GPL-3.0 with more explicit GPL-3.0-only

Change was done by running

  find . -type f -exec perl -pi -e "s/LicenseRef-Qt-Commercial OR GPL-3.0\+ OR GPL-3.0 WITH Qt-GPL-exception-1.0/LicenseRef-Qt-Commercial OR GPL-3.0-only WITH Qt-GPL-exception-1.0/g" {} \;

Change-Id: I5097e6ce8d10233993ee30d7e25120e2659eb10b
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2023-01-06 11:15:13 +00:00
Eike Ziller
b41abc94bb Fix highlighting of debugger disassembly view
The disassembly view uses a custom MIME type that derives from x-asm,
but that didn't trigger highlighting.

Make the generic highlighter look at the parent MIME types if no
highlighting was found for the MIME type itself.

Generalize this "go breadth-first through the parents" that was already
used for resolving editor factories.

Change-Id: Ia054058a8c06b9d8849384e79ee3b83fbc12279c
Reviewed-by: David Schulz <david.schulz@qt.io>
2023-01-03 13:57:00 +00:00
Jarek Kobus
bc4c1faf73 Fix logical XOR
The '^' is the bitwise XOR, we should use logical XOR in
these contexts. The operator!=() should serve for it.

More info and reasoning:
https://stackoverflow.com/questions/24542

Change-Id: I1bd70bdcab25455f409594f0f14c209d1de11d18
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: hjk <hjk@qt.io>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-10-07 07:42:22 +00:00
Eike Ziller
ccfd472a8c Generic highlighter: Try mime type aliases when looking for definitions
For example the yaml highlighting file declares text/yaml as the
supported mime type, but that is not the canonical name, which is
application/x-yaml.

Change-Id: If9e3f5e31bc5593a82cbbdac916ef41b0d23de7c
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-09-21 07:03:01 +00:00
Lucie Gérard
a7956df3ca Use SPDX license identifiers
Replace the current license disclaimer in files by
a SPDX-License-Identifier.

Task-number: QTBUG-67283
Change-Id: I708fd1f9f2b73d60f57cc3568646929117825813
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2022-08-26 12:27:18 +00:00
Dmitry Shachnev
4d9215e44d Correctly include KSyntaxHighlighting headers
In external KSyntaxHighlighting, these headers now have paths like
/usr/include/KF5/KSyntaxHighlighting/KSyntaxHighlighting/AbstractHighlighter,
where /usr/include/KF5/KSyntaxHighlighting is passed to compiler as include
path.

Old headers which had only one KSyntaxHighlighting fragment in path were
removed in v5.94.0:
https://invent.kde.org/frameworks/syntax-highlighting/-/merge_requests/305

Adjust our vendored version to make the code work with both external and
vendored versions.

Change-Id: Iadcc668c3c705c563ae359301d227ee19eadca0f
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: David Schulz <david.schulz@qt.io>
2022-05-24 11:28:08 +00:00
Eike Ziller
f562ebf239 Mimetypes: Make implementation switchable between new and old
- configure with QTC_USE_NEW_MIMEDATABASE to switch to the new one in
  utils/mimetypes2/
- added utils/mimeutils.h header for the Qt Creator specific static
  wrappers, that also includes the "public" headers for MimeType et al
  from the new or old implementation, depending on configuration
- change all utils/mimetypes/ includes to utils/mimeutils.h
- move the implementation for the wrappers to
  utils/mimetypes(2)/mimeutils.cpp
- also move the MimeDatabase declaration in the "old" implementation
  back to utils/mimetypes/mimedatabase.h

Change-Id: Ie8de229c035d6cd9a5e4739dc0fa78d9c17228e3
Reviewed-by: Jarek Kobus <jaroslaw.kobus@qt.io>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
2022-02-25 07:19:58 +00:00
hjk
8b7f9bacb2 TextEditor: Use FilePath in HighlighterSettings
Change-Id: I1002d3a0b16e403e1650475ec316adf797251a1f
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-09-28 06:43:38 +00:00
hjk
d97c10a42e TextEditor: highlighter.cpp code cosmetics
static, namespaces.

Change-Id: Id824f6979ce6c6ec6bbe4847c808c7ae47d26695
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-30 06:49:23 +00:00
hjk
bce19b73c5 TextEditor: FilePathify Repository *highlightRepository()
Change-Id: I66ed44e199fa26b28e23497c2650224e6331baa7
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-30 06:48:58 +00:00
David Schulz
ad4803ccc8 Editor: fix folding for Markdown
Fixes: QTCREATORBUG-25882
Change-Id: I46048a191f4dd9bb2f7c3029f8555066bb8451ab
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-21 11:11:49 +00:00
David Schulz
50853bba61 Editor: highlight qtquickcontrols2.conf as ini files
Fixes: QTCREATORBUG-25878
Change-Id: Ib9e4780d3374ed6a842ea38c1f3a356085f01c2b
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-21 08:38:25 +00:00
David Schulz
38bbd6eb8c Editor: remove FilePath::toFileInfo in syntax highlighter
Change-Id: I205c16d227368f13baef8c8db3e1c9f4de2a4d69
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2021-06-09 12:26:05 +00:00
David Schulz
aa8d2dc2d1 Utils: add FilePath::(complete)suffix
The same as FilePath::(complete)baseName avoid some toFileInfo.

Change-Id: Id1901ce2a4bef675215a9e020280df1c846df405
Reviewed-by: hjk <hjk@qt.io>
2021-06-04 09:32:52 +00:00
David Schulz
5ec611b68e Utils: add FilePath::completeBaseName
Removing some FilePath::toFileInfo() calls again.

Change-Id: I6610beebf2c30754fde525b71f4c4a34ceb5e30b
Reviewed-by: hjk <hjk@qt.io>
2021-06-04 07:07:07 +00:00
hjk
8e352af0ec Core: Add a default parameter to various ICore::*path functions
Saves some code on the user side.

Change-Id: I32cd220b6e533f5497a1865f9c34ab9db4cfda79
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-04-27 06:52:05 +00:00
Eike Ziller
c1f90aeca2 ICore: Change some path API to use FilePath
Change-Id: Id841d6177206a021c9e606ce560b47d1ae6e52b9
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: hjk <hjk@qt.io>
2021-04-26 08:03:47 +00:00
Eike Ziller
efa0f74645 TextEditor: Do not pop up general messages pane
General messages pane should only be opened on direct user interaction.

Task-number: QTCREATORBUG-24430
Change-Id: I62f6849ca5a32f0a75c5a91a667ee704d3632d1a
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-01-04 12:45:37 +00:00
David Schulz
62e7d7eb49 Editor: Highlight cmake configure_file input files
Usually cmake configure input files have the *.in suffix, so if we can
not find highlight definitions for a filename and it has the .in suffix
try again without that suffix.

Fixes: QTCREATORBUG-24465
Change-Id: I7a132eb407c299eb1670e89e2d043a924aed1ede
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2020-09-28 09:23:03 +00:00
David Schulz
150d29a8fd TextEditor: Fix remembering highlight definition
Amends 6989c9bbea

Since the change above the filename is checked before the mimetype, so
we have to save it in the same order.

Fixes: QTCREATORBUG-24505
Change-Id: Ib974dc0f69ca56cfd6ee9e34bec238e62f800598
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2020-08-19 12:40:51 +00:00
Eike Ziller
6989c9bbea Highlighter: Fix resolution of highlighting definition
We should try to find a definition based on the file path first, before
falling back to the MIME type, since MIME types are not extensible. So,
if we find a definition for a MIME type, there could be others, more
suited ones based on the file path.

Fixes: QTCREATORBUG-7906
Change-Id: I9b35efb26d287dd4c975a8944fca9a310c417394
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-03-24 12:53:50 +00:00
Eike Ziller
d0589d7f6e Highlighter: Fix typo
Change-Id: I491f7c58733a333a5cdcf2ebae67f9d4bff1eeef
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-03-24 12:49:43 +00:00
Eike Ziller
289c9e959c Highlighter: Remove unused methods
We want all the possible definitions nowadays.

Change-Id: I491d40b103a2daf187571910bb43c32e0bfbb1e4
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-03-24 12:35:49 +00:00
Eike Ziller
69bcf7ca60 Merge remote-tracking branch 'origin/4.11'
Change-Id: Ica0d173a08ff3f0296e875aa324d5bb6974bd90f
2020-01-08 07:13:32 +01:00
David Schulz
a163bcd8b0 Editor: always set format for visual whitespace
Change-Id: I2ab4cb9f77d649c1c7d51dec1ef11005325a4710
Fixes: QTCREATORBUG-23040
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2020-01-07 12:28:07 +00:00
Nikolai Kosjar
548e798885 TextEditor: Fix typo in a TextDocumentLayout function
Change-Id: I17153d9bfe9820f3ccc88f54bce1d494a522be33
Reviewed-by: David Schulz <david.schulz@qt.io>
2019-12-18 10:15:50 +00:00
Christian Stenger
9ac4e29a20 Move helper functions to more public location
Change-Id: I12a2000bfc82c194d12fb5c25302a06f782aa605
Reviewed-by: David Schulz <david.schulz@qt.io>
2019-11-15 12:00:31 +00:00
David Schulz
2c112a51c3 Highlighter: update all editors after downloading additional definitions
Instead of just the editor with the info bar that was triggering the
download action or none editor if the action was triggered from the
settings dialog.

Change-Id: I4158eeb7fdb0a763d082c6d801b400e8635c7f38
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-11-04 13:45:19 +00:00
David Schulz
5ece12d4ea Highlighter: clarify 'Update Definitions' action
by renaming it to Download Definitions and adding a tooltip stating that it
collects all definitions that are missing or were updated after the release and
downloads it to the ksyntax highlighting user folder.
Also adding a separate reload definitions button in the settings behind
the user path.

Change-Id: I059cc98e33147cae910fa4fdb35631d1dca81448
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-11-04 13:23:58 +00:00
David Schulz
06026b7cf4 Highlighter: Apply specific ksyntax format attributes
If a ksyntax format explicitly defines font attributes like bold,
italic, underline or strike through we now apply those attributes. If
the format defines a colors, we first check whether the color is
readable before setting it.

Fixes: QTCREATORBUG-22646
Fixes: QTCREATORBUG-22229
Fixes: QTCREATORBUG-13545
Change-Id: Id0389b3c71a078dc6d6df74ee5de7f5d479a9bcb
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-07-08 04:46:36 +00:00
David Schulz
6dde7767ce Highlighter: Use file pattern matching if mime type is 'text/plain'
Do not try to match 'text/plain' mime types against highlight
definitions, because it is automatically set if the file contains just
printable characters in the first bytes, in this case file pattern
matching gives better results.

Fixes: QTCREATORBUG-22540
Change-Id: Ifd662cd6961011f5cf5d9232ce5f17d2314b4824
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-06-24 08:21:44 +00:00
Eike Ziller
9d39e68173 Merge remote-tracking branch 'origin/4.9' into 4.10
Change-Id: I7725557a279cc13fe03a72c20accf63b50571608
2019-06-12 07:21:15 +02:00
David Schulz
6fd355b84b TextEditor: force rehighlight of next block if state changed
If the user state of a block changes while it gets highlighted
the next block will be rehighlighted too. Currently we store the
indentation depth in the block user state. So in order to store the
indentation depth _and_ the information whether the next block needs
to be rehighlighted we bit shift the indentation depth via the
brace depth helper functions from TextDocumentLayaout. And we cannot
store the struct KSyntaxHighlighting::State in the block user state (int)
directly to indicate that the next block also needs a rehighlight so we
toggle just the last bit of the user state.

Fixes: QTCREATORBUG-22290
Change-Id: I632f4416a725dc5fa1667bcab34fb2701294c9b8
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-06-07 05:20:36 +00:00
hjk
473a741c9f Utils: Rename FileName to FilePath
More in line with QFileInfo terminonlogy which appears to be
best-of-breed within Qt.

Change-Id: I1d051ff1c8363ebd4ee56376451df45216c4c9ab
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2019-05-28 12:23:26 +00:00
David Schulz
ccb5f2302d TextEditor: fix folding regression in generic highlighter
Fixes: QTCREATORBUG-22346
Change-Id: Ib35a70da77ffaa3b84e1d85a855625e2086625da
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-05-03 08:59:34 +00:00
David Schulz
429eb73ace TextEditor: fix highlighting whitespaces with ksyntax highlighter
Fixes: QTCREATORBUG-22097
Change-Id: Ia69198635e289fc6eff8d95bf1cdf59bda2e04e1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-03-14 09:44:11 +00:00
David Schulz
792fe95c00 TextEditor: Fix matching parenthesis highlight reggression
The update to the new KSyntaxHighlight engine was missing the matching
parenthesis highlight that was implemented in the generic highligter.

Fixes: QTCREATORBUG-22095
Change-Id: Ibac0f0739b4e1df63aadf0f18f1b76873e63a2fc
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-03-07 10:28:38 +00:00
Christian Stenger
6aed8223a9 SyntaxHighlighter: Update to latest master
Adapt the respective include inside the TextEditor.

Change-Id: Ie3cb17f1b0e3c0639840bc135156edd354a0aeda
Reviewed-by: David Schulz <david.schulz@qt.io>
2019-03-04 12:55:55 +00:00
David Schulz
8a0f7bcfd5 TextEditor: add option to remember highlighter definition
Add a button to the multiple definition found info that saves the
definition of the current highlighter for the open document.

Change-Id: I04b1b7571a864d781747547a1d315ec25bb6b5a1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
2019-02-28 07:14:43 +00:00
David Schulz
82466375b9 TextEditor: Show info when multiple highlight definitions are available
Show an editor info bar when multiple highlight definitions can be found
for a single file or mime type. Add a combo box to the info that allows
the user to choose between them.

Change-Id: I07278d065e19d4e04fba24a6d789c8b6c9f55d60
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2019-02-11 12:45:04 +00:00
David Schulz
67b0d9be2e TextEditor: return all definitions for a file name/mimetype/document
Change-Id: Ifd4ee9ab71b95a66cf11e30e2de688d421094a4a
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-02-07 13:48:50 +00:00
David Schulz
f75934f297 TextEditor: shorten namespace noise
Change-Id: I16bc218ccefb7234cb9c1299ee3022549b178600
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-02-07 12:51:27 +00:00
David Schulz
f4a45884ca TextEditor: add convenient definition for document function
Change-Id: I8bbaec71a4682e36d3919924932b410e2e9d74a9
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-02-07 12:51:19 +00:00
David Schulz
14834e6b0a TextEditor: replace generic highlighter with ksyntaxhighlighting
Fixes: QTCREATORBUG-21029
Change-Id: I9894c4384e0e47da6bf030b7b8e07c3ad4737ff3
Reviewed-by: Orgad Shaneh <orgads@gmail.com>
2019-01-28 11:37:08 +00:00