Commit Graph

121 Commits

Author SHA1 Message Date
David Schulz
4324f3e8c1 Editor: pass AssistInterface to createProcessor
The interface can be used for checking the context of a codeassist
request to determine
the correct processor that has to be created.

Change-Id: I47ddb05c46399566e27bae21711f11a3a4132c3f
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-16 08:25:36 +00:00
David Schulz
28447355ba Editor: reuse generic proposal widget
Do not close already visible proposal widget if we get new results for
the same base position. Just replace the model of the widget and update
the prefix.

Change-Id: I298aba6eb8177edc17fea783189a2f987dbf15a2
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-09-02 11:04:55 +00:00
Christian Kandeler
dc4a8b3866 TextEditor: Allow incremental proposals
... and make use of them with clangd.
This way, users can get immediate feedback when a new proposal entry
has been found, rather than having to wait until all of them have been
collected.

Change-Id: I2adfe0153aa7a058f28eb3bd65c71dd30ea018e0
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-18 11:43:08 +00:00
Christian Kandeler
b0d4fc359f ClangCodeModel: Let user choose the override
.... when following virtual function calls.
This brings us up to par with the built-in code model.
We do lose the icons, but they are of very little use in this context.

Change-Id: I29b27d538e7277d06a5af7acee07bddb6eb94c98
Reviewed-by: David Schulz <david.schulz@qt.io>
2021-06-01 08:22:21 +00:00
David Schulz
ba83b852b6 Editor: Close function hint proposal on destroyContext
Fixes: QTCREATORBUG-25691
Change-Id: I2cb1b52fdda386cbfe3ca7f54746edd3e5562ea0
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-05-17 09:57:52 +00:00
David Schulz
a86da031c7 TextEditor: Fix is visible check of function hint
Since the FunctionHintProposalWidget is just a proxy witget that uses a
FakeToolTip it is not shown directly so we cannot check the visibility
with isVisible.

Fixes: QTCREATORBUG-25664
Change-Id: I6888e373afcfc79565ce8e3dad1bb05501d58200
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2021-05-05 10:11:21 +00:00
Jarek Kobus
e3ae92bc5f TextEditor: Use invokeMethod instead of singleShot timer with 0 delay
Use QCoreApplication::instance() as a context object for the
IAssistProposal deleter.

Change-Id: Idf8cd1955dca146a500da1ea036298455c8a5da1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2021-02-02 08:15:28 +00:00
David Schulz
859d2edbb5 TextEditor: Always destroy old context when displaying new proposal
This makes sure that the old proposal widget is disconnected from the
finalizeProposal slot and thus prevents resetting the currently shown
proposal.

Change-Id: I80d58d9a04831d464bea69697568359990ac5260
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-10-26 05:00:49 +00:00
David Schulz
a962a08b1a Editor: fix completion character completions
Cleanup the proposal after an item is activated even if the proposal
widget is not visible anymore. Otherwise we might wrongly cleanup a
proposal that was triggered by a completion character while a completion
list was already open.

Change-Id: Ie95247de09313c5816cffd9a865b05183db02354
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-10-19 15:56:47 +00:00
David Schulz
2842b613ed TextEditor: request assist after trigger char inserted
... while proposal is shown

amends 23d63dcc8b

Fixes: QTCREATORBUG-24225
Change-Id: Ie935c7c1d4786a4fd3cf338d7f1df52ae28de63b
Reviewed-by: David Schulz <david.schulz@qt.io>
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-10-05 09:05:25 +00:00
David Schulz
a36bdfc858 Revert "CodeAssist: Avoid pointless completion request after accepting item"
is replaced by 23d63dcc8b

This reverts commit 44b71f7a16.

Change-Id: Ib5adaab4a962a54495b48e6b88ab164046526c37
Reviewed-by: Christian Kandeler <christian.kandeler@qt.io>
2020-10-02 09:32:02 +00:00
Christian Kandeler
23d63dcc8b TextEditor: Do not invoke auto-completion recursively
It's unclear why that was done, and it threw off the clang code model by
introducing an unexpected sequence of events.

Fixes: QTCREATORBUG-18676
Change-Id: I4dabb56eb97e18141080c22be324c826202977ce
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-09-11 11:44:35 +00:00
Eike Ziller
7aa0b1ea6b TextEditor: Fix build with Qt6
Adapt to QStringRef and QAbstractItemView::viewOptions() removal

Task-number: QTCREATORBUG-24098
Change-Id: Ia2d446312f68bd60143796284d31f5bba56aa0ed
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-09-08 07:47:30 +00:00
Christian Kandeler
7938320291 TextEditor: Introduce shortcut for forcing a function hint proposal
... and support it in the ClangCodeModel.
This allows users to get function signature(s) displayed regardless of
where exactly the cursor is on the function call.

Fixes: QTCREATORBUG-19394
Change-Id: I033e8774db93680bfc3ee52610b817e0ef8ccc76
Reviewed-by: David Schulz <david.schulz@qt.io>
2020-08-11 10:10:08 +00:00
David Schulz
755de9f86a Editor: delete processor after canceling
Set a null proposal has the potential to restart the processor
in combination with the invalidateCurrentRequestData from this
cancelCurrentRequest will result in a restarted processor that is not
tracked via m_asyncProcessor.

Change-Id: Ia0e0d49564170a1e705994933d07e00c23f24f5d
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-05-14 10:44:57 +00:00
David Schulz
738726d656 Editor: delete the processor that proposes a result
Not the currently active one.

Change-Id: Ia0e146e61c07564107ca5a3ec6b5b2d65967f572
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-05-14 10:44:45 +00:00
David Schulz
8bde432dfe CodeAssist: Fix leaking asynchronous processors
Currently the ownership of the processor is unknown to the codeassist
when running an async operation. Move the ownership of the processor to
the assist and delete the processor after the proposal was completed.

Change-Id: I6a2e023c47cbc876669dba866bee12b481447cb7
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-05-12 08:24:41 +00:00
David Schulz
552ccd6a61 CodeAssistant: add cancel to asynchronous processors
Fixes crash when the processor reports a result after the code assistant
was destroyed.

Change-Id: I8588d3d6acad69f1ec6302e8ba09d642ebbb77f1
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2020-02-20 12:59:55 +00:00
hjk
251287f0d3 Avoid warning on empty expressions
For some reason, Q_UNUSED includes already a semicolon, adding one
on the user side creates an additional empty statement.

Change-Id: I9c5e8fac381345a60792cb75e2938fd53958d3b0
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-07-23 11:55:59 +00:00
David Schulz
b0039f1ec8 LanguageClient: add signature help provider
Change-Id: Ia89c28b574c92802bbfda280115a50f5955f0854
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2019-05-21 05:46:37 +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
Nikolai Kosjar
44b71f7a16 CodeAssist: Avoid pointless completion request after accepting item
Previously, accepting an item from the completion pop-up triggered
another completion request, but the result of that request was never
displayed since the inserted text was a perfect match.

Now, trigger another completion request only if the inserted text
matches the activation characters.

Change-Id: Ic8ed4139efb10aadc8d41105634fcc856e0a15be
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2018-11-06 10:01:25 +00:00
Nikolai Kosjar
5601ac2952 TextEditor: Fix requesting more proposals than needed
Since

    commit d61d29cf16
    Introduce a basic client for the language server protocol

extra proprosals were requested in the fragile case on a change
notification, e.g. for function signature completion. Restrict this to
the language client proposal, as it was actually intended.

The language client does not support prefixes, so introduce this concept
for deciding whether to request new proposals or not.

Done-with: David Schulz
Change-Id: Ibc1ad82dbeeea93b85f279c59b8c7289fe6ec726
Reviewed-by: David Schulz <david.schulz@qt.io>
2018-10-23 13:10:52 +00:00
David Schulz
5719adc47c LSP: rerequest completion if contents change while processing
Task-number: QTCREATORBUG-21108
Change-Id: I6ca7920e7099dba0ba1bc953a2e6296bd86c1dc1
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-10-19 08:46:13 +00:00
Orgad Shaneh
41dee83bec TextEditor: Modernize
override, auto, nullptr, member initializers.

Change-Id: I04c6ebb683849568973bd7782fb5a3279267141e
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-09-20 08:48:49 +00:00
David Schulz
d61d29cf16 Introduce a basic client for the language server protocol
The language server protocol is used to transport language specific
information needed to efficiently edit source files. For example
completion, go to operations and symbol information. These information
are transferred via JSON-RPC. The complete definition can be found under
https://microsoft.github.io/language-server-protocol/specification.

This language server protocol support consists of two major parts, the
C++ representation of the language server protocol, and the client part
for the communication with an external language server.

The TypeScript definitions of the protocol interfaces are transferred to
C++ classes. Those classes have getter and setter for every interface
value. Optional values from the protocol are represented by
Utils::optional<ValueType>. The JSON objects that are used to transfer
the data between client and server are hidden by a specialized
JsonObject class derived from QJsonObject. Additionally this JsonObject
provides a validity check that is capable of creating a detailed error
message for malformed, or at least unexpected JSON representation of the
protocol.

The client is the interface between Qt Creator and language server
functionality, like completion, diagnostics, document and workspace
synchronization. The base client converts the data that is sent from/to
the server between the raw byte array and the corresponding C++ objects.
The transportat layer is defined in a specialized base client (this
initial change will only support stdio language server). The running
clients are handled inside the language client manager, which is also
used to connect global and exclusive Qt Creator functionality to the
clients.

Task-number: QTCREATORBUG-20284
Change-Id: I8e123e20c3f14ff7055c505319696d5096fe1704
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-09-03 08:00:46 +00:00
David Schulz
8749ccc69f TextEditor: sync code completions in snippets
Update all identical snippet placeholder after selecting an item from
the completion proposal.

Change-Id: Iac4f4183c30517a8133269cc607edadce0c6bd23
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2018-09-03 04:43:58 +00:00
Eike Ziller
847787f146 Merge remote-tracking branch 'origin/4.7'
Conflicts:
	src/plugins/debugger/debuggerruncontrol.cpp

Change-Id: I72882df605bc3fc8a8d20118fd4e49207ac92664
2018-08-07 09:42:02 +02:00
David Schulz
e3a0a710c6 TextEditor: fix crash while request follow symbol and typing on mac
Use a qobject_cast to prevent accessing a not available function.

Task-number: QTCREATORBUG-20910
Change-Id: If2aa6b7b120379681e9590db80904c45a6d9bd55
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2018-08-06 10:03:23 +00:00
Alessandro Portale
3d3f14e3fe Prefer using 'override' instead of 'virtual'
warning: prefer using 'override' or (rarely) 'final' instead of
'virtual' [modernize-use-override]

Change-Id: I6dac7a62b627fa1353b4455e1af92f869c2571cc
Reviewed-by: Marco Benelli <marco.benelli@qt.io>
2018-07-11 16:31:35 +00:00
David Schulz
20e67865ea CodeAssist: Store processor state in specialized objects
Change-Id: I19de64b948599c833496ab8caabf3eaafc845658
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2018-04-19 05:52:21 +00:00
David Schulz
3c4e723b9f CodeAssist: move destroy context condition to function
Increasing readability by moving complex construct into own function.

Change-Id: I4cad1a279293e3348f550e7c423d356d9c79769f
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2018-03-05 08:35:02 +00:00
David Schulz
a4b5fc00a8 CodeAssist: use shared pointer to pass around proposal models
Task-number: QTCREATORBUG-17752
Change-Id: Ia41f169b86ead209830e6f15764062389ced2b67
Reviewed-by: hjk <hjk@qt.io>
2018-02-27 12:32:36 +00:00
David Schulz
c67902ec4e TextEditor: modernize codeassistant
Change-Id: I298d53b5b06765489b866e99a8b2c942c53454f8
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
2018-02-15 08:00:35 +00:00
David Schulz
b4a1798618 TextEditor: add document content completer
Add completion based on words of the document. This provides basic
assistance for programming languages without a code model.

Task-number: QTCREATORBUG-13869
Change-Id: I3a9c59c741dfd6895442fc0524cfd1bd3b2b0111
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Eike Ziller <eike.ziller@qt.io>
2018-02-14 13:38:22 +00:00
hjk
ff04632b92 TextEditor: Remove QuickFixAssistProvider
It did not contain any functionality beyond the base IAssistProvider
anymore.

Change-Id: I0198b3d629f81be8c994ffed3904b5f12ee7f9b9
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-12-15 11:42:40 +00:00
Nikolai Kosjar
b4e2ab36a7 Clang: Remember selected function signature hint
...when typing more arguments:

    struct Foo {};
    void f(int, int);
    void f(Foo, Foo);
    void f(char, char);

    void c()
    {
        f( // 1. Trigger completion with Ctrl+Space
           // 2. Chose item "f(Foo, Foo)"
           // 3. Type: Foo(),
           // OK, signature hint "f(Foo, Foo)" is displayed again
    }

FunctionHintProposalWidget and IFunctionHintProposalModel are
instantiated for each calculation, so remember the selected hint in the
CodeAssist. Keep the latest 20 entries.

Task-number: QTCREATORBUG-11688
Change-Id: I579fc6d8a35dd8fa398e4b3170ddc05a85252d1a
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-09-08 13:29:20 +00:00
Nikolai Kosjar
0ff2c036ac TextEditor: Remove unneeded code
There is no need to trigger the automatic proposal timer anymore. This
was added to fix QTCREATORBUG-6052.

The removed code resulted in 3 completion requests when triggering a
function call: foo(. One is sufficient.

Change-Id: I3da6574bddaaaa101145ea607483e83620110c5f
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-09-08 12:24:41 +00:00
Ulf Hermann
47886969cc Drop unused variables and lambda captures
Also, add context to connect() expressions where we are or were
capturing "this".

Change-Id: I6e006ba6f83d532478018550d148ee93eca59605
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
Reviewed-by: hjk <hjk@qt.io>
2017-09-08 09:06:53 +00:00
Ivan Donchevskii
287ae7ae61 Completion: improve complete in the middle
Apply clang fix to the old code model
Do not replace the text after cursor if
the proposal does not contain it or
if proposal matches 100% the text after it

Task-number: QTCREATORBUG-18471
Change-Id: I662cb6e48a9e0ee14065594f5c823f114fff2474
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
2017-07-10 13:52:18 +00:00
Ivan Donchevskii
c62b6a5fa0 Clang: make correction whithout proposed items
Make . to -> correction even in case code assistant
has no items to propose.

Change-Id: Ie16d317c1a55f05883d3de5ba9bd475d315c59a9
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-06-15 09:00:07 +00:00
Nikolai Kosjar
e8ce2e62d2 CodeAssist: Do not retrigger completion when applying a snippet
This fixes the following case for the ClangCodeModel:

 1. Trigger non-member/non-prefix completion.
 2. Choose the generic "class" snippet.
    --> The snippet is inserted, cursor is right after "name", but it
        also triggers another completion that proposes e.g. the "namespace"
        snippet.

This does not happen with the built-in code model because at that cursor
position it provides "name" as completion result, which is a perfect
match and thus suppresses the completion list.

Change-Id: I2f797469b2a0952406b50c28f9704b113e19b16d
Reviewed-by: Ivan Donchevskii <ivan.donchevskii@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-06-14 10:43:36 +00:00
Orgad Shaneh
6b0e1bc5f8 Merge remote-tracking branch 'origin/4.3' into master
Change-Id: I83af635dcac98e4fd78b21d8dd9dc3a27a4fdf94
2017-06-12 10:01:16 +03:00
Nikolai Kosjar
c801965b58 CodeAssist: Fix leaking proposal model
The model is not owned by the proposal.

For corner cases, we leaked here already for ages. Starting with

  commit fab4dd068e
  CodeAssist: Fix auto completion if function signature is shown

leaks happened also for a hot path: code completion results that does
not match any so far typed prefix. Due to auto completion turned on,
this triggers frequently when typing text.

Task-number: QTCREATORBUG-17752
Task-number: QTCREATORBUG-18326
Change-Id: I9df177723b31cf3df36e73ef1e7920d9aa5e16e5
Reviewed-by: Marco Bubke <marco.bubke@qt.io>
2017-06-08 08:07:07 +00:00
Ivan Donchevskii
762f67f729 Clang: fix completion for incomplete includes
Complete includes when one choice exists.
Fix complete in the middle.

Task-number: QTCREATORBUG-15710
Change-Id: Iec794c17aabc8de47f981382f4b4286b9325827d
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-05-23 07:46:26 +00:00
Nikolai Kosjar
fab4dd068e CodeAssist: Fix auto completion if function signature is shown
This reverts

    commit 3bf19030ab.
    CodeAssist: Fragile proposals aren't closed by automatic proposals.

which fixed the case [1] but introduced the regression in case [2]. Re-
implement the fix for [1] in a different way: Check whether the new
proposal has any items to show before closing the function signature
hint.

Case [1]
  void f(int);
  void g()
  {
      f(bar // This is what we will have in the end. The steps are:
            // 1. Type "f("
            //    --> OK, function signature pop up is shown.
            // 2. Type "bar"
            //    --> OPS, function signature pop up is closed and no
            //        new completion list is shown because "bar" does
            //        not match any declarations.
  }

Case [2]
  int barman = 0;
  void f(int);
  void g()
  {
      f(bar // This is what we will have in the end. The steps are:
            // 1. Type "f("
            //    --> OK, function signature pop up is shown.
            // 2. Type "bar"
            //    --> OPS, no auto completion list for "barman" is
            //        proposed.
  }

Task-number: QTCREATORBUG-16934
Change-Id: I8456275d951de9e6fc53285a5dbcbd448d49ad08
Reviewed-by: David Schulz <david.schulz@qt.io>
2017-05-02 11:07:48 +00:00
Nikolai Kosjar
535cc76cac Clang: Avoid dot-arrow-correction if dot is gone
Change-Id: Iba23a17ba9345ed4f08e16faad02054903c04afc
Reviewed-by: Tim Jenssen <tim.jenssen@qt.io>
2017-03-23 17:26:06 +00:00
David Schulz
9bacb3e33e Editor: Highlight automatically inserted text
Keep the highlight as long as the cursor is directly behind the closing
character and the editor is the focus widget.

Change-Id: Ic1d4bac263e9d2f395791dad7ecdceb9d69635c5
Reviewed-by: Alessandro Portale <alessandro.portale@qt.io>
2016-06-13 05:08:07 +00:00
David Schulz
c422b81316 Move completion settings page to TextEditor plugin.
Change-Id: I12b7828d23d599e5903237d0cc2a3c0440e1b07d
Reviewed-by: Nikolai Kosjar <nikolai.kosjar@qt.io>
Reviewed-by: Leena Miettinen <riitta-leena.miettinen@qt.io>
2016-05-30 07:15:03 +00:00
David Schulz
08655de4a5 CodeAssist: Remove unrelated member from ProcessorRunner.
Change-Id: I53ca41e6d3309680d7153c0847c31b8380856848
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
2016-05-03 13:38:04 +00:00